Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <JetiExSerial.h>
- #include <JetiExProtocol.h>
- #include "GpsSensor.h"
- #include <EEPROM.h>
- GpsSensor gps;
- JetiExProtocol jetiEx;
- int units = 0;
- enum
- {
- ID_GPSLAT = 1,
- ID_GPSLON = 2,
- ID_GPSSPEEDKM = 3,
- ID_ALTME = 4,
- ID_COURSE = 5,
- };
- JETISENSOR_CONST sensorsEU[] PROGMEM =
- {
- // id name unit data type precision
- { ID_GPSLAT, "Latitude", " ", JetiSensor::TYPE_GPS, 0 },
- { ID_GPSLON, "Longitude", " ", JetiSensor::TYPE_GPS, 0 },
- { ID_GPSSPEEDKM, "Speed", "km/h", JetiSensor::TYPE_14b, 0 },
- { ID_ALTME, "Altitude", "m", JetiSensor::TYPE_14b, 0 },
- { ID_COURSE, "Course", "\xB0", JetiSensor::TYPE_14b, 0 },
- { 0 }// end of array
- };
- JETISENSOR_CONST sensorsUS[] PROGMEM =
- {
- // id name unit data type precision
- { ID_GPSLAT, "Latitude", " ", JetiSensor::TYPE_GPS, 0 },
- { ID_GPSLON, "Longitude", " ", JetiSensor::TYPE_GPS, 0 },
- { ID_GPSSPEEDMI, "Speed", "mph", JetiSensor::TYPE_14b, 0 },
- { ID_ALTFT, "Altitude", "ft", JetiSensor::TYPE_14b, 0 },
- { ID_COURSE, "Course", "\xB0", JetiSensor::TYPE_14b, 0 },
- { 0 }// end of array
- };
- void setup()
- {
- units = EEPROM.read(0);
- if (units == 255) {
- units = 0;
- }
- gps.Init( GpsSensor::SERIAL3 );
- jetiEx.SetDeviceId( 0x76, 0x32 ); // 0x3274
- if (units != 1) {
- jetiEx.Start( "GPS", sensorsEU, JetiExProtocol::SERIAL2 );
- }
- if (units == 1) {
- jetiEx.Start( "GPS", sensorsUS, JetiExProtocol::SERIAL2 );
- }
- }
- void loop()
- {
- gps.DoGpsSensor();
- float lat = gps.GetLat();
- float lon = gps.GetLon();
- jetiEx.SetSensorValueGPS( ID_GPSLAT, false, lat );
- jetiEx.SetSensorValueGPS( ID_GPSLON, true, lon );
- if (units == 0) {
- jetiEx.SetSensorValue( ID_ALTME, gps.GetAltMe() );
- jetiEx.SetSensorValue( ID_GPSSPEEDKM, gps.GetSpeedKm() );
- }
- if (units == 1) {
- jetiEx.SetSensorValue( ID_ALTFT, gps.GetAltFt() );
- jetiEx.SetSensorValue( ID_GPSSPEEDMI, gps.GetSpeedMi() );
- }
- jetiEx.SetSensorValue( ID_COURSE, gps.GetCourseDeg() );
- HandleMenu();
- jetiEx.DoJetiSend();
- }
- void HandleMenu()
- {
- static int _nMenu = 0;
- static bool _bSetDisplay = true;
- uint8_t c = jetiEx.GetJetiboxKey();
- // 224 0xe0 : // RIGHT
- // 112 0x70 : // LEFT
- // 208 0xd0 : // UP
- // 176 0xb0 : // DOWN
- // 144 0x90 : // UP+DOWN
- // 96 0x60 : // LEFT+RIGHT
- // Right
- if ( c == 0xe0 && _nMenu < 2 )
- {
- _nMenu++;
- _bSetDisplay = true;
- }
- // Left
- if ( c == 0x70 )
- {
- if ( _nMenu > 0 )
- {
- _nMenu--;
- _bSetDisplay = true;
- }
- else
- {
- jetiEx.SetJetiboxExit(); // todo does not exit menu
- return;
- }
- }
- // Up
- if ( c == 0xd0 && _nMenu == 1 )
- {
- if ( _nMenu == 1 ) {
- if (units == 0) {
- units = 1;
- }
- if (units == 1) {
- units = 0;
- }
- _bSetDisplay = true;
- }
- }
- // UP/DN
- if ( c == 0x90 && _nMenu == 2 )
- {
- EEPROM.write(0, units);
- _nMenu = 3;
- _bSetDisplay = true;
- }
- if ( !_bSetDisplay )
- return;
- switch ( _nMenu )
- {
- case 0:
- jetiEx.SetJetiboxText( JetiExProtocol::LINE1, " RCT Jeti Tools" );
- jetiEx.SetJetiboxText( JetiExProtocol::LINE2, " Test Sensor" );
- break;
- case 1:
- jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Alt/Speed units" );
- if (units == 0) {
- jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Meter & km/h" );
- }
- if (units == 1) {
- jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Feet & mph" );
- }
- break;
- case 2:
- jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Store settings" );
- jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Press UP/DN" );
- break;
- case 3:
- jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Settings stored!" );
- jetiEx.SetJetiboxText( JetiExProtocol::LINE2, " Happy flying!" );
- delay(2000);
- _nMenu = 1;
- _bSetDisplay = true;
- break;
- }
- _bSetDisplay = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement