-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Mozilla clang-format style * Custom `.clang-format` to have the least diff to current style * Apply `clang-format` * Add CI for `clang-format` * Fix Github actions copy/paste * Fix CI again * Also `clang-format` ino files * Add emptyline at EOF * Temporarily disable NewLine
- Loading branch information
Showing
25 changed files
with
609 additions
and
590 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# http://clang.llvm.org/docs/ClangFormatStyleOptions.html | ||
|
||
BasedOnStyle: Google | ||
Standard: Cpp03 | ||
AllowShortFunctionsOnASingleLine: Empty | ||
IncludeBlocks: Preserve | ||
IndentPPDirectives: AfterHash | ||
DerivePointerAlignment: false | ||
# This is only available in Clang-16, see | ||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html#insertnewlineateof | ||
# However, Github runners currently only ship with Clang-15, see | ||
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md | ||
# InsertNewlineAtEOF: true | ||
|
||
# Always break after if to get accurate coverage | ||
AllowShortIfStatementsOnASingleLine: false | ||
AllowShortLoopsOnASingleLine: false | ||
|
||
# custom | ||
IndentWidth: 4 | ||
ColumnLimit: 160 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: Check | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
clang-format: | ||
name: Lint clang-format | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Run clang-format lint | ||
run: find . \( -name '*.[ch]pp' -o -name '*.h' -o -name '*.ino' \) | xargs clang-format --verbose --style=file -n --Werror |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,6 @@ | |
void factorySetupLoop(); | ||
bool isFactorySetupDone(); | ||
|
||
|
||
// Variables | ||
|
||
|
||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,97 @@ | ||
#include "hal.h" | ||
#include "factory_setup.h" | ||
#include "hal.h" | ||
#include "openpaygo_pass.h" | ||
#include "openpaygo_token.h" | ||
|
||
|
||
// -------- SETUP --------- | ||
|
||
void setup() { | ||
// Setup serial first | ||
setupSerial(); | ||
debugPrintln("INFO: OpenPAYGO-HDK Starting..."); | ||
// Setup other peripherals (LEDs, RTC, etc.) | ||
setupPeripherals(); | ||
// We load the variables from memory | ||
loadSetupData(); | ||
// We check if setup done and load all data if done | ||
if(isFactorySetupDone()) { | ||
loadAllData(); | ||
// Setup Metrics | ||
setupMetrics(); | ||
// Setup Pass | ||
#ifdef PASS_ENABLED | ||
setupPass(); | ||
#endif | ||
debugPrintln("INFO: Factory setup done"); | ||
debugPrintln("INFO: Waiting for commands or NFC taps..."); | ||
} else { | ||
debugPrintln("INFO: Factory setup NOT done"); | ||
debugPrintln("INFO: Waiting for Factory setup instruction..."); | ||
} | ||
debugPrintln("INFO: OpenPAYGO-HDK Started!"); | ||
// If you want to add extra features, add their setup here | ||
// Setup serial first | ||
setupSerial(); | ||
debugPrintln("INFO: OpenPAYGO-HDK Starting..."); | ||
// Setup other peripherals (LEDs, RTC, etc.) | ||
setupPeripherals(); | ||
// We load the variables from memory | ||
loadSetupData(); | ||
// We check if setup done and load all data if done | ||
if (isFactorySetupDone()) { | ||
loadAllData(); | ||
// Setup Metrics | ||
setupMetrics(); | ||
// Setup Pass | ||
#ifdef PASS_ENABLED | ||
setupPass(); | ||
#endif | ||
debugPrintln("INFO: Factory setup done"); | ||
debugPrintln("INFO: Waiting for commands or NFC taps..."); | ||
} else { | ||
debugPrintln("INFO: Factory setup NOT done"); | ||
debugPrintln("INFO: Waiting for Factory setup instruction..."); | ||
} | ||
debugPrintln("INFO: OpenPAYGO-HDK Started!"); | ||
// If you want to add extra features, add their setup here | ||
} | ||
|
||
// -------- LOOP --------- | ||
|
||
void loop() { | ||
if (isFactorySetupDone()) { | ||
loopToken(); | ||
loopCommands(); | ||
loopMetrics(); | ||
#ifdef PASS_ENABLED | ||
loopPass(); | ||
#endif | ||
// If you want to add extra features, add their loop here | ||
} else { | ||
factorySetupLoop(); | ||
} | ||
if (isFactorySetupDone()) { | ||
loopToken(); | ||
loopCommands(); | ||
loopMetrics(); | ||
#ifdef PASS_ENABLED | ||
loopPass(); | ||
#endif | ||
// If you want to add extra features, add their loop here | ||
} else { | ||
factorySetupLoop(); | ||
} | ||
} | ||
|
||
|
||
// -------- SERIAL COMMAND HANDLING --------- | ||
|
||
void loopCommands() { | ||
if (Serial.available() > 0) { // send data only when you receive data; condition in setupComplete in case the eeprom was badly initialized | ||
handleSerialCommand(); | ||
} | ||
if (Serial.available() > 0) { // send data only when you receive data; condition in setupComplete in case the eeprom was badly initialized | ||
handleSerialCommand(); | ||
} | ||
} | ||
|
||
void handleSerialCommand() { | ||
if (Serial.read() == '#') { | ||
String input = Serial.readStringUntil(';'); | ||
debugPrint("INFO: Received Command: "); | ||
debugPrintln(input); | ||
if(input == "TOKEN") { | ||
uint32_t inputToken; | ||
input = Serial.readStringUntil('\n'); | ||
sscanf(input.c_str(), "%d", &inputToken); | ||
int tokenStatus = tokenReceived(inputToken); | ||
switch (tokenStatus) { | ||
case TOKEN_INVALID: | ||
Serial.println("#TOKEN;INVALID"); | ||
break; | ||
case TOKEN_ALREADY_USED: | ||
Serial.println("#TOKEN;ALREADY_USED"); | ||
break; | ||
case TOKEN_PAYG_DISABLED: | ||
Serial.println("#TOKEN;PAYG_DISABLED"); | ||
break; | ||
default: | ||
Serial.print("#TOKEN;VALID;"); | ||
Serial.print(getActivationTimeLeft()); | ||
break; | ||
} | ||
} else if (input == "STATUS") { | ||
if(paygDisabled) { | ||
Serial.println("#STATUS;PAYG_DISABLED"); | ||
} else if (isActive()) { | ||
Serial.print("#STATUS;ACTIVE;"); | ||
Serial.println(getActivationTimeLeft()); | ||
} else { | ||
Serial.print("#STATUS;INACTIVE"); | ||
} | ||
} else { | ||
Serial.println("#INVALID"); | ||
if (Serial.read() == '#') { | ||
String input = Serial.readStringUntil(';'); | ||
debugPrint("INFO: Received Command: "); | ||
debugPrintln(input); | ||
if (input == "TOKEN") { | ||
uint32_t inputToken; | ||
input = Serial.readStringUntil('\n'); | ||
sscanf(input.c_str(), "%d", &inputToken); | ||
int tokenStatus = tokenReceived(inputToken); | ||
switch (tokenStatus) { | ||
case TOKEN_INVALID: | ||
Serial.println("#TOKEN;INVALID"); | ||
break; | ||
case TOKEN_ALREADY_USED: | ||
Serial.println("#TOKEN;ALREADY_USED"); | ||
break; | ||
case TOKEN_PAYG_DISABLED: | ||
Serial.println("#TOKEN;PAYG_DISABLED"); | ||
break; | ||
default: | ||
Serial.print("#TOKEN;VALID;"); | ||
Serial.print(getActivationTimeLeft()); | ||
break; | ||
} | ||
} else if (input == "STATUS") { | ||
if (paygDisabled) { | ||
Serial.println("#STATUS;PAYG_DISABLED"); | ||
} else if (isActive()) { | ||
Serial.print("#STATUS;ACTIVE;"); | ||
Serial.println(getActivationTimeLeft()); | ||
} else { | ||
Serial.print("#STATUS;INACTIVE"); | ||
} | ||
} else { | ||
Serial.println("#INVALID"); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.