diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..d95cc19 --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +AlignOperands: Align +AllowAllArgumentsOnNextLine: false +AllowAllConstructorInitializersOnNextLine: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Always +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: None +AlwaysBreakTemplateDeclarations: Yes +BreakBeforeBraces: Custom +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: true +BreakBeforeBinaryOperators: None +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +ColumnLimit: 0 +CompactNamespaces: false +ContinuationIndentWidth: 8 +IndentCaseLabels: true +IndentPPDirectives: None +IndentWidth: 2 +KeepEmptyLinesAtTheStartOfBlocks: true +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: All +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PointerAlignment: Right +ReflowComments: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 2 +UseTab: Never diff --git a/src/LoRa_APRS_Tracker.cpp b/src/LoRa_APRS_Tracker.cpp index 9abea3b..2515ab3 100644 --- a/src/LoRa_APRS_Tracker.cpp +++ b/src/LoRa_APRS_Tracker.cpp @@ -46,8 +46,9 @@ uint32_t refreshDisplayTime = millis(); bool sendUpdate = true; int updateCounter = Config.sendCommentAfterXBeacons; -bool sendStandingUpdate = false; +bool sendStandingUpdate = false; bool statusState = true; +bool bluetoothConnected = false; uint32_t lastTx = 0.0; uint32_t txInterval = 60000L; diff --git a/src/bluetooth_utils.cpp b/src/bluetooth_utils.cpp index 0541e94..36e2fa4 100644 --- a/src/bluetooth_utils.cpp +++ b/src/bluetooth_utils.cpp @@ -6,10 +6,11 @@ #include "configuration.h" #include "TinyGPSPlus.h" -extern Configuration Config; -extern BluetoothSerial SerialBT; +extern Configuration Config; +extern BluetoothSerial SerialBT; extern logging::Logger logger; extern TinyGPSPlus gps; +extern bool bluetoothConnected; namespace BLUETOOTH_Utils { String serialReceived; @@ -47,9 +48,11 @@ namespace BLUETOOTH_Utils { void bluetoothCallback(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) { if (event == ESP_SPP_SRV_OPEN_EVT) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Bluetooth", "Bluetooth client connected !"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Bluetooth", "Client connected !"); + bluetoothConnected = true; } else if (event == ESP_SPP_CLOSE_EVT) { - logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Bluetooth", "Bluetooth client disconnected !"); + logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "Bluetooth", "Client disconnected !"); + bluetoothConnected = false; } } @@ -77,8 +80,8 @@ namespace BLUETOOTH_Utils { shouldSendToLoRa = !serialReceived.isEmpty() // Test true APRS frame and not a NMEA (case when RX buffer overflow) - && serialReceived.indexOf(">") != -1 - && serialReceived.indexOf(":") != -1 + && serialReceived.indexOf('>') != -1 + && serialReceived.indexOf(':') != -1 && serialReceived.indexOf("$G") == -1 && serialReceived.indexOf("$B") == -1; diff --git a/src/custom_characters.h b/src/custom_characters.h index 60919da..8015dd6 100644 --- a/src/custom_characters.h +++ b/src/custom_characters.h @@ -3,6 +3,23 @@ #include +static const unsigned char bluetoothSymbol[] PROGMEM = { + 0b00001100, 0b00000000, + 0b00001111, 0b00000000, + 0b00001100, 0b11000000, + 0b11001100, 0b00110000, + 0b00111100, 0b11000000, + 0b00001111, 0b00000000, + 0b00001111, 0b00000000, + 0b00111100, 0b11000000, + 0b11001100, 0b00110000, + 0b00001100, 0b11000000, + 0b00001111, 0b00000000, + 0b00001100, 0b00000000, + 0b00000000, 0b00000000, + 0b00000000, 0b00000000 +}; + static const unsigned char runnerSymbol[] PROGMEM = { 0b00000000, 0b11100000, 0b00000000, 0b11100000, diff --git a/src/display.cpp b/src/display.cpp index e0e0974..f2e5684 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -15,11 +15,14 @@ extern Configuration Config; extern Beacon *currentBeacon; extern int menuDisplay; extern bool symbolAvailable; +extern bool bluetoothConnected; String symbolArray[10] = {"[", ">", "j", "b", "<", "s", "u", "R", "v"}; int symbolArraySize = sizeof(symbolArray)/sizeof(symbolArray[0]); const uint8_t *symbolsAPRS[] = {runnerSymbol, carSymbol, jeepSymbol, bikeSymbol, motorcycleSymbol, shipSymbol, truckSymbol, recreationalVehicleSymbol, vanSymbol}; +uint32_t symbolTime = millis(); + // T-Beams bought with soldered OLED Screen comes with only 4 pins (VCC, GND, SDA, SCL) // If your board didn't come with 4 pins OLED Screen and comes with 5 and one of them is RST... // Uncomment Next Line (Remember ONLY if your OLED Screen has a RST pin). This is to avoid memory issues. @@ -182,11 +185,25 @@ void show_display(String header, String line1, String line2, String line3, Strin break; } } - if (symbol != 100) { - symbolAvailable = true; - display.drawBitmap((display.width() - SYM_WIDTH), 0, symbolsAPRS[symbol], SYM_WIDTH, SYM_HEIGHT, 1); - } else { - symbolAvailable = false; + + /* + * Symbol alternate every 2.5s (+/- 500ms due to 1s tick of display refresh) + * If bluetooth is disconnected or if we are in the first part of the clock, then we show the APRS symbol + * Otherwise, we are in the second part of the clock, then we show BT connected + */ + if (!bluetoothConnected || millis() - symbolTime <= 2500) { + if (symbol != 100) { + symbolAvailable = true; + display.drawBitmap((display.width() - SYM_WIDTH), 0, symbolsAPRS[symbol], SYM_WIDTH, SYM_HEIGHT, 1); + } else { + symbolAvailable = false; + } + } else if (bluetoothConnected) { + display.drawBitmap((display.width() - SYM_WIDTH), 0, bluetoothSymbol, SYM_WIDTH, SYM_HEIGHT, 1); + } + + if (millis() - symbolTime >= 5000) { + symbolTime = millis(); } }