3 #include "SSD1306Ascii.h"
4 #include "SSD1306AsciiAvrI2c.h"
6 // 0X3C+SA0 - 0x3C or 0x3D
7 #define I2C_ADDRESS 0x3C
12 extern uint8_t oXsGpsPdop ; // gps precision sent by oxs
13 extern uint8_t oXsLastGpsDelay ; // delay since last gps fix at oxs side
14 extern uint8_t oXsPacketRssi ; // RSSI of last packet received by oXs
16 extern uint32_t loraLastPacketReceivedMillis ;
17 uint32_t prevLoraLastPacketReceivedMillis ;
18 extern uint32_t loraLastGpsPacketReceivedMillis ;
19 extern int loraRxPacketRssi ;
20 extern float loraRxPacketSnr ;
21 extern int32_t lastGpsLon ;
22 extern int32_t lastGpsLat ;
33 SSD1306AsciiAvrI2c oled;
36 char *oXsLastGpsDelayText[8] = { "No" , "<1 s" , "<10 s" , "<1 m" ,"<10 m" , "<1 h" , "<10 h" , ">10 h" } ;
39 void print2Pos(uint8_t n) { // print on oled adding a space before if n is less than 10
40 if ( n < 10 ) oled.print(" ");
45 void convertLonLat( int32_t GPS_LatLon, uint8_t &_degree , uint8_t & _minute , uint8_t & _seconde, uint8_t & _secDec ) {
46 uint32_t GPS_LatLonAbs ;
47 uint32_t minute7decimals ;
48 uint32_t seconde7decimals ;
49 uint32_t secondeDec7decimals ;
50 //Serial.print("LonLat= ") ; Serial.println( GPS_LatLon ) ;
51 GPS_LatLonAbs = ( GPS_LatLon < 0 ? - GPS_LatLon : GPS_LatLon) ;
52 _degree = ( GPS_LatLonAbs / 10000000 ) ; // extract the degre without decimal
53 minute7decimals = (GPS_LatLonAbs % 10000000 ) * 60;
54 _minute = minute7decimals / 10000000 ;
55 seconde7decimals = (minute7decimals % 10000000 ) * 60 ;
56 _seconde = seconde7decimals / 10000000 ;
57 secondeDec7decimals = ( seconde7decimals % 10000000 ) * 10 ;
58 _secDec = secondeDec7decimals / 10 ;
59 //Serial.print("degree= ") ; Serial.println( (int32_t)_degree ) ;
62 Serial.begin(115200) ;
63 Serial.println("start lora") ;
64 oled.begin(&Adafruit128x64, I2C_ADDRESS);
65 oled.setFont(System5x7);
67 oled.print("Hello world!");
71 uint8_t loraDebugCode ;
72 uint8_t countTxToDebug = 0 ; // just to debug
73 uint8_t countRxToDebug = 0 ; // just to debug
77 loraDebugCode = loraHandle();
78 if ( loraDebugCode ) fillOled() ; // this for debugging
79 if ( loraDebugCode == 1 ) countTxToDebug++ ;
80 if ( loraDebugCode == 2 ) countRxToDebug++ ;
82 if ( loraLastPacketReceivedMillis != prevLoraLastPacketReceivedMillis ) { // if we receive a new packet, then print
83 prevLoraLastPacketReceivedMillis = loraLastPacketReceivedMillis ;
85 convertLonLat( lastGpsLon , lonDegree , lonMinute , lonSeconde , lonSecDec ) ;
86 //Serial.print("lonDegree back= ") ; Serial.println(lonDegree) ;
87 convertLonLat( lastGpsLat , latDegree , latMinute , latSeconde , latSecDec ) ;
89 //Serial.print( "At=") ; Serial.print( loraLastPacketReceivedMillis ) ; Serial.print( " lastGpsAt=") ; Serial.print( loraLastGpsPacketReceivedMillis ) ;
90 //Serial.print( " pdop=") ; Serial.print( oXsGpsPdop ) ; Serial.print( " GpsDelay=") ; Serial.print( oXsLastGpsDelay ) ;
91 //Serial.print( " oXsRSSI=") ; Serial.print( oXsPacketRssi ) ;
92 //Serial.print( " RxRSSI=") ; Serial.print( loraRxPacketRssi ) ; Serial.print( " RxSNR=") ; Serial.print( loraRxPacketSnr ) ;
93 //Serial.print( " Long=") ; Serial.print( lonDegree ) ; Serial.print( "° ") ; Serial.print( lonMinute ) ; Serial.print( "min ") ; Serial.print( lonSeconde ) ; Serial.print( "sec ") ; Serial.print( lonSecDec ) ;
94 //Serial.print( " Lat=") ; Serial.print( latDegree ) ; Serial.print( "° ") ; Serial.print( latMinute ) ; Serial.print( "min ") ; Serial.print( latSeconde ) ; Serial.print( "sec ") ; Serial.print( latSecDec ) ;
95 //Serial.println( " ") ;
101 static uint8_t countToDebug = 0 ; // just to debug
103 oled.setCursor(0,0) ;
104 // oled.print("Tx= ");
105 // oled.print(countTxToDebug) ;
106 // oled.setCursor(0,2) ;
107 // oled.print("Rx= ");
108 // oled.print(countRxToDebug) ;
111 if (lastGpsLon >= 0) {
116 print2Pos(lonDegree) ; oled.print(" ");
117 print2Pos(lonMinute) ; oled.print("' ");
118 print2Pos(lonSeconde) ; oled.print(".");
119 oled.print(lonSecDec); oled.print("\""); oled.clearToEOL() ;
121 oled.setCursor(0,1) ;
122 if (lastGpsLat >= 0) {
127 print2Pos(latDegree) ; oled.print(" ");
128 print2Pos(latMinute) ; oled.print("' ");
129 print2Pos(latSeconde) ; oled.print(".");
130 oled.print(latSecDec); oled.print("\"");oled.clearToEOL() ;
132 oled.setCursor(0, 2) ; oled.print("dop "); oled.print(oXsGpsPdop); oled.print( " ") ;
133 oled.setCursor(75, 2) ; oled.print("GPS "); oled.print(oXsLastGpsDelayText[oXsLastGpsDelay]); oled.clearToEOL() ;
134 oled.setCursor(0, 3) ; oled.print("oXs Rssi = "); oled.print(oXsPacketRssi); oled.clearToEOL() ;
135 //oled.setCursor(0, 4) ; oled.print("Last gps rec. "); oled.print( ( millis() - loraLastPacketReceivedMillis ) /1000); oled.print( " s") ; oled.clearToEOL() ;
137 oled.setCursor(0, 5) ; oled.print("Last pack rec. ");
138 uint32_t delayLastPacketReceived ;
139 delayLastPacketReceived = millis() - loraLastPacketReceivedMillis ;
140 if ( delayLastPacketReceived < 60000 ) {
141 oled.print( delayLastPacketReceived /1000); oled.print( " s ") ;
143 oled.print( delayLastPacketReceived /60000); oled.print( " m ") ;
145 oled.setCursor(0, 7) ; oled.print("RSSI = "); oled.print(loraRxPacketRssi); oled.print( " ") ;
146 oled.setCursor(75, 7) ;
147 oled.print("SNR = "); oled.print(loraRxPacketSnr); oled.clearToEOL() ;