├── src ├── JetiExProtocol.h ├── JetiExProtocol.cpp ├── JetiExSerial.h └── JetiExSerial.cpp ├── library.properties ├── .gitattributes ├── LICENSE ├── Examples ├── JetiNoEx │ └── JetiNoEx.ino ├── JetiExSensor │ ├── DemoSensor.h │ ├── DemoSensor.cpp │ └── JetiExSensor.ino └── JetiExSimple │ └── JetiExSimple.ino ├── TeensyReadme.txt ├── README.adoc └── .gitignore /src/JetiExProtocol.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sepp62/JetiExSensor/HEAD/src/JetiExProtocol.h -------------------------------------------------------------------------------- /src/JetiExProtocol.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sepp62/JetiExSensor/HEAD/src/JetiExProtocol.cpp -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=JetiExSensor 2 | version=1.0.5 3 | author=Bernd Wokoeck 4 | maintainer= 5 | sentence=Serial interface to transmit telemetry data to Jeti Duplex receivers. For Arduino Mini Pro 328, Nano, Leonardo/Pro Micro and Teensy 3.x 6 | paragraph=Connect your Arduino mini to a Jeti duplex receiver and see telemetry values on your transmitter display. 7 | category=Communication 8 | url=https://sourceforge.net/projects/jetiexsensorcpplib/JetiExSensor_V1.0.5.zip 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Sepp62 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Examples/JetiNoEx/JetiNoEx.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | Jetibox Only - No EX sensors 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2015 Bernd Wokoeck 8 | 9 | *** Extended notice on additional work and copyrights, see header of JetiExProtocol.cpp *** 10 | 11 | Wiring: 12 | 13 | Arduino Mini TXD-Pin 0 <-- Receiver "Ext." input (orange cable) 14 | 15 | Ressources: 16 | Uses built in UART of Arduini Mini Pro 328 or one of 3 Teensy UARTs 17 | 18 | Version history: 19 | 0.90 02/26/2016 created 20 | 21 | **************************************************************/ 22 | 23 | #include "JetiExProtocol.h" 24 | 25 | JetiExProtocol jetiEx; 26 | 27 | static char line1[ 16 ]; 28 | static char line2[ 16 ]; 29 | 30 | void setup() 31 | { 32 | #ifdef CORE_TEENSY 33 | Serial.begin( 9600 ); 34 | #endif 35 | 36 | // jetiEx.Start(); 37 | jetiEx.Start( NULL, NULL, JetiExProtocol::SERIAL2 ); 38 | 39 | jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Start 1" ); 40 | jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Start 2" ); 41 | 42 | /* add your setup code here */ 43 | } 44 | 45 | void loop() 46 | { 47 | /* add your main program code here */ 48 | 49 | int value1 = 99, value2 = 500; 50 | 51 | sprintf( line1, "value 1: %d", value1 ); 52 | jetiEx.SetJetiboxText( JetiExProtocol::LINE1, line1 ); 53 | 54 | sprintf( line2, "value 2: %d", value2 ); 55 | jetiEx.SetJetiboxText( JetiExProtocol::LINE2, line2 ); 56 | 57 | jetiEx.DoJetiSend(); 58 | } 59 | -------------------------------------------------------------------------------- /TeensyReadme.txt: -------------------------------------------------------------------------------- 1 | Changes in Teensy libraries 2 | =========================== 3 | 4 | Activate 9 Bit UART support 5 | --------------------------- 6 | ...\Arduino\hardware\teensy\avr\cores\teensy3\HardwareSerial.h 7 | 8 | // uncomment to enable 9 bit formats 9 | 10 | #define SERIAL_9BIT_SUPPORT 11 | 12 | 13 | Increase TX buffer to avoid "busy waiting" while sending JETI data blocks 14 | -------------------------------------------------------------------------- 15 | ...\Arduino\hardware\teensy\avr\cores\teensy3\serial2.c 16 | #define SERIAL2_TX_BUFFER_SIZE 128 // number of outgoing bytes to buffer 17 | 18 | 19 | Changes in Teensy HardwareSerial library in order to receive Jeti keys 20 | You dont need it, as long as you do not interconnect RX2 and TX2 21 | ---------------------------------------------------------------------- 22 | // comment 23 | in: ...\Arduino\hardware\teensy\avr\cores\teensy3\serial2.c 24 | /* 25 | 26 | #ifdef HAS_KINETISK_UART1_FIFO 27 | 28 | #define C2_ENABLE UART_C2_TE | UART_C2_RE | UART_C2_RIE | UART_C2_ILIE 29 | #else 30 | 31 | #define C2_ENABLE UART_C2_TE | UART_C2_RE | UART_C2_RIE 32 | 33 | #endif 34 | 35 | #define C2_TX_ACTIVE C2_ENABLE | UART_C2_TIE 36 | 37 | #define C2_TX_COMPLETING C2_ENABLE | UART_C2_TCIE 38 | 39 | #define C2_TX_INACTIVE C2_ENABLE 40 | 41 | */ 42 | 43 | // new code: 44 | 45 | 46 | #ifdef HAS_KINETISK_UART1_FIFO 47 | 48 | #define C2_RXENABLE UART_C2_RE | UART_C2_RIE | UART_C2_ILIE 49 | 50 | #else 51 | 52 | #define C2_RXENABLE UART_C2_RE | UART_C2_RIE 53 | 54 | #endif 55 | 56 | #define C2_TX_ACTIVE UART_C2_TE | UART_C2_TIE 57 | 58 | #define C2_TX_COMPLETING UART_C2_TE | UART_C2_TCIE 59 | 60 | #define C2_TX_INACTIVE C2_RXENABLE 61 | 62 | -------------------------------------------------------------------------------- /Examples/JetiExSensor/DemoSensor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | DemoSensor - get some demeo values for telemetry display 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2015 Bernd Wokoeck 8 | 9 | Version history: 10 | 1.00 11/22/2015 created 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the "Software"), 14 | to deal in the Software without restriction, including without limitation 15 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 | and/or sell copies of the Software, and to permit persons to whom the 17 | Software is furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 28 | IN THE SOFTWARE. 29 | 30 | **************************************************************/ 31 | 32 | #ifndef DEMOSENSOR_H 33 | #define DEMOSENSOR_H 34 | 35 | #if ARDUINO >= 100 36 | #include 37 | #else 38 | #include 39 | #endif 40 | 41 | class DemoSensor 42 | { 43 | public: 44 | DemoSensor(); 45 | 46 | long GetVoltage(); 47 | long GetAltitude(); 48 | long GetTemp(); 49 | long GetClimb(); 50 | long GetFuel(); 51 | long GetRpm(); 52 | 53 | long GetVal( int idx ); // values 7..18 54 | 55 | protected: 56 | enum 57 | { 58 | NVALS = 12, 59 | }; 60 | 61 | float volt; 62 | unsigned long tiVolt; 63 | 64 | float alt; 65 | unsigned long tiAlt; 66 | 67 | float temp; 68 | unsigned long tiTemp; 69 | 70 | float climb; 71 | unsigned long tiClimb; 72 | 73 | float fuel; 74 | unsigned long tiFuel; 75 | 76 | float rpm; 77 | unsigned long tiRpm; 78 | 79 | float vals[NVALS]; 80 | unsigned long tiVals[NVALS]; 81 | }; 82 | 83 | #endif // DEMOSENSOR 84 | -------------------------------------------------------------------------------- /Examples/JetiExSimple/JetiExSimple.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | Simple Main program 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2015 Bernd Wokoeck 8 | 9 | *** Extended notice on additional work and copyrights, see header of JetiExProtocol.cpp *** 10 | 11 | Wiring: 12 | 13 | Arduino Mini TXD-Pin 0 <-- Receiver "Ext." input (orange cable) 14 | 15 | Ressources: 16 | Uses built in UART of Arduini Mini Pro 328 or one of 3 Teensy UARTs 17 | 18 | Version history: 19 | 0.90 11/22/2015 created 20 | 0.95 12/23/2015 new sample sensors for GPS and date/time 21 | 0.96 02/21/2016 comPort number as optional parameter for Teensy in Start(...) 22 | sensor device id as optional parameter (SetDeviceId(...)) 23 | 1.02 03/28/2017 New sensor memory management. Sensor data can be located in PROGMEM 24 | 25 | **************************************************************/ 26 | 27 | #include "JetiExProtocol.h" 28 | 29 | JetiExProtocol jetiEx; 30 | 31 | enum 32 | { 33 | ID_VOLTAGE = 1, 34 | ID_ALTITUDE, 35 | ID_TEMP, 36 | ID_CLIMB, 37 | ID_FUEL, 38 | ID_RPM, 39 | ID_GPSLON, 40 | ID_GPSLAT, 41 | ID_DATE, 42 | ID_TIME, 43 | }; 44 | 45 | // id from 1..15 46 | JETISENSOR_CONST sensors[] PROGMEM = 47 | { 48 | // id name unit data type precision 0->0, 1->0.0, 2->0.00 49 | { ID_VOLTAGE, "Voltage", "V", JetiSensor::TYPE_14b, 1 }, 50 | { ID_ALTITUDE, "Altitude", "m", JetiSensor::TYPE_14b, 0 }, 51 | { ID_TEMP, "Temp", "\xB0\x43", JetiSensor::TYPE_14b, 0 }, // �C 52 | { ID_CLIMB, "Climb", "m/s", JetiSensor::TYPE_14b, 2 }, 53 | { ID_FUEL, "Fuel", "%", JetiSensor::TYPE_14b, 0 }, 54 | { ID_RPM, "RPM x 1000", "/min", JetiSensor::TYPE_14b, 1 }, 55 | 56 | { ID_GPSLON, "Longitude", " ", JetiSensor::TYPE_GPS, 0 }, 57 | { ID_GPSLAT, "Latitude", " ", JetiSensor::TYPE_GPS, 0 }, 58 | { ID_DATE, "Date", " ", JetiSensor::TYPE_DT, 0 }, 59 | { ID_TIME, "Time", " ", JetiSensor::TYPE_DT, 0 }, 60 | 61 | 0 // end of array 62 | }; 63 | 64 | void setup() 65 | { 66 | #ifdef CORE_TEENSY 67 | Serial.begin( 9600 ); 68 | #endif 69 | 70 | jetiEx.Start( "ECU", sensors ); 71 | 72 | jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Start 1" ); 73 | jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Start 2" ); 74 | 75 | /* add your setup code here */ 76 | } 77 | 78 | void loop() 79 | { 80 | /* add your main program code here */ 81 | 82 | jetiEx.SetSensorValue( ID_VOLTAGE, 74 ); // 7.4 V 83 | jetiEx.SetSensorValue( ID_ALTITUDE, 120 ); // 120 m 84 | jetiEx.SetSensorValue( ID_TEMP, 31 ); // 31 degrees C 85 | jetiEx.SetSensorValue( ID_CLIMB, 123 ); // 1.23 m/s 86 | jetiEx.SetSensorValue( ID_FUEL, 75 ); // 75% 87 | jetiEx.SetSensorValue( ID_RPM, 901 ); // 90.1 * 1000/min 88 | 89 | jetiEx.SetSensorValueGPS( ID_GPSLON, true, 11.55616f ); // E 11° 33' 22.176" 90 | jetiEx.SetSensorValueGPS( ID_GPSLAT, false, 48.24570f ); // N 48° 14' 44.520" 91 | jetiEx.SetSensorValueDate( ID_DATE, 29, 12, 2015 ); 92 | jetiEx.SetSensorValueTime( ID_TIME, 19, 16, 37 ); 93 | 94 | jetiEx.DoJetiSend(); 95 | } 96 | -------------------------------------------------------------------------------- /Examples/JetiExSensor/DemoSensor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | JetiExSerial - EX serial output implementation 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2015 Bernd Wokoeck 8 | 9 | Version history: 10 | 1.00 11/22/2015 created 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the "Software"), 14 | to deal in the Software without restriction, including without limitation 15 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 | and/or sell copies of the Software, and to permit persons to whom the 17 | Software is furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 23 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 25 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 28 | IN THE SOFTWARE. 29 | 30 | **************************************************************/ 31 | 32 | #include "DemoSensor.h" 33 | 34 | /* 35 | jetiEx.SetSensorValue( ID_VOLTAGE, 81 ); // 8.1 volt 36 | jetiEx.SetSensorValue( ID_ALTITUDE, 250 ); // 250 m 37 | jetiEx.SetSensorValue( ID_TEMP, 300 ); // 300 degrees celsius 38 | jetiEx.SetSensorValue( ID_CLIMB, 153 ); // 1.53 m/s 39 | jetiEx.SetSensorValue( ID_FUEL, 80 ); // 80 % 40 | jetiEx.SetSensorValue( ID_RPM, 5000 ); // 5000/min 41 | */ 42 | 43 | 44 | DemoSensor::DemoSensor() : volt( 81 ), tiVolt( 0 ), alt( 250 ), tiAlt( 0 ), temp( 300 ), tiTemp( 0 ), 45 | climb( 153 ), tiClimb( 0 ), fuel( 80 ), tiFuel( 0 ), rpm( 100 ), tiRpm( 0 ) 46 | { 47 | for( int i = 1; i <= NVALS; i++ ) 48 | vals[i-1] = 10*i; 49 | memset( tiVals, 0, sizeof( tiVals) ); 50 | } 51 | 52 | long DemoSensor::GetVoltage() 53 | { 54 | if( ( tiVolt + 100 ) <= millis() ) 55 | { 56 | tiVolt = millis(); 57 | volt -= .02; 58 | if( volt < 3.3 ) 59 | volt = 81; 60 | } 61 | return volt; 62 | } 63 | 64 | long DemoSensor::GetAltitude() 65 | { 66 | if( ( tiAlt + 100 ) <= millis() ) 67 | { 68 | tiAlt = millis(); 69 | alt -= 1; 70 | if( alt < 100 ) 71 | alt = 250; 72 | } 73 | return alt; 74 | } 75 | 76 | long DemoSensor::GetTemp() 77 | { 78 | if( ( tiTemp + 100 ) <= millis() ) 79 | { 80 | tiTemp = millis(); 81 | temp += 1; 82 | if( temp > 700 ) 83 | temp = 300; 84 | } 85 | return temp; 86 | } 87 | 88 | long DemoSensor::GetClimb() 89 | { 90 | if( ( tiClimb + 100 ) <= millis() ) 91 | { 92 | tiClimb = millis(); 93 | climb += .01; 94 | if( climb > 260 ) 95 | climb = 153; 96 | } 97 | return climb; 98 | } 99 | 100 | long DemoSensor::GetFuel() 101 | { 102 | if( ( tiFuel + 100 ) <= millis() ) 103 | { 104 | tiFuel = millis(); 105 | fuel -= .05; 106 | if( fuel < 5.0 ) 107 | fuel = 80; 108 | } 109 | return fuel; 110 | } 111 | 112 | long DemoSensor::GetRpm() 113 | { 114 | if( ( tiRpm + 100 ) <= millis() ) 115 | { 116 | tiRpm = millis(); 117 | rpm += 3; 118 | if( rpm > 900 ) 119 | rpm = 100; 120 | } 121 | return rpm; 122 | } 123 | 124 | 125 | // values 7..18 --> idx 0..12 126 | long DemoSensor::GetVal( int idx ) 127 | { 128 | if( ( tiVals[idx] + 100 ) <= millis() ) 129 | { 130 | tiVals[idx] = millis(); 131 | vals[idx] += .05; 132 | if( vals[idx] > ((idx+1)*10 + 9.9) ) 133 | vals[idx] = (idx+1)*10; 134 | } 135 | return vals[idx]; 136 | } 137 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = JetiEx Sensor Library for Arduino Mini Pro/Teensy 3.x/Micro Pro/Leonardo = 2 | 3 | Serial interface to transmit telemetry data to Jeti Duplex receivers. For Arduino Mini Pro 328, Nano, Leonardo/Pro Micro and Teensy 3.x. 4 | 5 | Version history: 6 | 7 | 0.90 11/22/2015 created 8 | 9 | 0.92 12/14/2015 set baudrate for 8 MHz Mini Pro added 10 | 15 sensor values, data type 22b added 11 | 0.93 12/14/2015 bug fixed when less sensors than fit in one frame 12 | 13 | 0.94 12/22/2015 Teensy 3.x support on Serial2 14 | 0.95 12/23/2015 Refactoring 15 | Data types added: GPS, date/time, 6b, 30b 16 | 0.96 02/21/2016 comPort number as optional parameter for Teensy in Start(...) 17 | sensor device id as optional parameter (SetDeviceId(...)) 18 | new sample program: JetiExSimple (stripped down to the essential things) 19 | 0.97 02/26/2016 runs w/o EX sensors (Jetibox only), see sample "JetiNoxEX" 20 | 0.98 04/09/2016 slightly improved sensor packet size calculation (avoids "flickering" values) 21 | 0.99 06/05/2016 max number of sensors increased to 32 22 | (set MAX_SENSOR to a higher value in JetiExProtocol.h if you need more) 23 | bug with TYPE_6b removed 24 | DemoSensor delivers 18 demo values now 25 | 1.00 01/29/2017 Some refactoring: 26 | - Bugixes for Jetibox keys and morse alarms (Thanks to Ingmar !) 27 | - Optimized half duplex control for AVR CPUs in JetiExHardwareSerialInt class (for improved Jetibox key handling) 28 | - Reduced size of serial transmit buffer (128-->64 words) 29 | - Changed bitrates for serial communication for AVR CPUs (9600-->9800 bps) 30 | - EX encryption removed, as a consequence: new manufacturer ID: 0xA409 31 | *** Telemetry setup in transmitter must be reconfigured (telemetry reset) *** 32 | - Delay at startup increased (to give receiver more init time) 33 | - New HandleMenu() function in JetiexSensor.ini (including more alarm test) 34 | - JETI_DEBUG and BLOCKING_MODE removed (cleanup) 35 | 1.01 02/15/2017 Support for ATMega32u4 CPU in Leonardo/Pro Micro 36 | 37 | GetKey routine optimized 38 | 1.02 03/28/2017 New sensor memory management. Sensor data can be located in PROGMEM 39 | 40 | 1.03 07/14/2017 Allow all jetibox key combinations (thanks to ThomasL) 41 | Disable RX at startup to prevent reception of receiver identification 42 | Send dictionary already in serial initialization for the 1st time 43 | in order to improve behaviour on telemetry reset 44 | 1.04 07/18/2017 dynamic sensor de-/activation 45 | 1.05 11/12/2017 send 3 textframes before start of EX transmission to get transmitter ready 46 | 47 | == License == 48 | 49 | Copyright (C) 2017 by Bernd Wokoeck 50 | 51 | Permission is hereby granted, free of charge, to any person obtaining 52 | a copy of this software and associated documentation files (the "Software"), 53 | to deal in the Software without restriction, including without limitation 54 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 55 | and/or sell copies of the Software, and to permit persons to whom the 56 | Software is furnished to do so, subject to the following conditions: 57 | 58 | The above copyright notice and this permission notice shall be included in 59 | all copies or substantial portions of the Software. 60 | 61 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 62 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 63 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 64 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 65 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 66 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 67 | IN THE SOFTWARE. 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | -------------------------------------------------------------------------------- /src/JetiExSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | JetiExSerial - EX serial output implementation 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2017 Bernd Wokoeck 8 | 9 | Version history: 10 | 0.90 11/22/2015 created 11 | 0.94 12/22/2015 Teensy 3.x support on Serial2 12 | 0.95 12/23/2015 Refactoring 13 | 0.96 02/21/2016 comPort number as parameter for Teensy 14 | 1.00 01/29/2017 Some refactoring: 15 | - Optimized half duplex control for AVR CPUs in JetiExHardwareSerialInt class (for improved Jetibox key handling) 16 | - Reduced size of serial transmit buffer (128-->64 words) 17 | - Changed bitrates for serial communication for AVR CPUs (9600-->9800 bps) 18 | - JETI_DEBUG and BLOCKING_MODE removed (cleanup) 19 | 1.0.1 02/15/2017 Support for ATMega32u4 CPU in Leonardo/Pro Micro 20 | 21 | Permission is hereby granted, free of charge, to any person obtaining 22 | a copy of this software and associated documentation files (the "Software"), 23 | to deal in the Software without restriction, including without limitation 24 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 25 | and/or sell copies of the Software, and to permit persons to whom the 26 | Software is furnished to do so, subject to the following conditions: 27 | 28 | The above copyright notice and this permission notice shall be included in 29 | all copies or substantial portions of the Software. 30 | 31 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 32 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 33 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 34 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 35 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 36 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 37 | IN THE SOFTWARE. 38 | 39 | **************************************************************/ 40 | 41 | #ifndef JETIEXSERIAL_H 42 | #define JETIEXSERIAL_H 43 | 44 | #if ARDUINO >= 100 45 | #include 46 | #else 47 | #include 48 | #endif 49 | 50 | class JetiExSerial 51 | { 52 | public: 53 | static JetiExSerial * CreatePort( int comPort ); // comPort: 0=default, Teensy: 1..3 54 | 55 | virtual void Init() = 0; 56 | virtual void Send( uint8_t data, boolean bit8 ) = 0; 57 | virtual uint8_t Getchar(void) = 0; 58 | 59 | virtual void TxOn() = 0; 60 | virtual void TxOff() = 0; 61 | }; 62 | 63 | // Teensy 64 | ///////// 65 | #ifdef CORE_TEENSY 66 | 67 | class JetiExTeensySerial : public JetiExSerial 68 | { 69 | public: 70 | JetiExTeensySerial( int comPort ); 71 | virtual void Init(); 72 | virtual void Send( uint8_t data, boolean bit8 ); 73 | virtual uint8_t Getchar(void); 74 | virtual void TxOn() {} 75 | virtual void TxOff() {} 76 | protected: 77 | bool m_bNextIsKey; 78 | HardwareSerial * m_pSerial; 79 | }; 80 | 81 | #else 82 | 83 | #if defined (__AVR_ATmega32U4__) 84 | #define _BV(bit) (1 << (bit)) 85 | #define UCSRA UCSR1A 86 | #define UCSRB UCSR1B 87 | #define UCSRC UCSR1C 88 | 89 | #define UCSZ2 UCSZ12 90 | #define RXEN RXEN1 91 | #define TXEN TXEN1 92 | #define UCSZ0 UCSZ10 93 | #define UCSZ1 UCSZ11 94 | #define UCSZ2 UCSZ12 95 | 96 | #define UPM0 UPM10 97 | #define UPM1 UPM11 98 | 99 | #define UBRRH UBRR1H 100 | #define UBRRL UBRR1L 101 | 102 | #define RXCIE RXCIE1 103 | #define UDRIE UDRIE1 104 | #define TXCIE TXCIE1 105 | 106 | #define TXB8 TXB81 107 | 108 | #define UDR UDR1 109 | #define UDRIE UDRIE1 110 | 111 | #define USART_RX_vect USART1_RX_vect 112 | #define USART_TX_vect USART1_TX_vect 113 | #define USART_UDRE_vect USART1_UDRE_vect 114 | #else 115 | #define UCSRA UCSR0A 116 | #define UCSRB UCSR0B 117 | #define UCSRC UCSR0C 118 | 119 | #define RXEN RXEN0 120 | #define TXEN TXEN0 121 | #define UCSZ0 UCSZ00 122 | #define UCSZ1 UCSZ01 123 | #define UCSZ2 UCSZ02 124 | 125 | #define UPM0 UPM00 126 | #define UPM1 UPM01 127 | 128 | #define UBRRH UBRR0H 129 | #define UBRRL UBRR0L 130 | 131 | #define RXCIE RXCIE0 132 | #define UDRIE UDRIE0 133 | #define TXCIE TXCIE0 134 | 135 | #define TXB8 TXB80 136 | #define UDR UDR0 137 | #define UDRIE UDRIE0 138 | #endif 139 | 140 | // ATMega 141 | ////////// 142 | class JetiExAtMegaSerial : public JetiExSerial 143 | { 144 | public: 145 | virtual void Init(); 146 | }; 147 | 148 | // interrupt driven transmission 149 | // -> low CPU usage (~1ms per frame), slightly higher latency 150 | //////////////////////////////// 151 | 152 | extern "C" void USART_UDRE_vect(void) __attribute__ ((signal)); // make C++ class accessible for ISR 153 | extern "C" void USART_RX_vect(void) __attribute__ ((signal)); // make C++ class accessible for ISR 154 | extern "C" void USART_TX_vect(void) __attribute__ ((signal)); // make C++ class accessible for ISR 155 | 156 | class JetiExHardwareSerialInt : public JetiExAtMegaSerial 157 | { 158 | friend void USART_UDRE_vect(void); 159 | friend void USART_RX_vect(void); 160 | friend void USART_TX_vect(void); 161 | 162 | public: 163 | virtual void Init(); 164 | virtual void Send( uint8_t data, boolean bit8 ); 165 | virtual uint8_t Getchar(void); 166 | 167 | virtual void TxOn() {} 168 | virtual void TxOff() {} 169 | 170 | protected: 171 | enum 172 | { 173 | TX_RINGBUF_SIZE = 64, // 34 bytes text buffer plus 30 bytes ex buffer 174 | RX_RINGBUF_SIZE = 4, 175 | }; 176 | 177 | // tx buffer 178 | volatile uint16_t m_txBuf[ TX_RINGBUF_SIZE ]; // use uint16_t to store bit 9 in a convenient way 179 | volatile uint16_t * m_txHeadPtr; 180 | volatile uint16_t * m_txTailPtr; 181 | volatile uint8_t m_txNumChar; 182 | volatile uint16_t * IncBufPtr( volatile uint16_t * ptr, volatile uint16_t * ringBuf, size_t bufSize ); 183 | 184 | // rx buffer 185 | volatile uint8_t m_rxBuf[ RX_RINGBUF_SIZE ]; 186 | volatile uint8_t * m_rxHeadPtr; 187 | volatile uint8_t * m_rxTailPtr; 188 | volatile uint8_t m_rxNumChar; 189 | volatile uint8_t * IncBufPtr8( volatile uint8_t * ptr, volatile uint8_t * ringBuf, size_t bufSize ); 190 | 191 | // receiver state 192 | volatile bool m_bSending; 193 | }; 194 | 195 | #endif // CORE_TEENSY 196 | 197 | #endif // JETIEXSERIAL_H -------------------------------------------------------------------------------- /Examples/JetiExSensor/JetiExSensor.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | Main program 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2017 Bernd Wokoeck 8 | 9 | *** Extended notice on additional work and copyrights, see header of JetiExProtocol.cpp *** 10 | 11 | Wiring: 12 | 13 | Arduino Mini TXD-Pin 0 <-- Receiver "Ext." input (orange cable) 14 | 15 | Ressources: 16 | Uses built in UART of Arduini Mini Pro 328 17 | 18 | Version history: 19 | 0.90 11/22/2015 created 20 | 0.95 12/23/2015 new sample sensors for GPS and date/time 21 | 0.96 02/21/2016 comPort number as optional parameter for Teensy in Start(...) 22 | sensor device id as optional parameter (SetDeviceId(...)) 23 | 0.99 06/05/2016 max number of sensors increased to 32 (set MAX_SENSOR to a higher value in JetiExProtocol.h if you need more) 24 | bug with TYPE_6b removed 25 | DemoSensor delivers 18 demo values now 26 | 1.00 01/29/2017 Some refactoring: 27 | - Bugixes for Jetibox keys and morse alarms (Thanks to Ingmar !) 28 | - Optimized half duplex control for AVR CPUs in JetiExHardwareSerialInt class (for improved Jetibox key handling) 29 | - Reduced size of serial transmit buffer (128-->64 words) 30 | - Changed bitrates for serial communication for AVR CPUs (9600-->9800 bps) 31 | - EX encryption removed, as a consequence: new manufacturer ID: 0xA409 32 | *** Telemetry setup in transmitter must be reconfigured (telemetry reset) *** 33 | - Delay at startup increased (to give receiver more init time) 34 | - New HandleMenu() function in JetiexSensor.ini (including more alarm test) 35 | - JETI_DEBUG and BLOCKING_MODE removed (cleanup) 36 | 1.0.1 02/15/2017 Support for ATMega32u4 CPU in Leonardo/Pro Micro 37 | GetKey routine optimized 38 | 1.02 03/28/2017 New sensor memory management. Sensor data can be located in PROGMEM 39 | 1.03 07/14/2017 Allow all jetibox key combinations (thanks to ThomasL) 40 | Disable RX at startup to prevent reception of receiver identification or other junk chars 41 | Send dictionary already in serial initialization for the 1st time 42 | in order to improve behaviour on telemetry reset 43 | 1.04 07/18/2017 dynamic sensor de-/activation 44 | 45 | Permission is hereby granted, free of charge, to any person obtaining 46 | a copy of this software and associated documentation files (the "Software"), 47 | to deal in the Software without restriction, including without limitation 48 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 49 | and/or sell copies of the Software, and to permit persons to whom the 50 | Software is furnished to do so, subject to the following conditions: 51 | 52 | The above copyright notice and this permission notice shall be included in 53 | all copies or substantial portions of the Software. 54 | 55 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 56 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 57 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 58 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 59 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 60 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 61 | IN THE SOFTWARE. 62 | 63 | **************************************************************/ 64 | 65 | #include "JetiExProtocol.h" 66 | #include "DemoSensor.h" 67 | 68 | // #define JETIEX_DEBUG 69 | 70 | JetiExProtocol jetiEx; 71 | DemoSensor demoSensor; 72 | 73 | void HandleMenu(); 74 | 75 | enum 76 | { 77 | ID_VOLTAGE = 1, 78 | ID_ALTITUDE, 79 | ID_TEMP, 80 | ID_CLIMB, 81 | ID_FUEL, 82 | ID_RPM, 83 | ID_GPSLON, 84 | ID_GPSLAT, 85 | ID_DATE, 86 | ID_TIME, 87 | ID_VAL11, ID_VAL12, ID_VAL13, ID_VAL14, ID_VAL15, ID_VAL16, ID_VAL17, ID_VAL18, 88 | ID_VAL19, ID_VAL20, ID_VAL21, ID_VAL22, ID_VAL23, ID_VAL24, ID_VAL25, ID_VAL26, 89 | ID_VAL27, ID_VAL28, ID_VAL29, ID_VAL30, ID_VAL31 90 | }; 91 | 92 | // sensor definition (max. 31 for DC/DS-16) 93 | // name plus unit must be < 20 characters 94 | // precision = 0 --> 0, precision = 1 --> 0.0, precision = 2 --> 0.00 95 | JETISENSOR_CONST sensors[] PROGMEM = 96 | { 97 | // id name unit data type precision 98 | { ID_VOLTAGE, "Voltage", "V", JetiSensor::TYPE_14b, 1 }, 99 | { ID_ALTITUDE, "Altitude", "m", JetiSensor::TYPE_14b, 0 }, 100 | { ID_TEMP, "Temp", "\xB0\x43", JetiSensor::TYPE_14b, 0 }, // °C 101 | { ID_CLIMB, "Climb", "m/s", JetiSensor::TYPE_14b, 2 }, 102 | { ID_FUEL, "Fuel", "%", JetiSensor::TYPE_14b, 0 }, 103 | { ID_RPM, "RPM x 1000", "/min", JetiSensor::TYPE_14b, 1 }, 104 | 105 | { ID_GPSLON, "Longitude", " ", JetiSensor::TYPE_GPS, 0 }, 106 | { ID_GPSLAT, "Latitude", " ", JetiSensor::TYPE_GPS, 0 }, 107 | { ID_DATE, "Date", " ", JetiSensor::TYPE_DT, 0 }, 108 | { ID_TIME, "Time", " ", JetiSensor::TYPE_DT, 0 }, 109 | 110 | { ID_VAL11, "V11", "U11", JetiSensor::TYPE_14b, 0 }, 111 | { ID_VAL12, "V12", "U12", JetiSensor::TYPE_14b, 0 }, 112 | { ID_VAL13, "V13", "U13", JetiSensor::TYPE_14b, 0 }, 113 | { ID_VAL14, "V14", "U14", JetiSensor::TYPE_14b, 0 }, 114 | { ID_VAL15, "V15", "U15", JetiSensor::TYPE_14b, 0 }, 115 | { ID_VAL16, "V16", "U16", JetiSensor::TYPE_14b, 0 }, 116 | { ID_VAL17, "V17", "U17", JetiSensor::TYPE_14b, 0 }, 117 | { ID_VAL18, "V18", "U18", JetiSensor::TYPE_14b, 0 }, 118 | 119 | /* 120 | { ID_VAL19, "V19", "U19", JetiSensor::TYPE_14b, 0 }, 121 | { ID_VAL20, "V20", "U20", JetiSensor::TYPE_14b, 0 }, 122 | { ID_VAL21, "V21", "U21", JetiSensor::TYPE_14b, 0 }, 123 | { ID_VAL22, "V22", "U22", JetiSensor::TYPE_14b, 0 }, 124 | { ID_VAL23, "V23", "U23", JetiSensor::TYPE_14b, 0 }, 125 | { ID_VAL24, "V24", "U24", JetiSensor::TYPE_14b, 0 }, 126 | { ID_VAL25, "V25", "U25", JetiSensor::TYPE_14b, 0 }, 127 | { ID_VAL26, "V26", "U26", JetiSensor::TYPE_14b, 0 }, 128 | { ID_VAL27, "V27", "U27", JetiSensor::TYPE_14b, 0 }, 129 | { ID_VAL28, "V28", "U28", JetiSensor::TYPE_14b, 0 }, 130 | { ID_VAL29, "V29", "U29", JetiSensor::TYPE_14b, 0 }, 131 | { ID_VAL30, "V30", "U30", JetiSensor::TYPE_14b, 0 }, 132 | { ID_VAL31, "V31", "U31", JetiSensor::TYPE_14b, 0 },*/ 133 | { 0 } // end of array 134 | }; 135 | 136 | void setup() 137 | { 138 | #ifdef JETIEX_DEBUG 139 | #if defined (CORE_TEENSY) || (__AVR_ATmega32U4__) 140 | Serial.begin( 9600 ); 141 | while( !Serial ) 142 | ; 143 | #endif 144 | #endif 145 | 146 | // jetiEx.SetSensorActive( ID_VAL11, false, sensors ); // disable sensor 147 | 148 | jetiEx.SetDeviceId( 0x76, 0x32 ); // 0x3276 149 | jetiEx.Start( "ECU", sensors, JetiExProtocol::SERIAL2 ); 150 | 151 | jetiEx.SetJetiboxText( JetiExProtocol::LINE1, "Start 1" ); 152 | jetiEx.SetJetiboxText( JetiExProtocol::LINE2, "Start 2" ); 153 | 154 | /* add your setup code here */ 155 | } 156 | 157 | void loop() 158 | { 159 | /* add your main program code here */ 160 | 161 | jetiEx.SetSensorValue( ID_VOLTAGE, demoSensor.GetVoltage() ); 162 | jetiEx.SetSensorValue( ID_ALTITUDE, demoSensor.GetAltitude() ); 163 | jetiEx.SetSensorValue( ID_TEMP, demoSensor.GetTemp() ); 164 | jetiEx.SetSensorValue( ID_CLIMB, demoSensor.GetClimb() ); 165 | jetiEx.SetSensorValue( ID_FUEL, demoSensor.GetFuel() ); 166 | jetiEx.SetSensorValue( ID_RPM, demoSensor.GetRpm() ); 167 | 168 | jetiEx.SetSensorValueGPS( ID_GPSLON, true, 11.55616f ); // E 11° 33' 22.176" 169 | jetiEx.SetSensorValueGPS( ID_GPSLAT, false, 48.24570f ); // N 48° 14' 44.520" 170 | jetiEx.SetSensorValueDate( ID_DATE, 29, 12, 2015 ); 171 | jetiEx.SetSensorValueTime( ID_TIME, 19, 16, 37 ); 172 | 173 | jetiEx.SetSensorValue( ID_VAL11, demoSensor.GetVal(4) ); 174 | jetiEx.SetSensorValue( ID_VAL12, demoSensor.GetVal(5) ); 175 | jetiEx.SetSensorValue( ID_VAL13, demoSensor.GetVal(6) ); 176 | jetiEx.SetSensorValue( ID_VAL14, demoSensor.GetVal(7) ); 177 | jetiEx.SetSensorValue( ID_VAL15, demoSensor.GetVal(8) ); 178 | jetiEx.SetSensorValue( ID_VAL16, demoSensor.GetVal(9) ); 179 | jetiEx.SetSensorValue( ID_VAL17, demoSensor.GetVal(10) ); 180 | jetiEx.SetSensorValue( ID_VAL18, demoSensor.GetVal(11) ); 181 | 182 | HandleMenu(); 183 | 184 | jetiEx.DoJetiSend(); 185 | } 186 | 187 | void HandleMenu() 188 | { 189 | static char _buffer[ 17 ]; 190 | static int _x = 0, _y = 0; 191 | 192 | uint8_t c = jetiEx.GetJetiboxKey(); 193 | 194 | if( c == 0 ) 195 | return; 196 | 197 | #ifdef JETIEX_DEBUG 198 | #if defined (CORE_TEENSY) || (__AVR_ATmega32U4__) 199 | Serial.println( c ); 200 | #endif 201 | #endif 202 | 203 | // down 204 | if( c == 0xb0 ) 205 | { 206 | _y++; 207 | } 208 | 209 | // up 210 | if( c == 0xd0 ) 211 | { 212 | if( _y > 0 ) 213 | _y--; 214 | } 215 | 216 | // right 217 | if( c == 0xe0 ) 218 | { 219 | _x++; 220 | // jetiEx.SetJetiAlarm( 'U' ); // Alarm "U" 221 | } 222 | 223 | // left 224 | if( c == 0x70 ) 225 | { 226 | if( _x > 0 ) 227 | _x--; 228 | else 229 | jetiEx.SetJetiAlarm( 'U' ); // Alarm "U" 230 | } 231 | 232 | sprintf( _buffer, "Menu x/y: %d/%d", _x, _y ); 233 | jetiEx.SetJetiboxText( JetiExProtocol::LINE1, _buffer ); 234 | 235 | sprintf( _buffer, "Key: 0x%2.2x", c ); 236 | jetiEx.SetJetiboxText( JetiExProtocol::LINE2, _buffer ); 237 | } 238 | 239 | -------------------------------------------------------------------------------- /src/JetiExSerial.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Jeti Sensor EX Telemetry C++ Library 3 | 4 | JetiExSerial - EX serial output implementation for AtMega328 5 | -------------------------------------------------------------------- 6 | 7 | Copyright (C) 2015 Bernd Wokoeck 8 | 9 | Version history: 10 | 0.90 11/22/2015 created 11 | 0.92 12/11/2015 baud rate for 8 MHz Pro mini (thanks to Wolfgang/wiff) 12 | 0.94 12/22/2015 Teensy 3.x support on Serial2 13 | 0.95 12/23/2015 Refactoring 14 | 0.96 02/21/2016 comPort number as parameter for Teensy 15 | 1.00 01/29/2017 Some refactoring: 16 | - Optimized half duplex control for AVR CPUs in JetiExHardwareSerialInt class (for improved Jetibox key handling) 17 | - Reduced size of serial transmit buffer (128-->64 words) 18 | - Changed bitrates for serial communication for AVR CPUs (9600-->9800 bps) 19 | - JETI_DEBUG and BLOCKING_MODE removed (cleanup) 20 | 1.0.1 02/15/2017 Support for ATMega32u4 CPU in Leonardo/Pro Micro 21 | GetKey routine optimized 22 | 1.0.3 07/14/2017 Allow all jetibox key combinations (thanks to ThomasL) 23 | Disable RX at startup to prevent reception of receiver identification 24 | 25 | Permission is hereby granted, free of charge, to any person obtaining 26 | a copy of this software and associated documentation files (the "Software"), 27 | to deal in the Software without restriction, including without limitation 28 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 29 | and/or sell copies of the Software, and to permit persons to whom the 30 | Software is furnished to do so, subject to the following conditions: 31 | 32 | The above copyright notice and this permission notice shall be included in 33 | all copies or substantial portions of the Software. 34 | 35 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 36 | OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 37 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 38 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 39 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 40 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 41 | IN THE SOFTWARE. 42 | 43 | **************************************************************/ 44 | 45 | #include "JetiExSerial.h" 46 | 47 | // Teensy 48 | ///////// 49 | #ifdef CORE_TEENSY 50 | 51 | JetiExSerial * JetiExSerial::CreatePort( int comPort ) 52 | { 53 | return new JetiExTeensySerial( comPort ); 54 | } 55 | 56 | JetiExTeensySerial::JetiExTeensySerial( int comPort ) : m_bNextIsKey( false ) 57 | { 58 | switch( comPort ) 59 | { 60 | default: 61 | case 2: m_pSerial = &Serial2; break; 62 | case 1: m_pSerial = &Serial1; break; 63 | case 3: m_pSerial = &Serial3; break; 64 | } 65 | } 66 | 67 | void JetiExTeensySerial::Init() 68 | { 69 | m_pSerial->begin( 9600, SERIAL_9O1 ); 70 | } 71 | void JetiExTeensySerial::Send( uint8_t data, boolean bit8 ) 72 | { 73 | uint32_t w = data | ( bit8 ? 0x100 : 0x000 ); 74 | m_pSerial->write9bit(w); 75 | } 76 | uint8_t JetiExTeensySerial::Getchar(void) // you must modify \Arduino\hardware\teensy\avr\cores\teensy3\serial2.c in order to receive jeti keys 77 | { // refer to TeensyReadme.txt 78 | while( m_pSerial->available() > 0 ) 79 | { 80 | int c = m_pSerial->read(); 81 | // Serial.print( c ); 82 | // if( c == 0x70 || c == 0xb0 || c == 0xd0 || c == 0xe0 ) // filter for jetibox keys: Left = 0x70, down = 0xb0, up= 0xd0, right = 0xe0 83 | if( c != 0xf0 && (c & 0x0f) == 0 ) // check upper nibble 84 | return c; 85 | } 86 | return 0; 87 | } 88 | 89 | #else 90 | 91 | // ATMega 92 | ///////// 93 | 94 | #include 95 | #include 96 | 97 | // HARDWARE SERIAL 98 | ////////////////// 99 | void JetiExAtMegaSerial::Init() // pins are unsued for hardware version 100 | { 101 | // init UART-registers 102 | UCSRA = 0x00; 103 | UCSRB = _BV(UCSZ2) /* | _BV(RXEN) */ | _BV(TXEN); // 0x1C: 9 Bit, RX disable, Tx enable 104 | UCSRC = _BV(UCSZ0) | _BV(UCSZ1) | _BV(UPM0) | _BV(UPM1) ; // 0x36: 9-bit data, 2 stop bits, odd parity 105 | 106 | // wormfood.net/avrbaudcalc.php 107 | #if F_CPU == 16000000L // for the 16 MHz clock on most Arduino boards 108 | UBRRH = 0x00; 109 | UBRRL = 0x66; // 9800 Bit/s 110 | #elif F_CPU == 8000000L // for the 8 MHz internal clock (Pro Mini 3.3 Volt) 111 | UBRRH = 0x00; 112 | UBRRL = 0x32; // 9800 Bit/s 113 | #else 114 | #error Unsupported clock speed 115 | #endif 116 | 117 | // TX and RX pins goes high, when disabled 118 | pinMode( 0, INPUT_PULLUP ); 119 | pinMode( 1, INPUT_PULLUP ); 120 | 121 | // debug 122 | // pinMode( 13, OUTPUT); 123 | // digitalWrite(13, LOW ); 124 | } 125 | 126 | 127 | // Interrupt driven transmission 128 | //////////////////////////////// 129 | JetiExHardwareSerialInt * _pInstance = 0; // instance pointer to find the serial object from ISR 130 | 131 | // static function for port object creation 132 | JetiExSerial * JetiExSerial::CreatePort( int comPort ) 133 | { 134 | return new JetiExHardwareSerialInt(); 135 | } 136 | 137 | void JetiExHardwareSerialInt::Init() 138 | { 139 | JetiExAtMegaSerial::Init(); 140 | 141 | // init tx ring buffer 142 | memset( (void*)m_txBuf, 0, sizeof( m_txBuf ) ); 143 | m_txHeadPtr = m_txBuf; 144 | m_txTailPtr = m_txBuf; 145 | m_txNumChar = 0; 146 | 147 | // init rx ring buffer 148 | memset( (void*)m_rxBuf, 0, sizeof( m_rxBuf ) ); 149 | m_rxHeadPtr = m_rxBuf; 150 | m_rxTailPtr = m_rxBuf; 151 | m_rxNumChar = 0; 152 | 153 | m_bSending = false; 154 | _pInstance = this; // there is a single instance only 155 | } 156 | 157 | // Read key from Jeti box 158 | uint8_t JetiExHardwareSerialInt::Getchar(void) 159 | { 160 | uint8_t c = 0; 161 | 162 | if( m_rxNumChar ) // atomic operation 163 | { 164 | cli(); 165 | c = *(_pInstance->m_rxTailPtr); 166 | m_rxNumChar--; 167 | m_rxTailPtr = IncBufPtr8( m_rxTailPtr, m_rxBuf, RX_RINGBUF_SIZE ); 168 | sei(); 169 | } 170 | return c; 171 | } 172 | 173 | // Send one byte 174 | void JetiExHardwareSerialInt::Send( uint8_t data, boolean bit8 ) 175 | { 176 | cli(); 177 | if( m_txNumChar < TX_RINGBUF_SIZE ) 178 | { 179 | *m_txHeadPtr = data | (bit8 ? 0x0100 : 0x0000); // write data to buffer 180 | m_txNumChar++; // increase number of characters in buffer 181 | m_txHeadPtr = IncBufPtr( m_txHeadPtr, m_txBuf, TX_RINGBUF_SIZE ); // increase ringbuf pointer 182 | } 183 | else 184 | { 185 | // todo handle buffer overflow 186 | // digitalWrite( 13, HIGH ); 187 | } 188 | 189 | // enable transmitter 190 | if( !m_bSending ) 191 | { 192 | m_bSending = true; 193 | uint8_t ucsrb = UCSRB; 194 | ucsrb &= ~( (1<= ( pRingBuf + bufSize ) ) 208 | return pRingBuf; // wrap around 209 | else 210 | return ptr; 211 | } 212 | 213 | volatile uint8_t * JetiExHardwareSerialInt::IncBufPtr8( volatile uint8_t * ptr, volatile uint8_t * pRingBuf, size_t bufSize ) 214 | { 215 | ptr++; 216 | if( ptr >= ( pRingBuf + bufSize ) ) 217 | return pRingBuf; // wrap around 218 | else 219 | return ptr; 220 | } 221 | 222 | // ISR - transmission complete 223 | ISR( USART_TX_vect ) 224 | { 225 | // enable receiver 226 | uint8_t ucsrb = UCSRB; 227 | ucsrb &= ~( (1<m_rxHeadPtr = _pInstance->m_rxBuf; 233 | _pInstance->m_rxTailPtr = _pInstance->m_rxBuf; 234 | _pInstance->m_rxNumChar = 0; 235 | 236 | // digitalWrite( 13, LOW ); 237 | } 238 | 239 | 240 | // ISR - send buffer empty 241 | ISR( USART_UDRE_vect ) 242 | { 243 | if( _pInstance->m_txNumChar != 0 ) 244 | { 245 | uint16_t txChar = *(_pInstance->m_txTailPtr); 246 | 247 | // handle bit 8 248 | if( txChar & 0x0100 ) 249 | UCSRB |= (1<m_txNumChar--; 256 | _pInstance->m_txTailPtr = _pInstance->IncBufPtr( _pInstance->m_txTailPtr, _pInstance->m_txBuf, JetiExHardwareSerialInt::TX_RINGBUF_SIZE ); 257 | } 258 | else 259 | { 260 | // enable TX complete interrupt to get a signal for end of transmission 261 | uint8_t ucsrb = UCSRB; 262 | ucsrb &= ~(1<m_bSending = false; 266 | } 267 | } 268 | 269 | // ISR - receiver buffer full 270 | ISR( USART_RX_vect ) 271 | { 272 | // uint8_t status = UCSR0A; 273 | // uint8_t bit8 = UCSR0B; // unused 274 | uint8_t c = UDR; 275 | // if( c == 0x70 || c == 0xb0 || c == 0xd0 || c == 0xe0 ) // Left = 0x70, down = 0xb0, up= 0xd0, right = 0xe0 276 | if( c != 0xf0 && (c & 0x0f) == 0 ) // check upper nibble 277 | { 278 | *(_pInstance->m_rxHeadPtr) = c; // write data to buffer 279 | _pInstance->m_rxNumChar++; // increase number of characters in buffer 280 | _pInstance->m_rxHeadPtr = _pInstance->IncBufPtr8( _pInstance->m_rxHeadPtr, _pInstance->m_rxBuf, _pInstance->RX_RINGBUF_SIZE ); // increase ringbuf pointer 281 | } 282 | 283 | // if( status & FE0 ) // debug 284 | // digitalWrite( 13, HIGH ); 285 | } 286 | 287 | #endif // CORE_TEENSY 288 | --------------------------------------------------------------------------------