| | |
| | | } |
| | | |
| | | public void refreshFromDevice() { |
| | | // 检查是否正在导航预览模式,如果是则不更新位置 |
| | | if (isNavigating()) { |
| | | return; |
| | | } |
| | | |
| | | Device device = Device.getGecaoji(); |
| | | if (device == null) { |
| | | positionValid = false; |
| | |
| | | positionValid = true; |
| | | headingDegrees = heading; |
| | | } |
| | | |
| | | /** |
| | | * 检查是否正在导航预览模式 |
| | | * @return 如果正在导航预览返回true,否则返回false |
| | | */ |
| | | private boolean isNavigating() { |
| | | try { |
| | | dikuai.daohangyulan nav = dikuai.daohangyulan.getInstance(); |
| | | if (nav != null) { |
| | | return nav.isNavigating(); |
| | | } |
| | | } catch (Exception e) { |
| | | // 如果获取导航实例失败,返回false(不影响主要功能) |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private void ensurePosition() { |
| | | if (position == null) { |
| | |
| | | return new Point2D.Double(position.x, position.y); |
| | | } |
| | | |
| | | /** |
| | | * 设置割草机位置(用于导航预览等场景) |
| | | * @param x X坐标 |
| | | * @param y Y坐标 |
| | | */ |
| | | public void setPosition(double x, double y) { |
| | | ensurePosition(); |
| | | position.x = x; |
| | | position.y = y; |
| | | positionValid = true; |
| | | } |
| | | |
| | | /** |
| | | * 设置割草机方向(用于导航预览等场景) |
| | | * @param headingDegrees 方向角度(度,0-360) |
| | | */ |
| | | public void setHeading(double headingDegrees) { |
| | | double normalized = headingDegrees % 360.0; |
| | | if (normalized < 0) { |
| | | normalized += 360.0; |
| | | } |
| | | this.headingDegrees = normalized; |
| | | } |
| | | |
| | | /** |
| | | * 获取割草机方向 |
| | | * @return 方向角度(度,0-360) |
| | | */ |
| | | public double getHeading() { |
| | | return headingDegrees; |
| | | } |
| | | |
| | | public double getWorldRadius(double scale) { |
| | | if (!positionValid) { |
| | | return Double.NaN; |