From 3a6a6be160e674e707eafbe253c34cb6291698e4 Mon Sep 17 00:00:00 2001 From: Pawel Jalocha Date: Wed, 1 May 2019 21:35:54 +0100 Subject: [PATCH] More (dummy for now) pages on the OLED, switchable by the button --- main/ctrl.cpp | 123 ++++++++++++++++++++++++++++++++++++++- main/hal.cpp | 158 +++++++++++++++++++++++++++----------------------- main/hal.h | 60 +++---------------- 3 files changed, 217 insertions(+), 124 deletions(-) diff --git a/main/ctrl.cpp b/main/ctrl.cpp index ded6e5e..3abc186 100644 --- a/main/ctrl.cpp +++ b/main/ctrl.cpp @@ -98,6 +98,92 @@ int OLED_DisplayPosition(GPS_Position *GPS=0, uint8_t LineIdx=2) return 0; } #endif +#ifdef WITH_U8G2 + +void OLED_PutLine(u8g2_t *OLED, uint8_t LineIdx, const char *Line) +{ if(Line==0) return; +#ifdef DEBUG_PRINT + xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + Format_String(CONS_UART_Write, "OLED_PutLine( ,"); + Format_UnsDec(CONS_UART_Write, (uint16_t)LineIdx); + CONS_UART_Write(','); + Format_String(CONS_UART_Write, Line); + Format_String(CONS_UART_Write, ")\n"); + xSemaphoreGive(CONS_Mutex); +#endif + // u8g2_SetFont(OLED, u8g2_font_5x8_tr); + u8g2_SetFont(OLED, u8g2_font_amstrad_cpc_extended_8r); + u8g2_DrawStr(OLED, 0, (LineIdx+1)*8, Line); +} + +void OLED_DrawStatus(u8g2_t *OLED, uint32_t Time, uint8_t LineIdx=0) +{ char Line[32]; + Format_String(Line , "OGN Tx/Rx "); + Format_HHMMSS(Line+10, Time); Line[16]=0; + OLED_PutLine(OLED, LineIdx++, Line); + Parameters.Print(Line); Line[16]=0; + OLED_PutLine(OLED, LineIdx++, Line); } + +void OLED_DrawPosition(u8g2_t *OLED, GPS_Position *GPS=0, uint8_t LineIdx=2) +{ char Line[20]; + if(GPS && GPS->isValid()) + { Line[0]=' '; + Format_SignDec(Line+1, GPS->Latitude /60, 6, 4); Line[9]=' '; + Format_UnsDec (Line+10, GPS->Altitude /10, 5, 0); Line[15]='m'; + OLED_PutLine(OLED, LineIdx , Line); + Format_SignDec(Line, GPS->Longitude/60, 7, 4); + Format_SignDec(Line+10, GPS->ClimbRate, 4, 1); + OLED_PutLine(OLED, LineIdx+1, Line); + Format_UnsDec (Line , GPS->Speed, 4, 1); Format_String(Line+5, "m/s "); + Format_UnsDec (Line+10, GPS->Heading, 4, 1); Line[15]='^'; + OLED_PutLine(OLED, LineIdx+2, Line); + Format_String(Line, "0D/00sat DOP00.0"); + Line[0]+=GPS->FixMode; Format_UnsDec(Line+3, GPS->Satellites, 2); + Format_UnsDec(Line+12, (uint16_t)GPS->HDOP, 3, 1); + OLED_PutLine(OLED, LineIdx+3, Line); + } + // else { OLED_PutLine(OLED, LineIdx, 0); OLED_PutLine(OLED, LineIdx+1, 0); OLED_PutLine(LineIdx+2, 0); OLED_PutLine(LineIdx+3, 0); } + if(GPS && GPS->isDateValid()) + { Format_UnsDec (Line , (uint16_t)GPS->Day, 2, 0); Line[2]='.'; + Format_UnsDec (Line+ 3, (uint16_t)GPS->Month, 2, 0); Line[5]='.'; + Format_UnsDec (Line+ 6, (uint16_t)GPS->Year , 2, 0); Line[8]=' '; Line[9]=' '; } + else Format_String(Line, " "); + if(GPS && GPS->isTimeValid()) + { Format_UnsDec (Line+10, (uint16_t)GPS->Hour, 2, 0); + Format_UnsDec (Line+12, (uint16_t)GPS->Min, 2, 0); + Format_UnsDec (Line+14, (uint16_t)GPS->Sec, 2, 0); + } else Line[10]=0; + OLED_PutLine(OLED, LineIdx+4, Line); + Line[0]=0; + if(GPS && GPS->hasBaro) + { Format_String(Line , "0000.0hPa 00000m"); + Format_UnsDec(Line , GPS->Pressure/40, 5, 1); + Format_UnsDec(Line+10, GPS->StdAltitude/10, 5, 0); } + OLED_PutLine(OLED, LineIdx+5, Line); +} + +void OLED_DrawGPS(u8g2_t *OLED) +{ u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); + u8g2_DrawStr(OLED, 0, 16, "GPS"); +} + +void OLED_DrawRF(u8g2_t *OLED) +{ u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); + u8g2_DrawStr(OLED, 0, 16, "RF"); +} + +void OLED_DrawBARO(u8g2_t *OLED) +{ u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); + u8g2_DrawStr(OLED, 0, 16, "Baro"); +} + +void OLED_DrawSYS(u8g2_t *OLED) +{ u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); + u8g2_DrawStr(OLED, 0, 16, "SYS"); +} + +#endif + // ======================================================================================================================== static NMEA_RxMsg NMEA; @@ -274,6 +360,9 @@ static void ProcessInput(void) // ======================================================================================================================== +const uint8_t OLED_Pages = 5; +static uint8_t OLED_Page=0; + extern "C" void vTaskCTRL(void* pvParameters) { uint32_t PrevTime=0; @@ -287,7 +376,21 @@ void vTaskCTRL(void* pvParameters) #ifdef WITH_BEEPER Play_TimerCheck(1); // read the button(s) #endif - Button_TimerCheck(); + bool PageChange=0; + int32_t PressRelease=Button_TimerCheck(); + if(PressRelease!=0) + { xSemaphoreTake(CONS_Mutex, portMAX_DELAY); + Format_String(CONS_UART_Write, "PressRelease = "); + Format_SignDec(CONS_UART_Write, PressRelease); + Format_String(CONS_UART_Write, "ms\n"); + xSemaphoreGive(CONS_Mutex); } + if(PressRelease>0) + { if(PressRelease<=300) // short button push: switch pages + { OLED_Page++; if(OLED_Page>=OLED_Pages) OLED_Page=0; + PageChange=1; } + else if(PressRelease<=2000) // long button push: some page action + { } + } uint32_t Time=TimeSync_Time(); GPS_Position *GPS = GPS_getPosition(); @@ -321,6 +424,24 @@ void vTaskCTRL(void* pvParameters) #endif #endif // WITH_OLED +#ifdef WITH_U8G2 + if(Button_SleepRequest) + { u8g2_SetPowerSave(&U8G2_OLED, 0); } + else if(TimeChange || PageChange) + { u8g2_ClearBuffer(&U8G2_OLED); + switch(OLED_Page) + { case 1: OLED_DrawGPS(&U8G2_OLED); break; + case 2: OLED_DrawRF(&U8G2_OLED); break; + case 3: OLED_DrawBARO(&U8G2_OLED); break; + case 4: OLED_DrawSYS(&U8G2_OLED); break; + default: + { OLED_DrawStatus(&U8G2_OLED, Time, 0); + OLED_DrawPosition(&U8G2_OLED, GPS, 2); } + } + u8g2_SendBuffer(&U8G2_OLED); + } +#endif + #ifdef DEBUG_PRINT // in debug mode print the parameters and state every 60sec if((Time%60)!=0) continue; ProcessCtrlC(); diff --git a/main/hal.cpp b/main/hal.cpp index eec6d57..27354f2 100644 --- a/main/hal.cpp +++ b/main/hal.cpp @@ -908,7 +908,64 @@ static uint8_t u8g2_esp32_gpio_and_delay_cb(u8x8_t *u8x8, uint8_t msg, uint8_t a } return 0; } -static u8g2_t U8G2_OLED; +u8g2_t U8G2_OLED; + +void U8G2_DrawLogo(u8g2_t *OLED) // draw logo and hardware options in software +{ + u8g2_DrawCircle(OLED, 96, 32, 30, U8G2_DRAW_ALL); + u8g2_DrawCircle(OLED, 96, 32, 34, U8G2_DRAW_UPPER_RIGHT); + u8g2_DrawCircle(OLED, 96, 32, 38, U8G2_DRAW_UPPER_RIGHT); + // u8g2_SetFont(OLED, u8g2_font_open_iconic_all_4x_t); + // u8g2_DrawGlyph(OLED, 64, 32, 0xF0); + u8g2_SetFont(OLED, u8g2_font_ncenB14_tr); + u8g2_DrawStr(OLED, 74, 31, "OGN"); + u8g2_SetFont(OLED, u8g2_font_8x13_tr); + u8g2_DrawStr(OLED, 69, 43, "Tracker"); + +#ifdef WITH_FollowMe + u8g2_DrawStr(OLED, 0, 16 ,"FollowMe"); +#endif +#ifdef WITH_TTGO + u8g2_DrawStr(OLED, 0, 16 ,"TTGO"); +#endif +#ifdef WITH_HELTEC + u8g2_DrawStr(OLED, 0, 16 ,"HELTEC"); +#endif +#ifdef WITH_TBEAM + u8g2_DrawStr(OLED, 0, 16 ,"T-BEAM"); +#endif + +#ifdef WITH_GPS_MTK + u8g2_DrawStr(OLED, 0, 28 ,"MTK GPS"); +#endif +#ifdef WITH_GPS_UBX + u8g2_DrawStr(OLED, 0, 28 ,"UBX GPS"); +#endif +#ifdef WITH_GPS_SRF + u8g2_DrawStr(OLED, 0, 28 ,"SRF GPS"); +#endif + +#ifdef WITH_RFM95 + u8g2_DrawStr(OLED, 0, 40 ,"RFM95"); +#endif +#ifdef WITH_RFM69 + u8g2_DrawStr(OLED, 0, 40 ,"RFM69"); +#endif + +#ifdef WITH_BMP180 + u8g2_DrawStr(OLED, 0, 52 ,"BMP180"); +#endif +#ifdef WITH_BMP280 + u8g2_DrawStr(OLED, 0, 52 ,"BMP280"); +#endif +#ifdef WITH_BME280 + u8g2_DrawStr(&OLED, 0, 52 ,"BME280"); +#endif + +#ifdef WITH_BT_SPP + u8g2_DrawStr(OLED, 0, 64 ,"BT SPP"); +#endif +} void U8G2_Init(void) { @@ -921,58 +978,10 @@ void U8G2_Init(void) u8g2_InitDisplay(&U8G2_OLED); u8g2_SetPowerSave(&U8G2_OLED, 0); u8g2_ClearBuffer(&U8G2_OLED); + // u8g2_DrawBox (&U8G2_OLED, 0, 26, 80, 6); // u8g2_DrawFrame(&U8G2_OLED, 0, 26, 100, 6); - u8g2_DrawCircle(&U8G2_OLED, 96, 32, 30, U8G2_DRAW_ALL); - u8g2_SetFont(&U8G2_OLED, u8g2_font_ncenB14_tr); - u8g2_DrawStr(&U8G2_OLED, 74, 40 ,"OGN"); - - u8g2_SetFont(&U8G2_OLED, u8g2_font_8x13_tr); - -#ifdef WITH_FollowMe - u8g2_DrawStr(&U8G2_OLED, 0, 16 ,"FollowMe"); -#endif -#ifdef WITH_TTGO - u8g2_DrawStr(&U8G2_OLED, 0, 16 ,"TTGO"); -#endif -#ifdef WITH_HELTEC - u8g2_DrawStr(&U8G2_OLED, 0, 16 ,"HELTEC"); -#endif -#ifdef WITH_TBEAM - u8g2_DrawStr(&U8G2_OLED, 0, 16 ,"T-BEAM"); -#endif - -#ifdef WITH_GPS_MTK - u8g2_DrawStr(&U8G2_OLED, 0, 28 ,"MTK GPS"); -#endif -#ifdef WITH_GPS_UBX - u8g2_DrawStr(&U8G2_OLED, 0, 28 ,"UBX GPS"); -#endif -#ifdef WITH_GPS_SRF - u8g2_DrawStr(&U8G2_OLED, 0, 28 ,"SRF GPS"); -#endif - -#ifdef WITH_RFM95 - u8g2_DrawStr(&U8G2_OLED, 0, 40 ,"RFM95"); -#endif -#ifdef WITH_RFM69 - u8g2_DrawStr(&U8G2_OLED, 0, 40 ,"RFM69"); -#endif - -#ifdef WITH_BMP180 - u8g2_DrawStr(&U8G2_OLED, 0, 52 ,"BMP180"); -#endif -#ifdef WITH_BMP280 - u8g2_DrawStr(&U8G2_OLED, 0, 52 ,"BMP280"); -#endif -#ifdef WITH_BME280 - u8g2_DrawStr(&U8G2_OLED, 0, 52 ,"BME280"); -#endif - -#ifdef WITH_BT_SPP - u8g2_DrawStr(&U8G2_OLED, 0, 64 ,"BT SPP"); -#endif - + U8G2_DrawLogo(&U8G2_OLED); u8g2_SendBuffer(&U8G2_OLED); } @@ -1087,51 +1096,56 @@ static int8_t Button_Filter=(-Button_FilterTime); // #endif // } -static void Button_keptPressed(uint8_t Ticks) -{ Button_PressTime+=Ticks; +static uint32_t Button_keptPressed(uint8_t Ticks) +{ uint32_t ReleaseTime=0; + Button_PressTime+=Ticks; // Button_SleepRequest = Button_PressTime>=30000; // [ms] setup SleepRequest if button pressed for >= 4sec // if(Button_PressTime>=32000) // { Format_String(CONS_UART_Write, "Sleep in 2 sec\n"); // vTaskDelay(2000); // Sleep(); } if(Button_ReleaseTime) - { Format_String(CONS_UART_Write, "Button pressed: released for "); - Format_UnsDec(CONS_UART_Write, Button_ReleaseTime, 4, 3); - Format_String(CONS_UART_Write, "sec\n"); - Button_ReleaseTime=0; - } -} - -static void Button_keptReleased(uint8_t Ticks) -{ Button_ReleaseTime+=Ticks; + { // Format_String(CONS_UART_Write, "Button pressed: released for "); + // Format_UnsDec(CONS_UART_Write, Button_ReleaseTime, 4, 3); + // Format_String(CONS_UART_Write, "sec\n"); + ReleaseTime=Button_ReleaseTime; + Button_ReleaseTime=0; } + return ReleaseTime; } // [ms] when button was pressed, return the release time +static uint32_t Button_keptReleased(uint8_t Ticks) +{ uint32_t PressTime=0; + Button_ReleaseTime+=Ticks; if(Button_PressTime) - { Format_String(CONS_UART_Write, "Button released: pressed for "); - Format_UnsDec(CONS_UART_Write, Button_PressTime, 4, 3); - Format_String(CONS_UART_Write, "sec\n"); + { // Format_String(CONS_UART_Write, "Button released: pressed for "); + // Format_UnsDec(CONS_UART_Write, Button_PressTime, 4, 3); + // Format_String(CONS_UART_Write, "sec\n"); // if(Button_SleepRequest) // { Format_String(CONS_UART_Write, "Sleep in 2 sec\n"); // vTaskDelay(2000); // Sleep(); } + PressTime=Button_PressTime; Button_PressTime=0; } -} + return PressTime; } // [ms] when button is released, return the press time -void Button_TimerCheck(uint8_t Ticks) -{ +int32_t Button_TimerCheck(uint8_t Ticks) +{ int32_t PressReleaseTime=0; #ifdef PIN_BUTTON // CONS_UART_Write(Button_isPressed()?'^':'_'); if(Button_isPressed()) { Button_Filter+=Ticks; if(Button_Filter>Button_FilterTime) Button_Filter=Button_FilterTime; - if(Button_Filter>=Button_FilterThres) { Button_keptPressed(Ticks); } + if(Button_Filter>=Button_FilterThres) + { uint32_t ReleaseTime=Button_keptPressed(Ticks); + if(ReleaseTime) PressReleaseTime=(-(int32_t)ReleaseTime);; } } else { Button_Filter-=Ticks; if(Button_Filter<(-Button_FilterTime)) Button_Filter=(-Button_FilterTime); - if(Button_Filter<=(-Button_FilterThres)) { Button_keptReleased(Ticks); } + if(Button_Filter<=(-Button_FilterThres)) + { uint32_t PressTime=Button_keptReleased(Ticks); + if(PressTime) PressReleaseTime=PressTime; } } #endif - -} + return PressReleaseTime; } // [ms] return press (positive) or release (negative) button times /* extern "C" diff --git a/main/hal.h b/main/hal.h index 4d10cb5..45cec6c 100644 --- a/main/hal.h +++ b/main/hal.h @@ -19,63 +19,17 @@ #define HARDWARE_ID 0x02 #define SOFTWARE_ID 0x01 -// #define DEFAULT_AcftType 1 // [0..15] default aircraft-type: glider -// #define DEFAULT_GeoidSepar 40 // [m] -// #define DEFAULT_CONbaud 115200 -// #define DEFAULT_PPSdelay 80 - #define USE_BLOCK_SPI // use block SPI interface for RF chip #define I2C_SPEED 1000000 // [Hz] bit rate on the I2C (nominally up to 400000) -// #define WITH_HELTEC // HELTEC module: PCB LED on GPI025 -// #define WITH_TTGO // TTGO module: PCB LED on GPIO2, GPIO25 free to use as DAC2 output -// #define WITH_TBEAM // T-Beam module -// #define WITH_JACEK // JACEK ESP32 OGN-Tracker - -// #define WITH_OLED // OLED display on the I2C: some TTGO modules are without OLED display -// #define WITH_OLED2 // 2nd OLED display, I2C address next higher - -// #define WITH_RFM95 // RF chip selection: both HELTEC and TTGO use sx1276 which is same af RFM95 -// #define WITH_RFM69 // Jacek design uses RFM69 - -// #define WITH_LED_RX -// #define WITH_LED_TX - -// #define WITH_GPS_ENABLE // use GPS_ENABLE control line to turn the GPS ON/OFF -// #define WITH_GPS_PPS // use the PPS signal from GPS for precise time-sync. -// #define WITH_GPS_CONFIG // attempt to configure higher GPS baud rate and airborne mode -// #define WITH_GPS_UBX // GPS understands UBX -// #define WITH_GPS_MTK // GPS understands MTK -// #define WITH_GPS_SRF -// #define WITH_MAVLINK - -// #define WITH_GPS_UBX_PASS // to pass directly UBX packets to/from GPS -// #define WITH_GPS_NMEA_PASS // to pass directly NMEA to/from GPS - -// #define WITH_BMP180 // BMP180 pressure sensor -// #define WITH_BMP280 // BMP280 pressure sensor -// #define WITH_BME280 // with humidity -// #define WITH_MS5607 // MS5607 pressure sensor - -// #define WITH_FLARM // Receive FLARM -// #define WITH_PFLAA // PFLAU and PFLAA for compatibility with XCsoar and LK8000 - -// #define WITH_CONFIG // interpret the console input: $POGNS to change parameters - -// #define WITH_BEEPER - -// #define WITH_SD // use the SD card in SPI mode and FAT file system -// #define WITH_SPIFFS // use SPIFFS file system in Flash -// #define WITH_LOG // log own positions and other received to SPIFFS and possibly to uSD - -// #define WITH_BT_SPP // Bluetooth serial port for smartphone/tablet link -// #define WITH_WIFI // attempt to connect to the wifi router for uploading the log files -// #define WITH_SPIFFS_LOG // log transmitted and received packets to SPIFFS - #include "config.h" // user options // ============================================================================================================ +#ifdef WITH_U8G2 +#include "u8g2.h" +#endif + extern uint8_t BARO_I2C; #ifdef WITH_MAVLINK @@ -127,6 +81,10 @@ int OLED_SetContrast(uint8_t Contrast, uint8_t DispIdx=0); int OLED_PutLine(uint8_t Line, const char *Text, uint8_t DispIdx=0); #endif +#ifdef WITH_U8G2 +extern u8g2_t U8G2_OLED; +#endif + #ifdef WITH_SD esp_err_t SD_Mount(void); void SD_Unmount(); @@ -176,7 +134,7 @@ void LED_RX_Flash(uint8_t Time=100); void LED_TimerCheck(uint8_t Ticks=1); extern bool Button_SleepRequest; -void Button_TimerCheck(uint8_t Ticks=1); +int32_t Button_TimerCheck(uint8_t Ticks=1); void IO_Configuration(void); // Configure I/O