SHARE
TWEET

Untitled

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