Exemplo n.º 1
0
  /** method which is called if a timer is set up */
  public void updateGps(int fix) {
    Double bearMov = new Double();
    Double speed = new Double();
    Double sunAzimut = new Double();
    compassRose.setGpsStatus(
        fix,
        myNavigation.gpsPos.getSats(),
        myNavigation.gpsPos.getSatsInView(),
        myNavigation.gpsPos.getHDOP());
    if ((fix > 0) && (myNavigation.gpsPos.getSats() >= 0)) {
      // display values only, if signal good
      lblPosition.setText(myNavigation.gpsPos.toString(CoordsScreen.getLocalSystem(currFormatSel)));
      speed.set(myNavigation.gpsPos.getSpeed());
      sunAzimut.set(myNavigation.skyOrientationDir.lonDec);
      bearMov.set(myNavigation.gpsPos.getBear());
      updateDistance();
      compassRose.setSunMoveDirections(
          (float) sunAzimut.value, (float) bearMov.value, (float) speed.value);
      // Set background to signal quality
    }

    // receiving data, but signal ist not good
    if ((fix == 0) && (myNavigation.gpsPos.getSats() >= 0)) {
      gpsStatus = YELLOW;
    }
    // receiving no data
    if (fix == -1) {
      if (gpsStatus != RED)
        (new MessageBox(
                MyLocale.getMsg(321, "Error"),
                MyLocale.getMsg(1510, "No data from GPS.\nConnection to serial port/gpsd closed."),
                FormBase.OKB))
            .exec();
      gpsStatus = RED;
      myNavigation.stopGps();
    }
    // cannot interpret data
    if (fix == -2) {
      if (gpsStatus != RED)
        (new MessageBox(
                MyLocale.getMsg(321, "Error"),
                MyLocale.getMsg(
                        1511,
                        "Cannot interpret data from GPS/gpsd!\nPossible reasons:\nWrong port,\nwrong baud rate,\ninvalid protocol (need NMEA/gpsd).\nConnection to serial port closed.\nLast String tried to interpret:\n")
                    + myNavigation.gpsPos.lastStrExamined,
                FormBase.OKB))
            .exec();
      gpsStatus = RED;
      myNavigation.stopGps(); // TODO automatic in myNavigate?
    }
  }
Exemplo n.º 2
0
 public void switchToMovingMap() {
   CWPoint centerTo = null;
   if (myNavigation.isGpsPosValid())
     centerTo = new CWPoint(myNavigation.gpsPos); // set gps-pos if gps is on
   else {
     // setze Zielpunkt als Ausgangspunkt, wenn GPS aus ist und lade entsprechende Karte
     // centerTo = new CWPoint(myNavigation.destination);
     if (myNavigation.destination.isValid()) centerTo = new CWPoint(myNavigation.destination);
     else {
       if (mainT.ch != null && mainT.ch.getPos().isValid())
         centerTo = new CWPoint(mainT.ch.getPos());
       else {
         if (pref.getCurCentrePt().isValid()) centerTo = new CWPoint(pref.getCurCentrePt());
       }
     }
   }
   if (centerTo != null && centerTo.isValid()) mainT.SwitchToMovingMap(centerTo, false);
   else
     (new MessageBox(
             MyLocale.getMsg(321, "Error"),
             MyLocale.getMsg(
                 1513,
                 "Cannot start moving map without valid coordinates. Please enter coordinates as destination, as center, in selected cache or start GPS"),
             FormBase.OKB))
         .execute();
 }
Exemplo n.º 3
0
 /**
  * set the coords of the destination
  *
  * @param dest destination
  */
 public void setDestination(CWPoint dest) {
   myNavigation.setDestination(dest);
   if (!myNavigation.destination.isValid())
     (new MessageBox(
             MyLocale.getMsg(321, "Error"),
             MyLocale.getMsg(1507, "Coordinates are out of range:")
                 + "\n"
                 + MyLocale.getMsg(1508, "latitude")
                 + ": "
                 + myNavigation.destination.latDec
                 + "\n "
                 + MyLocale.getMsg(1509, "longditue")
                 + ": "
                 + myNavigation.destination.lonDec,
             FormBase.OKB))
         .execute();
 }
Exemplo n.º 4
0
  /** Eventhandler */
  public void onEvent(Event ev) {
    if (ev instanceof MenuEvent) {
      if (ev.type == MenuEvent.SELECTED) {
        if (((MenuEvent) ev).menu == mnuContextFormt) {
          mnuContextFormt.close();
          mnuContextFormt.getItemAt(currFormatSel).modifiers &= ~MenuItem.Checked;
          currFormatSel = mnuContextFormt.getInt();
          mnuContextFormt.getItemAt(currFormatSel).modifiers |= MenuItem.Checked;
          lblPosition.setText(
              myNavigation.gpsPos.toString(CoordsScreen.getLocalSystem(currFormatSel)));
          btnGoto.setText(getGotoBtnText());
        } // end lat-lon-format context menu
        if (((MenuEvent) ev).menu == mnuContextRose) {
          MenuItem action = (MenuItem) mnuContextRose.getSelectedItem();
          if (action != null) {
            for (int i = 0; i < miLuminary.length; i++) {
              if (action == miLuminary[i]) {
                myNavigation.setLuminary(i);
                miLuminary[i].modifiers |= MenuItem.Checked;
                compassRose.setLuminaryName(SkyOrientation.getLuminaryName(myNavigation.luminary));
              } else miLuminary[i].modifiers &= ~MenuItem.Checked;
            }
            if (action == miNorthCentered) {
              if (compassRose.isNorthCentered()) {
                compassRose.setNorthCentered(false);
                miNorthCentered.modifiers &= ~MenuItem.Checked;
              } else {
                compassRose.setNorthCentered(true);
                miNorthCentered.modifiers |= MenuItem.Checked;
              }
            }
          }
        }
      }
    }

    if (ev instanceof ControlEvent && ev.type == ControlEvent.PRESSED) {
      // start/stop GPS connection
      if (ev.target == btnGPS) {
        if (btnGPS.getText().equals(MyLocale.getMsg(1504, "Start"))) startGps();
        else myNavigation.stopGps();
      }

      // set current position as centre and recalculate distance of caches in MainTab
      if (ev.target == btnCenter) {
        if (myNavigation.gpsPos.isValid()) {
          pref.setCurCentrePt(myNavigation.gpsPos);
        } else
          (new MessageBox(
                  MyLocale.getMsg(312, "Error"),
                  MyLocale.getMsg(
                      1514, "Cannot recalculate distances, because the GPS position is not set"),
                  FormBase.OKB))
              .execute();
      }
      // Start moving map
      if (ev.target == btnMap) {
        switchToMovingMap();
      }
      // create new waypoint with current GPS-position
      if (ev.target == btnSave) {
        CacheHolder ch = new CacheHolder();
        ch.setPos(myNavigation.gpsPos);
        ch.setType(CacheType.CW_TYPE_STAGE); // see CacheType.GC_AW_STAGE_OF_MULTI // TODO unfertig
        mainT.newWaypoint(ch);
      }
      // change destination waypoint
      if (ev.target == btnGoto) {
        if (Vm.isMobile()) {
          InputScreen InScr = new InputScreen(CoordsScreen.getLocalSystem(currFormatSel));
          if (myNavigation.destination.isValid()) InScr.setCoords(myNavigation.destination);
          else InScr.setCoords(new CWPoint(0, 0));
          if (InScr.execute(null, CellConstants.TOP) == FormBase.IDOK)
            setDestination(InScr.getCoords());
        } else {
          CoordsScreen cs = new CoordsScreen();
          if (myNavigation.destination.isValid())
            cs.setFields(myNavigation.destination, CoordsScreen.getLocalSystem(currFormatSel));
          else cs.setFields(new CWPoint(0, 0), CoordsScreen.getLocalSystem(currFormatSel));
          if (cs.execute(null, CellConstants.TOP) == FormBase.IDOK) setDestination(cs.getCoords());
        }
      }
    }
    super.onEvent(ev);
  }
Exemplo n.º 5
0
 public void startGps() {
   myNavigation.startGps(pref.logGPS, Convert.toInt(pref.logGPSTimer));
 }
Exemplo n.º 6
0
 public void setDestinationAndSwitch(CacheHolder ch) {
   myNavigation.setDestination(ch);
   mainT.select(this);
 }
Exemplo n.º 7
0
 /**
  * set the coords of the destination and switch to gotoPanel
  *
  * @param LatLon destination
  */
 public void setDestinationAndSwitch(CWPoint where) {
   myNavigation.setDestination(where);
   mainT.select(this);
 }