Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. #include <JetiExSerial.h>
  2. #include <JetiExProtocol.h>
  3. #include "GpsSensor.h"
  4. #include <EEPROM.h>
  5. #include "units.h"
  6.  
  7. GpsSensor       gps;
  8. JetiExProtocol  jetiEx;
  9.  
  10. int units = EEPROM.read(0);
  11.  
  12. enum
  13. {
  14.   ID_GPSLAT       = 1,
  15.   ID_GPSLON       = 2,
  16.   ID_GPSSPEEDKM   = 3,
  17.   ID_ALTME        = 4,
  18.   ID_COURSE       = 5,
  19. };
  20.  
  21. JETISENSOR_CONST sensors[] PROGMEM =
  22. {
  23.   // id             name        unit          data type           precision
  24.   { ID_GPSLAT,     "Latitude",   " ",         JetiSensor::TYPE_GPS, 0 },
  25.   { ID_GPSLON,     "Longitude",  " ",         JetiSensor::TYPE_GPS, 0 },
  26.   { ID_GPSSPEEDKM, "Speed",      "km/h",       JetiSensor::TYPE_14b, 0 },
  27.   { ID_ALTME,      "Altitude",   "m",        JetiSensor::TYPE_14b, 0 },
  28.   { ID_COURSE,     "Course",     "\xB0",      JetiSensor::TYPE_14b, 0 },
  29.   { 0 }// end of array
  30. };
  31.  
  32. void setup()
  33. {
  34.   if (units == 255) {
  35.     units = 0;
  36.   }
  37.   gps.Init( GpsSensor::SERIAL3 );
  38.  
  39.   jetiEx.SetDeviceId( 0x76, 0x32 );     // 0x3274
  40.   jetiEx.Start( "GPS", sensors, JetiExProtocol::SERIAL2 );
  41. }
  42.  
  43. void loop()
  44. {
  45.   gps.DoGpsSensor();
  46.  
  47.   float lat = gps.GetLat();
  48.   float lon = gps.GetLon();
  49.   jetiEx.SetSensorValueGPS( ID_GPSLAT, false, lat );
  50.   jetiEx.SetSensorValueGPS( ID_GPSLON, true, lon );
  51.   if (units == 0) {
  52.     jetiEx.SetSensorValue( ID_ALTME, gps.GetAltMe() );
  53.     jetiEx.SetSensorValue( ID_GPSSPEEDKM, gps.GetSpeedKm() );
  54.   }
  55.   if (units == 1) {
  56.     //jetiEx.SetSensorValue( ID_ALTFT, gps.GetAltFt() );
  57.     //jetiEx.SetSensorValue( ID_GPSSPEEDMI, gps.GetSpeedMi() );
  58.   }
  59.   jetiEx.SetSensorValue( ID_COURSE, gps.GetCourseDeg() );
  60.  
  61.   HandleMenu();
  62.   jetiEx.DoJetiSend();
  63. }
  64.  
  65. void HandleMenu()
  66. {
  67.   static int  _nMenu = 0;
  68.   static bool _bSetDisplay = true;
  69.   uint8_t c = jetiEx.GetJetiboxKey();
  70.  
  71.   // 224 0xe0 : // RIGHT
  72.   // 112 0x70 : // LEFT
  73.   // 208 0xd0 : // UP
  74.   // 176 0xb0 : // DOWN
  75.   // 144 0x90 : // UP+DOWN
  76.   // 96 0x60 : // LEFT+RIGHT
  77.  
  78.   // Right
  79.   if ( c == 0xe0 && _nMenu < 2 )
  80.   {
  81.     _nMenu++;
  82.     _bSetDisplay = true;
  83.   }
  84.  
  85.   // Left
  86.   if ( c == 0x70 )
  87.   {
  88.     if ( _nMenu > 0 )
  89.     {
  90.       _nMenu--;
  91.       _bSetDisplay = true;
  92.     }
  93.     else
  94.     {
  95.       jetiEx.SetJetiboxExit(); // todo does not exit menu
  96.       return;
  97.     }
  98.   }
  99.  
  100.   // Up
  101.   if ( c == 0xd0 && _nMenu == 1 )
  102.   {
  103.     if ( _nMenu == 1 ) {
  104.       if (units == 0) {
  105.         units = 1;
  106.       }
  107.       if (units == 1) {
  108.         units = 0;
  109.       }
  110.       _bSetDisplay = true;
  111.     }
  112.   }
  113.  
  114.   // UP/DN
  115.   if ( c == 0x90 && _nMenu == 2 )
  116.   {
  117.     EEPROM.write(0, units);
  118.     _nMenu = 3;
  119.     _bSetDisplay = true;
  120.   }
  121.  
  122.   if ( !_bSetDisplay )
  123.     return;
  124.  
  125.   switch ( _nMenu )
  126.   {
  127.     case 0:
  128.       jetiEx.SetJetiboxText( JetiExProtocol::LINE1, " RCT Jeti Tools" );
  129.       jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "  Test Sensor" );
  130.       break;
  131.     case 1:
  132.       jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Alt/Speed units" );
  133.       if (units == 0) {
  134.         jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Meter & km/h" );
  135.       }
  136.       if (units == 1) {
  137.         jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Feet & mph" );
  138.       }
  139.       break;
  140.     case 2:
  141.       jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Store settings" );
  142.       jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Press UP/DN" );
  143.       break;
  144.     case 3:
  145.       jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Settings stored!" );
  146.       jetiEx.SetJetiboxText( JetiExProtocol::LINE2, " Happy flying!" );
  147.       delay(2000);
  148.       _nMenu = 1;
  149.       _bSetDisplay = true;
  150.       break;
  151.   }
  152.   _bSetDisplay = false;
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement