Skip to content

Conversation

@lefty01
Copy link
Owner

@lefty01 lefty01 commented Jan 5, 2026

…ol). switch from modifying esp system time and transmitting the time to client to a browser only stop watch with auto-pause mode based on speed. drawback not keeping time on the esp or sending it back from browse means refresh of browser would reset value.

…ol). switch from modifying esp system time and transmitting the time to client to a browser only stop watch with auto-pause mode based on speed. drawback not keeping time on the esp or sending it back from browse means refresh of browser would reset value.
@github-actions
Copy link

github-actions bot commented Jan 5, 2026

⚠️ Clang-format issues detected in include

diff --git a/include/common.h b/include/common.h
index 9096fdd..e97826b 100644
--- a/include/common.h
+++ b/include/common.h
@@ -44,8 +44,8 @@ enum class EventType {
 //      Maybe, but maybe in some nicer way?? Code is a bit messy right now and
 //      it's not 100% clear what it means
 enum SensorModeFlags {
-  MANUAL  = 0x00, // speed and incline can be adjusted via button or webui
-  SPEED   = 0x01, // b'01 ... only incline can be adjusted (speed from sensor)
+  MANUAL = 0x00, // speed and incline can be adjusted via button or webui
+  SPEED = 0x01, // b'01 ... only incline can be adjusted (speed from sensor)
   INCLINE = 0x02, // b'10 ... only speed can be adjusted (incline from sensor)
   SPEEDINCLINE_BITFIELD = 0x03 // b'11 ... no adjust/overwrite get speed and incline from sensor
 };
@@ -72,7 +72,6 @@ extern double angle;
 extern bool pendingWebSocketEvent;
 extern struct webSocektMsg wsQueue;
 
-
 void logText(const char* text);
 void logText(String text);
 void logText(std::string text);
diff --git a/include/debug_print.h b/include/debug_print.h
index b6edd70..9f083f7 100644
--- a/include/debug_print.h
+++ b/include/debug_print.h
@@ -9,19 +9,18 @@
 #include <PubSubClient.h>
 #include <map>
 
-std::map<int, std::string> mqtt_state_map = {
-  {MQTT_CONNECTION_TIMEOUT,      "MQTT_CONNECTION_TIMEOUT"},
-  {MQTT_CONNECTION_LOST,         "MQTT_CONNECTION_LOST"},
-  {MQTT_CONNECT_FAILED,          "MQTT_CONNECT_FAILED"},
-  {MQTT_DISCONNECTED,            "MQTT_DISCONNECTED"},
-  {MQTT_CONNECT_BAD_PROTOCOL,    "MQTT_CONNECT_BAD_PROTOCOL"},
-  {MQTT_CONNECT_BAD_CLIENT_ID,   "MQTT_CONNECT_BAD_CLIENT_ID"},
-  {MQTT_CONNECT_UNAVAILABLE,     "MQTT_CONNECT_UNAVAILABLE"},
-  {MQTT_CONNECT_BAD_CREDENTIALS, "MQTT_CONNECT_BAD_CREDENTIALS"},
-  {MQTT_CONNECT_UNAUTHORIZED,    "MQTT_CONNECT_UNAUTHORIZED"}
-};
-
-const char* state2str(int state) {
+std::map<int, std::string> mqtt_state_map = {{MQTT_CONNECTION_TIMEOUT, "MQTT_CONNECTION_TIMEOUT"},
+                                             {MQTT_CONNECTION_LOST, "MQTT_CONNECTION_LOST"},
+                                             {MQTT_CONNECT_FAILED, "MQTT_CONNECT_FAILED"},
+                                             {MQTT_DISCONNECTED, "MQTT_DISCONNECTED"},
+                                             {MQTT_CONNECT_BAD_PROTOCOL, "MQTT_CONNECT_BAD_PROTOCOL"},
+                                             {MQTT_CONNECT_BAD_CLIENT_ID, "MQTT_CONNECT_BAD_CLIENT_ID"},
+                                             {MQTT_CONNECT_UNAVAILABLE, "MQTT_CONNECT_UNAVAILABLE"},
+                                             {MQTT_CONNECT_BAD_CREDENTIALS, "MQTT_CONNECT_BAD_CREDENTIALS"},
+                                             {MQTT_CONNECT_UNAUTHORIZED, "MQTT_CONNECT_UNAUTHORIZED"}};
+
+const char* state2str(int state)
+{
   return std::string(mqtt_state_map[state]).c_str();
 }
 
@@ -31,17 +30,17 @@ const char* state2str(int state) {
 const char* mqttDbg = MQTTDEVICEID "/debug";
 
 #define DEBUG_PRINT_MQTTSTATE(x) Serial.println(state2str(x))
-#define DEBUG_PRINTMQTT(x)    mqttClient.publish(mqttDbg, x)
+#define DEBUG_PRINTMQTT(x) mqttClient.publish(mqttDbg, x)
 #else
 #define DEBUG_PRINT_MQTTSTATE(x)
 #endif
 
-#define DEBUG_BEGIN(x)        Serial.begin(x)
-#define DEBUG_PRINT(x)        Serial.print(x)
-#define DEBUG_PRINTLN(x)      Serial.println(x)
-#define DEBUG_PRINTDEC(x)     Serial.print(x, DEC)
-#define DEBUG_PRINTHEX(x)     Serial.print(x, HEX)
-#define DEBUG_PRINTLNHEX(x)   Serial.println(x, HEX)
+#define DEBUG_BEGIN(x) Serial.begin(x)
+#define DEBUG_PRINT(x) Serial.print(x)
+#define DEBUG_PRINTLN(x) Serial.println(x)
+#define DEBUG_PRINTDEC(x) Serial.print(x, DEC)
+#define DEBUG_PRINTHEX(x) Serial.print(x, HEX)
+#define DEBUG_PRINTLNHEX(x) Serial.println(x, HEX)
 #define DEBUG_PRINTF(x_, ...) Serial.printf((x_), ##__VA_ARGS__)
 
 #else
diff --git a/include/hardware.h b/include/hardware.h
index 9070fbf..580b985 100644
--- a/include/hardware.h
+++ b/include/hardware.h
@@ -31,8 +31,7 @@ static constexpr int TREADMILL_BUTTON_PRESS_SIGNAL_TIME_MS = 250;
 extern volatile long workoutDistance;
 extern bool timer_tick;
 
-class GPIOExtenderAW9523
-{
+class GPIOExtenderAW9523 {
 public:
   GPIOExtenderAW9523(TwoWire& w)
   {
@@ -56,54 +55,54 @@ private:
   bool enabled = false;
   bool isInterrupted = false;
   TwoWire* wire;
-  static constexpr uint8_t AW9523_ADDR  = 0x5B;
-  static constexpr uint8_t INPUT_PORT0  = 0x00; //P0 port input state
-  static constexpr uint8_t INPUT_PORT1  = 0x01; //P1 port input state
+  static constexpr uint8_t AW9523_ADDR = 0x5B;
+  static constexpr uint8_t INPUT_PORT0 = 0x00; //P0 port input state
+  static constexpr uint8_t INPUT_PORT1 = 0x01; //P1 port input state
   static constexpr uint8_t OUTPUT_PORT0 = 0x02; //P0 port output state
   static constexpr uint8_t OUTPUT_PORT1 = 0x03; //P1 port output state
   static constexpr uint8_t CONFIG_PORT0 = 0x04; //P0 port direction configure
   static constexpr uint8_t CONFIG_PORT1 = 0x05; //P1 port direction configure
-  static constexpr uint8_t INT_PORT0    = 0x06; //P0 port interrupt enable
-  static constexpr uint8_t INT_PORT1    = 0x07; //P1 port interrupt enable
-  static constexpr uint8_t ID           = 0x10;
-  static constexpr uint8_t CTL          = 0x11; //Global control register
+  static constexpr uint8_t INT_PORT0 = 0x06; //P0 port interrupt enable
+  static constexpr uint8_t INT_PORT1 = 0x07; //P1 port interrupt enable
+  static constexpr uint8_t ID = 0x10;
+  static constexpr uint8_t CTL = 0x11; //Global control register
   static constexpr uint8_t LED_MODE_SWITCH0 = 0x12; //P0 port mode configure
   static constexpr uint8_t LED_MODE_SWITCH1 = 0x13; //P1 port mode configure
-  static constexpr uint8_t DIM0         = 0x20; //P1_0 LED current control
-  static constexpr uint8_t DIM1         = 0x21; //P1_1 LED current control
-  static constexpr uint8_t DIM2         = 0x22; //P1_2 LED current control
-  static constexpr uint8_t DIM3         = 0x23; //P1_3 LED current control
-  static constexpr uint8_t DIM4         = 0x24; //P0_0 LED current control
-  static constexpr uint8_t DIM5         = 0x25; //P0_1 LED current control
-  static constexpr uint8_t DIM6         = 0x26; //P0_2 LED current control
-  static constexpr uint8_t DIM7         = 0x27; //P0_3 LED current control
-  static constexpr uint8_t DIM8         = 0x28; //P0_4 LED current control
-  static constexpr uint8_t DIM9         = 0x29; //P0_5 LED current control
-  static constexpr uint8_t DIM10        = 0x2A; //P0_6 LED current control
-  static constexpr uint8_t DIM11        = 0x2B; //P0_7 LED current control
-  static constexpr uint8_t DIM12        = 0x20; //P1_4 LED current control
-  static constexpr uint8_t DIM13        = 0x21; //P1_5 LED current control
-  static constexpr uint8_t DIM14        = 0x22; //P1_6 LED current control
-  static constexpr uint8_t DIM15        = 0x23; //P1_7 LED current control
-  static constexpr uint8_t SW_RSTN      = 0x7F;
-  static constexpr uint8_t ID_AW9523    = 0x23;
-  static constexpr uint16_t AW9523_KEY_UP               = 0x0001;
-  static constexpr uint16_t AW9523_KEY_LEFT             = 0x0002;
-  static constexpr uint16_t AW9523_KEY_DOWN             = 0x0004;
-  static constexpr uint16_t AW9523_KEY_RIGHT            = 0x0008;
-  static constexpr uint16_t AW9523_KEY_OK               = 0x0010;
-  static constexpr uint16_t AW9523_KEY_BACK             = 0x0020;
-  static constexpr uint16_t AW9523_TREADMILL_REED       = 0x0100;
+  static constexpr uint8_t DIM0 = 0x20; //P1_0 LED current control
+  static constexpr uint8_t DIM1 = 0x21; //P1_1 LED current control
+  static constexpr uint8_t DIM2 = 0x22; //P1_2 LED current control
+  static constexpr uint8_t DIM3 = 0x23; //P1_3 LED current control
+  static constexpr uint8_t DIM4 = 0x24; //P0_0 LED current control
+  static constexpr uint8_t DIM5 = 0x25; //P0_1 LED current control
+  static constexpr uint8_t DIM6 = 0x26; //P0_2 LED current control
+  static constexpr uint8_t DIM7 = 0x27; //P0_3 LED current control
+  static constexpr uint8_t DIM8 = 0x28; //P0_4 LED current control
+  static constexpr uint8_t DIM9 = 0x29; //P0_5 LED current control
+  static constexpr uint8_t DIM10 = 0x2A; //P0_6 LED current control
+  static constexpr uint8_t DIM11 = 0x2B; //P0_7 LED current control
+  static constexpr uint8_t DIM12 = 0x20; //P1_4 LED current control
+  static constexpr uint8_t DIM13 = 0x21; //P1_5 LED current control
+  static constexpr uint8_t DIM14 = 0x22; //P1_6 LED current control
+  static constexpr uint8_t DIM15 = 0x23; //P1_7 LED current control
+  static constexpr uint8_t SW_RSTN = 0x7F;
+  static constexpr uint8_t ID_AW9523 = 0x23;
+  static constexpr uint16_t AW9523_KEY_UP = 0x0001;
+  static constexpr uint16_t AW9523_KEY_LEFT = 0x0002;
+  static constexpr uint16_t AW9523_KEY_DOWN = 0x0004;
+  static constexpr uint16_t AW9523_KEY_RIGHT = 0x0008;
+  static constexpr uint16_t AW9523_KEY_OK = 0x0010;
+  static constexpr uint16_t AW9523_KEY_BACK = 0x0020;
+  static constexpr uint16_t AW9523_TREADMILL_REED = 0x0100;
 
   // These are used to control/override the Treadmil, e.g. pins are connected to
   // the different button so that software can "press" them
   // TODO: They could also be used to read pins, to see if user presses them
-  static constexpr uint16_t AW9523_TREADMILL_START      = 0x0200;
+  static constexpr uint16_t AW9523_TREADMILL_START = 0x0200;
   static constexpr uint16_t AW9523_TREADMILL_SPEED_DOWN = 0x0400;
-  static constexpr uint16_t AW9523_TREADMILL_INC_DOWN   = 0x0800;
-  static constexpr uint16_t AW9523_TREADMILL_INC_UP     = 0x1000;
-  static constexpr uint16_t AW9523_TREADMILL_SPEED_UP   = 0x2000;
-  static constexpr uint16_t AW9523_TREADMILL_STOP       = 0x4000;
+  static constexpr uint16_t AW9523_TREADMILL_INC_DOWN = 0x0800;
+  static constexpr uint16_t AW9523_TREADMILL_INC_UP = 0x1000;
+  static constexpr uint16_t AW9523_TREADMILL_SPEED_UP = 0x2000;
+  static constexpr uint16_t AW9523_TREADMILL_STOP = 0x4000;
 };
 
 void initHardware(void);

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

⚠️ Clang-format issues detected in src

diff --git a/src/ESP32_TTGO_FTMS.cpp b/src/ESP32_TTGO_FTMS.cpp
index 918bedd..df6c3e2 100644
--- a/src/ESP32_TTGO_FTMS.cpp
+++ b/src/ESP32_TTGO_FTMS.cpp
@@ -206,20 +206,15 @@ static void showInfo()
   intoText = String("ESP32 FTMS - ") + VERSION + String("\n");
   logText(intoText.c_str());
   logText(configTreadmill.treadmill_name.c_str());
-  intoText = String("\nSpeed[") + configTreadmill.min_speed +
-             String(", ") + configTreadmill.max_speed +
-             String(" Incline[") + configTreadmill.min_incline +
-             String(", ") + configTreadmill.max_incline +
+  intoText = String("\nSpeed[") + configTreadmill.min_speed + String(", ") + configTreadmill.max_speed +
+             String(" Incline[") + configTreadmill.min_incline + String(", ") + configTreadmill.max_incline +
              String("]\n");
   logText(intoText.c_str());
   intoText = String("Dist/REED: ") + configTreadmill.belt_distance + String("mm\n");
   logText(intoText.c_str());
-  intoText = String("HW: REED: ") + configTreadmill.hasReed +
-             String(" MPU6050: ") + configTreadmill.hasMPU6050 +
-             String(" inAngle: ") + configTreadmill.hasMPU6050inAngle +
-             String(" IrSense: ") + configTreadmill.hasIrSense +
-             String(" GPIOExtender(AW9523): ") + GPIOExtender.isAvailable() +
-             String("\n");
+  intoText = String("HW: REED: ") + configTreadmill.hasReed + String(" MPU6050: ") + configTreadmill.hasMPU6050 +
+             String(" inAngle: ") + configTreadmill.hasMPU6050inAngle + String(" IrSense: ") +
+             configTreadmill.hasIrSense + String(" GPIOExtender(AW9523): ") + GPIOExtender.isAvailable() + String("\n");
   logText(intoText.c_str());
 }
 
@@ -295,11 +290,11 @@ void loop()
       // and calc rpm from reed switch provide same unit
       if (configTreadmill.hasIrSense) {
         kmph = kmphIRsense;
-        mps  = kmph / 3.6; // meter per second (EVERY_SECOND)
+        mps = kmph / 3.6; // meter per second (EVERY_SECOND)
         totalDistance += mps;
       } else {
         float rpm = calculateRPM();
-        mps  = configTreadmill.belt_distance * (rpm) / (60 * 1000); // meter per sec
+        mps = configTreadmill.belt_distance * (rpm) / (60 * 1000); // meter per sec
         kmph = mps * 3.6; // km per hour
         totalDistance = workoutDistance / 1000; // conv mm to meter
       }
diff --git a/src/config.cpp b/src/config.cpp
index 404eb94..5fdf07a 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -223,19 +223,19 @@ void initConfig(void)
 {
   logText("initConfig...");
   // Get Treadmill config
-  configTreadmill.treadmill_name        = LittleFS_findString(F("treadmillname"));
-  configTreadmill.max_speed             = LittleFS_findFloat(F("max_speed"));
-  configTreadmill.min_speed             = LittleFS_findFloat(F("min_speed"));
-  configTreadmill.max_incline           = LittleFS_findFloat(F("max_incline"));
-  configTreadmill.min_incline           = LittleFS_findFloat(F("min_incline"));
-  configTreadmill.speed_interval_step   = LittleFS_findFloat(F("speed_interval_step"));
+  configTreadmill.treadmill_name = LittleFS_findString(F("treadmillname"));
+  configTreadmill.max_speed = LittleFS_findFloat(F("max_speed"));
+  configTreadmill.min_speed = LittleFS_findFloat(F("min_speed"));
+  configTreadmill.max_incline = LittleFS_findFloat(F("max_incline"));
+  configTreadmill.min_incline = LittleFS_findFloat(F("min_incline"));
+  configTreadmill.speed_interval_step = LittleFS_findFloat(F("speed_interval_step"));
   configTreadmill.incline_interval_step = LittleFS_findFloat(F("incline_interval_step"));
-  configTreadmill.belt_distance         = LittleFS_findFloat(F("belt_distance"));
+  configTreadmill.belt_distance = LittleFS_findFloat(F("belt_distance"));
   // Get Your HW config, e.g. interface to Treadmill and other added HW
-  configTreadmill.hasMPU6050            = LittleFS_findInt(F("hasMPU6050"));
-  configTreadmill.hasMPU6050inAngle     = LittleFS_findInt(F("hasMPU6050inAngle"));
-  configTreadmill.hasIrSense            = LittleFS_findInt(F("hasIrSense"));
-  configTreadmill.hasReed               = LittleFS_findInt(F("hasReed"));
+  configTreadmill.hasMPU6050 = LittleFS_findInt(F("hasMPU6050"));
+  configTreadmill.hasMPU6050inAngle = LittleFS_findInt(F("hasMPU6050inAngle"));
+  configTreadmill.hasIrSense = LittleFS_findInt(F("hasIrSense"));
+  configTreadmill.hasReed = LittleFS_findInt(F("hasReed"));
 
   // check if values were valid, else set to safe defaults
   if (configTreadmill.treadmill_name.length() == 0) {
diff --git a/src/gui-tft.cpp b/src/gui-tft.cpp
index 6f974ec..a7bc2ab 100644
--- a/src/gui-tft.cpp
+++ b/src/gui-tft.cpp
@@ -31,23 +31,23 @@
 #define TFT_SETUP_FONT_SIZE 4
 #define TFT_STATS_FONT_SIZE 2
 
-#define CIRCLE_SPEED_X_POS   188
+#define CIRCLE_SPEED_X_POS 188
 #define CIRCLE_INCLINE_X_POS 208
 #define CIRCLE_BT_STAT_X_POS 227
 
-#define CIRCLE_SPEED_Y_POS    11
-#define CIRCLE_INCLINE_Y_POS  11
-#define CIRCLE_BT_STAT_Y_POS  11
-#define CIRCLE_Y_POS          11
-#define CIRCLE_RADIUS          8
+#define CIRCLE_SPEED_Y_POS 11
+#define CIRCLE_INCLINE_Y_POS 11
+#define CIRCLE_BT_STAT_Y_POS 11
+#define CIRCLE_Y_POS 11
+#define CIRCLE_RADIUS 8
 
 // with tft.setRotation(1); => landscape orientation (usb right side)
 
 #if defined(DRAW_STATS_WIDTH) && defined(DRAW_STATS_HEIGHT)
-const int DRAW_WIDTH  = DRAW_STATS_WIDTH;
+const int DRAW_WIDTH = DRAW_STATS_WIDTH;
 const int DRAW_HEIGHT = DRAW_STATS_HEIGHT;
 #else
-const int DRAW_WIDTH  = TFT_HEIGHT;
+const int DRAW_WIDTH = TFT_HEIGHT;
 const int DRAW_HEIGHT = TFT_WIDTH;
 #endif
 
@@ -66,50 +66,51 @@ void tft_gfxUpdateHeader(void);
 #define NUM_TOUCH_BUTTONS 6
 #endif
 //LGFX_Button touchButtons[NUM_TOUCH_BUTTONS];
-LGFX_Button btnSpeedToggle    = LGFX_Button();
-LGFX_Button btnInclineToggle  = LGFX_Button();
-LGFX_Button btnSpeedUp        = LGFX_Button();
-LGFX_Button btnSpeedDown      = LGFX_Button();
-LGFX_Button btnInclineUp      = LGFX_Button();
-LGFX_Button btnInclineDown    = LGFX_Button();
+LGFX_Button btnSpeedToggle = LGFX_Button();
+LGFX_Button btnInclineToggle = LGFX_Button();
+LGFX_Button btnSpeedUp = LGFX_Button();
+LGFX_Button btnSpeedDown = LGFX_Button();
+LGFX_Button btnInclineUp = LGFX_Button();
+LGFX_Button btnInclineDown = LGFX_Button();
 // 480 x 320, use full-top-half to show speed, incline, total_dist, and acc. elevation gain
 // maybe draw some nice gauges for speed/incline and odometers for dist and elevation
 // in addition might want to have an elevation profile being displayed
 // 260, 5, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "MODE");
 
-#define btnSpeedToggle_X       250
-#define btnSpeedToggle_Y         5
-#define btnInclineToggle_X     360
-#define btnInclineToggle_Y       5
-#define btnSpeedUp_X           250
-#define btnSpeedUp_Y           100
-#define btnSpeedDown_X         250
-#define btnSpeedDown_Y         170
-#define btnInclineUp_X         360
-#define btnInclineUp_Y         100
-#define btnInclineDown_X       360
-#define btnInclineDown_Y       170
+#define btnSpeedToggle_X 250
+#define btnSpeedToggle_Y 5
+#define btnInclineToggle_X 360
+#define btnInclineToggle_Y 5
+#define btnSpeedUp_X 250
+#define btnSpeedUp_Y 100
+#define btnSpeedDown_X 250
+#define btnSpeedDown_Y 170
+#define btnInclineUp_X 360
+#define btnInclineUp_Y 100
+#define btnInclineDown_X 360
+#define btnInclineDown_Y 170
 
 void initLovyanGFXTouchAreas(void)
- {
+{
   // for (unsigned n = 0; n < NUM_TOUCH_BUTTONS; ++n) {
   //     touchButtons[n] = LGFX_Button();
   // }
   // fixme: ...
   //logText("initLovyanGFXTouchAreas...");
-  btnSpeedToggle   .initButtonUL(&tft, btnSpeedToggle_X,    btnSpeedToggle_Y,   100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "SPEED");
-  btnInclineToggle .initButtonUL(&tft, btnInclineToggle_X,  btnInclineToggle_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "INCL.");
-  btnSpeedUp       .initButtonUL(&tft, btnSpeedUp_X,        btnSpeedUp_Y,       100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "UP");
-  btnSpeedDown     .initButtonUL(&tft, btnSpeedDown_X,      btnSpeedDown_Y,     100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "DOWN");
-  btnInclineUp     .initButtonUL(&tft, btnInclineUp_X,      btnInclineUp_Y,     100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "UP");
-  btnInclineDown   .initButtonUL(&tft, btnInclineDown_X,    btnInclineDown_Y,   100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "DOWN");
+  btnSpeedToggle.initButtonUL(&tft, btnSpeedToggle_X, btnSpeedToggle_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE,
+                              "SPEED");
+  btnInclineToggle.initButtonUL(&tft, btnInclineToggle_X, btnInclineToggle_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE,
+                                "INCL.");
+  btnSpeedUp.initButtonUL(&tft, btnSpeedUp_X, btnSpeedUp_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "UP");
+  btnSpeedDown.initButtonUL(&tft, btnSpeedDown_X, btnSpeedDown_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "DOWN");
+  btnInclineUp.initButtonUL(&tft, btnInclineUp_X, btnInclineUp_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "UP");
+  btnInclineDown.initButtonUL(&tft, btnInclineDown_X, btnInclineDown_Y, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE,
+                              "DOWN");
   //modeButton.initButtonUL(&tft, 260, 5, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "MODE");
   //modeButton.drawButton();
 }
 #endif
 
-
-
 void tft_initDisplay(void)
 {
   tft.fillScreen(TFT_BLACK);
@@ -128,7 +129,7 @@ void tft_initDisplay(void)
 #if defined(HAS_TOUCH_DISPLAY) && defined(TOUCH_CALLIBRATION_AT_STARTUP)
   if (tft.touch()) {
     tft.setTextFont(4);
-    tft.setCursor(20, tft.height()/2);
+    tft.setCursor(20, tft.height() / 2);
     tft.println("Press corner near arrow to callibrate touch");
     tft.setCursor(0, 0);
     tft.calibrateTouch(nullptr, TFT_WHITE, TFT_BLACK, std::max(tft.width(), tft.height()) >> 3);
@@ -158,18 +159,18 @@ void tft_gfxUpdateDisplay(bool clear)
 // FIXME: is that a "good" way to handle different (touch) screen ...!??
 #if defined(TARGET_WT32_SC01)
   if (clear) {
-      // create buttons
-      //modeButton.initButtonUL(&tft, 260, 5, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "MODE");
-
-  // for (uint8_t row=0; row<5; row++) {
-  //     for (uint8_t col=0; col<3; col++) {
-  //	  buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
-  //					  BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
-  //					  BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
-  //					  buttonlabels[col + row*3], BUTTON_TEXTSIZE);
-  //	  buttons[col + row*3].drawButton();
-  //   }
-  // }
+    // create buttons
+    //modeButton.initButtonUL(&tft, 260, 5, 100, 50, TFT_WHITE, TFT_BLUE, TFT_WHITE, "MODE");
+
+    // for (uint8_t row=0; row<5; row++) {
+    //     for (uint8_t col=0; col<3; col++) {
+    //	  buttons[col + row*3].initButton(&tft, BUTTON_X+col*(BUTTON_W+BUTTON_SPACING_X),
+    //					  BUTTON_Y+row*(BUTTON_H+BUTTON_SPACING_Y),    // x, y, w, h, outline, fill, text
+    //					  BUTTON_W, BUTTON_H, ILI9341_WHITE, buttoncolors[col+row*3], ILI9341_WHITE,
+    //					  buttonlabels[col + row*3], BUTTON_TEXTSIZE);
+    //	  buttons[col + row*3].drawButton();
+    //   }
+    // }
 
     // draw touch control buttons within DRAW_CTRL_WIDTH/HEIGHT
 
@@ -179,20 +180,18 @@ void tft_gfxUpdateDisplay(bool clear)
     // tft.fillRect(330,  90,  50,  30, TFT_BLUE);   // speed up
     // tft.fillRect(330, 130,  50,  30, TFT_YELLOW); // speed down
 
-
-    btnSpeedToggle   .drawButton();
-    btnInclineToggle .drawButton();
-    btnSpeedUp       .drawButton();
-    btnSpeedDown     .drawButton();
-    btnInclineUp     .drawButton();
-    btnInclineDown   .drawButton();
-
+    btnSpeedToggle.drawButton();
+    btnInclineToggle.drawButton();
+    btnSpeedUp.drawButton();
+    btnSpeedDown.drawButton();
+    btnInclineUp.drawButton();
+    btnInclineDown.drawButton();
   }
 
   if (clear) {
     //tft.drawRect(1, 1, DRAW_WIDTH - 2, 20, TFT_GREENYELLOW);
-    tft.drawFastVLine(DRAW_WIDTH / 2, 22,                   DRAW_HEIGHT - 22, TFT_WHITE);
-    tft.drawFastHLine(1,              DRAW_HEIGHT / 2 + 20, DRAW_WIDTH  -  2, TFT_WHITE);
+    tft.drawFastVLine(DRAW_WIDTH / 2, 22, DRAW_HEIGHT - 22, TFT_WHITE);
+    tft.drawFastHLine(1, DRAW_HEIGHT / 2 + 20, DRAW_WIDTH - 2, TFT_WHITE);
 
     tft.setTextFont(2);
 
@@ -227,7 +226,7 @@ void tft_gfxUpdateDisplay(bool clear)
   tft.fillRect(0, DRAW_HEIGHT - 26, DRAW_WIDTH / 4 + 10, 40, TFT_BLACK);
   tft.setCursor(4, DRAW_HEIGHT - 20);
   tft.setTextFont(4);
-  tft.println(totalDistance/1000);
+  tft.println(totalDistance / 1000);
 
   // elevation bot right
   tft.fillRect(DRAW_WIDTH / 2 + 2, DRAW_HEIGHT - 26, DRAW_WIDTH / 4 + 10, 40, TFT_BLACK);
@@ -237,8 +236,8 @@ void tft_gfxUpdateDisplay(bool clear)
 #else
   if (clear) {
     //tft.drawRect(1, 1, DRAW_WIDTH - 2, 20, TFT_GREENYELLOW);
-    tft.drawFastVLine(DRAW_WIDTH / 2, 22,                   DRAW_HEIGHT - 22, TFT_WHITE);
-    tft.drawFastHLine(1,              DRAW_HEIGHT / 2 + 20, DRAW_WIDTH  -  2, TFT_WHITE);
+    tft.drawFastVLine(DRAW_WIDTH / 2, 22, DRAW_HEIGHT - 22, TFT_WHITE);
+    tft.drawFastHLine(1, DRAW_HEIGHT / 2 + 20, DRAW_WIDTH - 2, TFT_WHITE);
 
     tft.setTextFont(2);
 
@@ -273,7 +272,7 @@ void tft_gfxUpdateDisplay(bool clear)
   tft.fillRect(0, DRAW_HEIGHT - 26, DRAW_WIDTH / 4, 40, TFT_BLACK);
   tft.setCursor(4, DRAW_HEIGHT - 20);
   tft.setTextFont(4);
-  tft.println(totalDistance/1000);
+  tft.println(totalDistance / 1000);
 
   // elevation bot right
   tft.fillRect(DRAW_WIDTH / 2 + 2, DRAW_HEIGHT - 26, DRAW_WIDTH / 4, 40, TFT_BLACK);
@@ -285,12 +284,10 @@ void tft_gfxUpdateDisplay(bool clear)
 #endif // NO_DISPLAY
 }
 
-
-
 void tft_loopHandleGfx(void)
 {
 #ifndef NO_DISPLAY
-#if defined (HAS_TOUCH_DISPLAY)
+#if defined(HAS_TOUCH_DISPLAY)
   int32_t touch_x = 0, touch_y = 0;
 
   //logText("loop handle touch..\n");
@@ -306,37 +303,52 @@ void tft_loopHandleGfx(void)
   //DEBUG_PRINTF("loopHandleTouch() -> %d,%d\n",touch_x,touch_y);
 
   // FIXME: switch to button array (touchButtons[]) and cycle through buttons here
-  if (btnSpeedToggle.contains(touch_x, touch_y)) btnSpeedToggle.press(true);
-  else                                           btnSpeedToggle.press(false);
-
-  if (btnInclineToggle.contains(touch_x, touch_y)) btnInclineToggle.press(true);
-  else                                             btnInclineToggle.press(false);
-
-  if (btnSpeedUp.contains(touch_x, touch_y)) btnSpeedUp.press(true);
-  else                                       btnSpeedUp.press(false);
-
-  if (btnSpeedDown.contains(touch_x, touch_y)) btnSpeedDown.press(true);
-  else                                         btnSpeedDown.press(false);
-
-  if (btnInclineUp.contains(touch_x, touch_y)) btnInclineUp.press(true);
-  else                                         btnInclineUp.press(false);
-
-  if (btnInclineDown.contains(touch_x, touch_y)) btnInclineDown.press(true);
-  else                                           btnInclineDown.press(false);
-
+  if (btnSpeedToggle.contains(touch_x, touch_y))
+    btnSpeedToggle.press(true);
+  else
+    btnSpeedToggle.press(false);
+
+  if (btnInclineToggle.contains(touch_x, touch_y))
+    btnInclineToggle.press(true);
+  else
+    btnInclineToggle.press(false);
+
+  if (btnSpeedUp.contains(touch_x, touch_y))
+    btnSpeedUp.press(true);
+  else
+    btnSpeedUp.press(false);
+
+  if (btnSpeedDown.contains(touch_x, touch_y))
+    btnSpeedDown.press(true);
+  else
+    btnSpeedDown.press(false);
+
+  if (btnInclineUp.contains(touch_x, touch_y))
+    btnInclineUp.press(true);
+  else
+    btnInclineUp.press(false);
+
+  if (btnInclineDown.contains(touch_x, touch_y))
+    btnInclineDown.press(true);
+  else
+    btnInclineDown.press(false);
 
   if (btnSpeedToggle.justPressed()) {
     logText("loopHandleTouch() speed mode toggle!\n");
     speedInclineMode ^= SPEED; // b'01 toggle bit
-    if (speedInclineMode & SPEED) btnSpeedToggle.drawButton();
-    else                          btnSpeedToggle.drawButton(true);
+    if (speedInclineMode & SPEED)
+      btnSpeedToggle.drawButton();
+    else
+      btnSpeedToggle.drawButton(true);
     tft_gfxUpdateHeader();
   }
   if (btnInclineToggle.justPressed()) {
     logText("loopHandleTouch() incline mode toggle!\n");
     speedInclineMode ^= INCLINE; // b'10
-    if (speedInclineMode & INCLINE) btnInclineToggle.drawButton();
-    else                            btnInclineToggle.drawButton(true);
+    if (speedInclineMode & INCLINE)
+      btnInclineToggle.drawButton();
+    else
+      btnInclineToggle.drawButton(true);
     tft_gfxUpdateHeader();
   }
 
@@ -372,13 +384,12 @@ void tft_loopHandleGfx(void)
 
 #endif
 #endif //#ifndef NO_DISPLAY
-
 }
 
-
 #ifndef NO_DISPLAY
 
-static void tft_gfxUpdateHeaderWIFIStatus(const unsigned long reconnect_counter, const String &ip) {
+static void tft_gfxUpdateHeaderWIFIStatus(const unsigned long reconnect_counter, const String& ip)
+{
   //tft.fillRect(2, 2, 60, 18, TFT_BLACK);
   int32_t cursorX = tft.getCursorX();
   int32_t cursorY = tft.getCursorY();
@@ -399,8 +410,7 @@ static void tft_gfxUpdateHeaderBTStatus(bool connected)
 {
   if (connected) {
     tft.fillCircle(CIRCLE_BT_STAT_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_SKYBLUE);
-  }
-  else {
+  } else {
     tft.fillCircle(CIRCLE_BT_STAT_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_BLACK);
     tft.drawCircle(CIRCLE_BT_STAT_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_SKYBLUE);
   }
@@ -422,16 +432,14 @@ static void tft_gfxUpdateHeaderSpeedInclineMode(uint8_t mode)
   // green: sensor/auto mode
   // red  : manual mode (via website, or buttons)
   if (mode & SPEED) {
-      tft.fillCircle(CIRCLE_SPEED_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_GREEN);
-  }
-  else if ((mode & SPEED) == 0) {
+    tft.fillCircle(CIRCLE_SPEED_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_GREEN);
+  } else if ((mode & SPEED) == 0) {
     tft.fillCircle(CIRCLE_SPEED_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_RED);
   }
 
   if (mode & INCLINE) {
-      tft.fillCircle(CIRCLE_INCLINE_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_GREEN);
-  }
-  else if ((mode & INCLINE) == 0) {
+    tft.fillCircle(CIRCLE_INCLINE_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_GREEN);
+  } else if ((mode & INCLINE) == 0) {
     tft.fillCircle(CIRCLE_INCLINE_X_POS, CIRCLE_Y_POS, CIRCLE_RADIUS, TFT_RED);
   }
 }
diff --git a/src/hardware.cpp b/src/hardware.cpp
index 33c7862..070e0c1 100644
--- a/src/hardware.cpp
+++ b/src/hardware.cpp
@@ -36,22 +36,22 @@ esp_reset_reason_t reset_reason;
 unsigned long sw_timer_clock = 0;
 
 // IRSensor - interrupt sensors to measure speed on GPIO:
-#define SPEED_IR_SENSOR1   15
-#define SPEED_IR_SENSOR2   13
+#define SPEED_IR_SENSOR1 15
+#define SPEED_IR_SENSOR2 13
 volatile unsigned long t1;
 volatile unsigned long t2;
 volatile bool t1_valid = false;
 volatile bool t2_valid = false;
 
 bool timer_tick; // Every second
-static constexpr int AW9523_INTERRUPT_PIN  = 25; // GPIO Extender interrupt
+static constexpr int AW9523_INTERRUPT_PIN = 25; // GPIO Extender interrupt
 static constexpr int SPEED_REED_SWITCH_PIN = 26; // REED-Contact
 
-volatile unsigned long startTime = 0;     // start of revolution in microseconds
+volatile unsigned long startTime = 0; // start of revolution in microseconds
 volatile unsigned long longpauseTime = 0; // revolution time with no reed-switch interrupt
-volatile long accumulatorInterval = 0;    // time sum between display during intervals
-volatile unsigned int revCount = 0;       // number of revolutions since last display update
-volatile long accumulator4 = 0;           // sum of last 4 rpm times over 4 seconds
+volatile long accumulatorInterval = 0; // time sum between display during intervals
+volatile unsigned int revCount = 0; // number of revolutions since last display update
+volatile long accumulator4 = 0; // sum of last 4 rpm times over 4 seconds
 volatile long workoutDistance = 0; // FIXME: vs. total_dist ... select either reed/ir/manual
 
 // PINS
@@ -63,16 +63,16 @@ volatile long workoutDistance = 0; // FIXME: vs. total_dist ... select either re
 #if TARGET_TTGO_T_DISPLAY
 // TTGO T-Display buttons
 #define BUTTON_1 35
-#define BUTTON_2  0
+#define BUTTON_2 0
 #elif TARGET_WT32_SC01
 // This is a touch screen so there is no buttons
 // IO_21 and IO_22 are routed out and use used for SPI to the screen
 // Pins with names that start with J seems to be connected so screen, take care to avoid.
 #elif TARGET_TTGO_T4
 // no-touch screen with three buttons
-#define BUTTON_1 38  // LEFT
-#define BUTTON_2 37  // CENTRE
-#define BUTTON_3 39  // RIGHT
+#define BUTTON_1 38 // LEFT
+#define BUTTON_2 37 // CENTRE
+#define BUTTON_3 39 // RIGHT
 #elif TARGET_WT32_WROOMD
 // no display or buttons, web only
 #else
@@ -127,21 +127,19 @@ void btn1TapHandler(Button2& b)
   DEBUG_PRINTLN("Button 1 TapHandler");
 
   if (time > 3000) {
-   // > 3sec enters config menu
+    // > 3sec enters config menu
     DEBUG_PRINTLN("RESET timer/counter!");
     doReset();
-  }
-  else if (time > 600) {
+  } else if (time > 600) {
     DEBUG_PRINTLN("Button 1 long click...");
     // reset to manual mode
     speedInclineMode = MANUAL;
     DEBUG_PRINT("speedInclineMode=");
-      DEBUG_PRINTLN(speedInclineMode);
+    DEBUG_PRINTLN(speedInclineMode);
 #ifndef NO_DISPLAY
     gfxUpdateHeader();
 #endif
-  }
-  else {
+  } else {
     // button1 short click toggle speed/incline mode
     DEBUG_PRINTLN("Button 1 short click...");
     speedInclineMode += 1;
@@ -161,8 +159,7 @@ void btn2TapHandler(Button2& b)
 
   if (time > 3000) { // > 3sec enters config menu
     //DEBUG_PRINTLN("very long (>3s) click ... do nothing");
-  }
-  else if (time > 500) {
+  } else if (time > 500) {
     DEBUG_PRINTLN("long (>500ms) click...");
     if ((speedInclineMode & SPEED) == 0) {
       speedDown();
@@ -170,8 +167,7 @@ void btn2TapHandler(Button2& b)
     if ((speedInclineMode & INCLINE) == 0) {
       inclineDown();
     }
-  }
-  else {
+  } else {
     DEBUG_PRINTLN("short click...");
     if ((speedInclineMode & SPEED) == 0) {
       speedUp();
@@ -182,15 +178,13 @@ void btn2TapHandler(Button2& b)
   }
 }
 
-
 void btn3TapHandler(Button2& b)
 {
   unsigned int time = b.wasPressedFor();
   DEBUG_PRINTLN("Button 3 TapHandler");
   if (time > 3000) {
     // DEBUG_PRINTLN("very long (>3s) click ... do nothing");
-  }
-  else {
+  } else {
     DEBUG_PRINTLN("short click...");
     if ((speedInclineMode & SPEED) == 0) {
       speedDown();
@@ -210,7 +204,7 @@ void loopHandleButton()
   btn2.loop();
 #endif
 #ifdef BUTTON_3
-    btn3.loop();
+  btn3.loop();
 #endif
 }
 
@@ -232,7 +226,7 @@ void initButton()
   // short  click = up
   // longer click = down
   btn2.setTapHandler(btn2TapHandler);
- #endif
+#endif
 
 #ifdef BUTTON_3
   // short  click = down
@@ -245,14 +239,13 @@ void delayWithDisplayUpdate(unsigned long delayMilli)
 {
   unsigned long timeStartMilli = millis();
   unsigned long currentMilli = timeStartMilli;
-  while((currentMilli - timeStartMilli) < delayMilli) {
+  while ((currentMilli - timeStartMilli) < delayMilli) {
 #warning todo cs: add gxloop handler again.
-//    gfxUpdateLoopHandler();
-    unsigned long timeLeftMilli = delayMilli - (currentMilli - timeStartMilli) ;
-    if (timeLeftMilli >= 5 ) {
+    //    gfxUpdateLoopHandler();
+    unsigned long timeLeftMilli = delayMilli - (currentMilli - timeStartMilli);
+    if (timeLeftMilli >= 5) {
       delay(5);
-    }
-    else {
+    } else {
       delay(timeLeftMilli);
     }
     currentMilli = millis();
@@ -274,8 +267,7 @@ void initSensors(void)
       logText(" failed (DISABLED)\n");
       configTreadmill.hasMPU6050 = false;
       // TODO Would we want to retry, now, later, by config or is power off/on good enough
-    }
-    else {
+    } else {
       logText("Calc offsets, do not move MPU6050 (3sec)");
 
       mpu6050.calcOffsets(); // gyro and accel.
@@ -284,7 +276,7 @@ void initSensors(void)
 
       logText(" done\n");
     }
-//    I2C_0.end();
+    //    I2C_0.end();
   }
 }
 // ------------------ Mesure speed with something triggering a GPIO pin periodicle
@@ -303,7 +295,7 @@ void IRAM_ATTR reedSwitch_ISR()
   }
 
   //if (test_elapsed > 1000000) {
-  if (test_elapsed > 1000000) {  // assume the treadmill isn't spinning in 1 second.
+  if (test_elapsed > 1000000) { // assume the treadmill isn't spinning in 1 second.
     startTime = usNow; // reset the clock;
     longpauseTime = 0;
     return;
@@ -312,7 +304,7 @@ void IRAM_ATTR reedSwitch_ISR()
     // acts as a debounce, don't looking for interupts soon after the first hit.
     //DEBUG_PRINT(test_elapsed); //DEBUG_PRINTLN(" Counted");
 
-    startTime = usNow;  // reset the clock
+    startTime = usNow; // reset the clock
     //long elapsed = test_elapsed;
     longpauseTime = test_elapsed;
 
@@ -326,7 +318,7 @@ void IRAM_ATTR reedSwitch_ISR()
 // Messure two IR-Sensors
 static void IRAM_ATTR speedSensor1_ISR(void)
 {
-  if (! t1_valid) {
+  if (!t1_valid) {
     t1 = micros();
     t1_valid = true;
   }
@@ -344,7 +336,8 @@ static void IRAM_ATTR speedSensor2_ISR(void)
 // If a treadmill has some special placement of the angle sensor
 // here is where that value is converted from sensor read to proper angle of running area.
 
-double angleSensorTreadmillConversion(double inAngle) {
+double angleSensorTreadmillConversion(double inAngle)
+{
   double convertedAngle = inAngle;
 
   if (configTreadmill.hasMPU6050inAngle) {
@@ -366,9 +359,9 @@ double angleSensorTreadmillConversion(double inAngle) {
       x=c*sin(A)     x=a*sin(C)
       C=asin(c*sin(A)/a)
     */
-    double c = 32.0;  // lenght of motor part in cm TODO treadmill config?
+    double c = 32.0; // lenght of motor part in cm TODO treadmill config?
     double a = 150.0; // lenght of running area in cm TODO treadmill config?
-    convertedAngle = asin(c*sin(inAngle * DEG_TO_RAD)/a) * RAD_TO_DEG;
+    convertedAngle = asin(c * sin(inAngle * DEG_TO_RAD) / a) * RAD_TO_DEG;
   }
   return convertedAngle;
 }
@@ -392,8 +385,9 @@ float getIncline(void)
 
     angle = angleSensorTreadmillConversion(sensorAngle); // convert angle depending placment of mpu6050 on treadmill
 
-    if (angle < 0) angle = 0; // TODO We might allow running downhill, some threadmill support it and pratically
-                              //      you could put something under it on the back side
+    if (angle < 0)
+      angle = 0; // TODO We might allow running downhill, some threadmill support it and pratically
+    //      you could put something under it on the back side
 
     char yStr[5];
     snprintf(yStr, 5, "%.2f", angle);
@@ -410,8 +404,10 @@ float getIncline(void)
     // ******************************************
   }
 
-  if (temp_incline <= configTreadmill.min_incline) temp_incline = configTreadmill.min_incline;
-  if (temp_incline > configTreadmill.max_incline)  temp_incline = configTreadmill.max_incline;
+  if (temp_incline <= configTreadmill.min_incline)
+    temp_incline = configTreadmill.min_incline;
+  if (temp_incline > configTreadmill.max_incline)
+    temp_incline = configTreadmill.max_incline;
 
 #warning cs todo remove this
   DEBUG_PRINTF("sensor angle (%.2f): used angle: %.2f: -> incline: %f%%\n", sensorAngle, angle, temp_incline);
@@ -437,9 +433,9 @@ void loopHandleHardware(void)
   }
 
   if (configTreadmill.hasMPU6050) {
-    I2C_0.begin(SDA_0 , SCL_0 , I2C_FREQ);
-    mpu6050.update();  // read out data from the sensor
-//    I2C_0.end();
+    I2C_0.begin(SDA_0, SCL_0, I2C_FREQ);
+    mpu6050.update(); // read out data from the sensor
+    //    I2C_0.end();
   }
 
   // IrSensor to check speed
@@ -450,13 +446,13 @@ void loopHandleHardware(void)
     t = t2 - t1;
     // check ir-speed sensor if not manual mode
     if (t2_valid) {
-     // hasIrSense = detected
+      // hasIrSense = detected
       kmphIRsense = (float)(1.0 / t) * c;
       noInterrupts();
       t1_valid = false;
       t2_valid = false;
       interrupts();
-      DEBUG_PRINTF("IrSense: t=%li kmph_sense=%f\n",t,kmphIRsense);
+      DEBUG_PRINTF("IrSense: t=%li kmph_sense=%f\n", t, kmphIRsense);
     }
   }
 }
@@ -472,9 +468,10 @@ void handleEvent(EventType event)
   // in that case.
   // Currently there is no queue so if Events are translated to new events and call
   // handleEvent() to post them take care to not get into loops.
-  if (GPIOExtender.pressEvent(event)) return;
+  if (GPIOExtender.pressEvent(event))
+    return;
 
-  DEBUG_PRINTF("handleEvent() Cant handle Event:0x%x\n",static_cast<uint32_t>(event));
+  DEBUG_PRINTF("handleEvent() Cant handle Event:0x%x\n", static_cast<uint32_t>(event));
   return;
 }
 float calculateRPM(void)
@@ -483,15 +480,14 @@ float calculateRPM(void)
 
   if (configTreadmill.hasReed) {
     if (revCount > 0) {
-     // confirm there was at least one spin in the last second
+      // confirm there was at least one spin in the last second
       noInterrupts();
       temp_rpm = 60000000 / (accumulatorInterval / revCount);
       revCount = 0;
       accumulatorInterval = 0;
       interrupts();
     }
-  }
-  else {
+  } else {
     temp_rpm = 0;
     //rpmaccumulatorInterval = 0;
     //accumulator4 = 0;  // average rpm of last 4 samples
@@ -499,7 +495,8 @@ float calculateRPM(void)
   return temp_rpm;
 }
 
-static void initGPIOExtender(void) {
+static void initGPIOExtender(void)
+{
   logText("initGPIOExtender...");
   while (!GPIOExtender.begin()) {
     DEBUG_PRINTLN("GPIOExtender not found");
@@ -514,45 +511,46 @@ void GPIOExtenderAW9523::scanButtons(void)
   if (enabled) {
     static uint16_t prevKeys = 0;
     uint16_t pins = getPins();
-    uint16_t keys = ((~pins) & 0x3f );
-
-    if ( keys != prevKeys) {
-    // New key status
-    //DEBUG_PRINTF("GPIOExtender KEY IN:0x%x (0x%x)\n",keys,pins);
-
-    if ((keys & AW9523_KEY_UP) && AW9523_KEY_UP) {
-      DEBUG_PRINTLN("AW9523_KEY_UP");
-      handleEvent(EventType::KEY_UP);
-      //handleEvent(EventType::TREADMILL_INC_UP);
-    }
-    if ((keys & AW9523_KEY_LEFT) && AW9523_KEY_LEFT) {
-      DEBUG_PRINTLN("AW9523_KEY_LEFT");
-      handleEvent(EventType::KEY_LEFT);
-      //handleEvent(EventType::TREADMILL_SPEED_DOWN);
-    }
-    if ((keys & AW9523_KEY_DOWN) && AW9523_KEY_DOWN) {
-      DEBUG_PRINTLN("AW9523_KEY_DOWN");
-      handleEvent(EventType::KEY_DOWN);
-      //handleEvent(EventType::TREADMILL_INC_DOWN);
-    }
-    if ((keys & AW9523_KEY_RIGHT) && AW9523_KEY_RIGHT) {
-      DEBUG_PRINTLN("AW9523_KEY_RIGHT");
-      handleEvent(EventType::KEY_RIGHT);
-      //handleEvent(EventType::TREADMILL_SPEED_UP);
-    }
-    if ((keys & AW9523_KEY_OK) && AW9523_KEY_OK) {
-      DEBUG_PRINTLN("AW9523_KEY_OK");
-      handleEvent(EventType::KEY_OK);
-      //handleEvent(EventType::TREADMILL_START);
-    }
-    if ((keys & AW9523_KEY_BACK) && AW9523_KEY_BACK) {
-      DEBUG_PRINTLN("AW9523_KEY_BACK");
-      handleEvent(EventType::KEY_BACK);
-      //handleEvent(EventType::TREADMILL_STOP);
-    }
-
-    if ((keys & 0xffc0)  != 0)  DEBUG_PRINTF("Non key pins: 0x%x\n",keys);
-    prevKeys = keys;
+    uint16_t keys = ((~pins) & 0x3f);
+
+    if (keys != prevKeys) {
+      // New key status
+      //DEBUG_PRINTF("GPIOExtender KEY IN:0x%x (0x%x)\n",keys,pins);
+
+      if ((keys & AW9523_KEY_UP) && AW9523_KEY_UP) {
+        DEBUG_PRINTLN("AW9523_KEY_UP");
+        handleEvent(EventType::KEY_UP);
+        //handleEvent(EventType::TREADMILL_INC_UP);
+      }
+      if ((keys & AW9523_KEY_LEFT) && AW9523_KEY_LEFT) {
+        DEBUG_PRINTLN("AW9523_KEY_LEFT");
+        handleEvent(EventType::KEY_LEFT);
+        //handleEvent(EventType::TREADMILL_SPEED_DOWN);
+      }
+      if ((keys & AW9523_KEY_DOWN) && AW9523_KEY_DOWN) {
+        DEBUG_PRINTLN("AW9523_KEY_DOWN");
+        handleEvent(EventType::KEY_DOWN);
+        //handleEvent(EventType::TREADMILL_INC_DOWN);
+      }
+      if ((keys & AW9523_KEY_RIGHT) && AW9523_KEY_RIGHT) {
+        DEBUG_PRINTLN("AW9523_KEY_RIGHT");
+        handleEvent(EventType::KEY_RIGHT);
+        //handleEvent(EventType::TREADMILL_SPEED_UP);
+      }
+      if ((keys & AW9523_KEY_OK) && AW9523_KEY_OK) {
+        DEBUG_PRINTLN("AW9523_KEY_OK");
+        handleEvent(EventType::KEY_OK);
+        //handleEvent(EventType::TREADMILL_START);
+      }
+      if ((keys & AW9523_KEY_BACK) && AW9523_KEY_BACK) {
+        DEBUG_PRINTLN("AW9523_KEY_BACK");
+        handleEvent(EventType::KEY_BACK);
+        //handleEvent(EventType::TREADMILL_STOP);
+      }
+
+      if ((keys & 0xffc0) != 0)
+        DEBUG_PRINTF("Non key pins: 0x%x\n", keys);
+      prevKeys = keys;
     }
   }
 }
@@ -560,9 +558,9 @@ void GPIOExtenderAW9523::scanButtons(void)
 void GPIOExtenderAW9523::logPins(void)
 {
   if (enabled) {
-      uint8_t port0 = read(INPUT_PORT0);
-      uint8_t port1 = read(INPUT_PORT1);
-      DEBUG_PRINTF("GPIOExtenderAW9523 Read port:0x%x%x\n",port1,port0);
+    uint8_t port0 = read(INPUT_PORT0);
+    uint8_t port1 = read(INPUT_PORT1);
+    DEBUG_PRINTF("GPIOExtenderAW9523 Read port:0x%x%x\n", port1, port0);
   }
 }
 
@@ -574,16 +572,28 @@ bool GPIOExtenderAW9523::pressEvent(EventType eventButton)
     // convert event to HW line
     uint16_t line = -1;
     switch (eventButton) {
-      case EventType::TREADMILL_START:      line = AW9523_TREADMILL_START; break;
-      case EventType::TREADMILL_SPEED_DOWN: line = AW9523_TREADMILL_SPEED_DOWN; break;
-      case EventType::TREADMILL_INC_DOWN:   line = AW9523_TREADMILL_INC_DOWN; break;
-      case EventType::TREADMILL_STOP:       line = AW9523_TREADMILL_STOP; break;
-      case EventType::TREADMILL_SPEED_UP:   line = AW9523_TREADMILL_SPEED_UP; break;
-      case EventType::TREADMILL_INC_UP:     line = AW9523_TREADMILL_INC_UP; break;
-      default:
-        // Cant handle Event
-        DEBUG_PRINTF("GPIOExtenderAW9523 ERROR: Unknown event 0x%x\n", static_cast<uint32_t>(eventButton));
-        return false;
+    case EventType::TREADMILL_START:
+      line = AW9523_TREADMILL_START;
+      break;
+    case EventType::TREADMILL_SPEED_DOWN:
+      line = AW9523_TREADMILL_SPEED_DOWN;
+      break;
+    case EventType::TREADMILL_INC_DOWN:
+      line = AW9523_TREADMILL_INC_DOWN;
+      break;
+    case EventType::TREADMILL_STOP:
+      line = AW9523_TREADMILL_STOP;
+      break;
+    case EventType::TREADMILL_SPEED_UP:
+      line = AW9523_TREADMILL_SPEED_UP;
+      break;
+    case EventType::TREADMILL_INC_UP:
+      line = AW9523_TREADMILL_INC_UP;
+      break;
+    default:
+      // Cant handle Event
+      DEBUG_PRINTF("GPIOExtenderAW9523 ERROR: Unknown event 0x%x\n", static_cast<uint32_t>(eventButton));
+      return false;
     }
     if (line == -1) {
       DEBUG_PRINTF("GPIOExtenderAW9523 ERROR: event not converted to line 0x%x\n", static_cast<uint32_t>(eventButton));
@@ -597,34 +607,41 @@ bool GPIOExtenderAW9523::pressEvent(EventType eventButton)
                    line, port0Bit, ~port0Bit);
 
       // pinMode(pin, OUTPUT);
-      if (!write(CONFIG_PORT0, ~port0Bit)) return false; //0-output 1-input
+      if (!write(CONFIG_PORT0, ~port0Bit))
+        return false; //0-output 1-input
       // digitalWrite(pin, LOW);
-      if (!write(OUTPUT_PORT0, ~port0Bit)) return false; //0-low 1-high
+      if (!write(OUTPUT_PORT0, ~port0Bit))
+        return false; //0-low 1-high
 
 #warning Remove delay and schedule last part later in some way and go back to "main" loop mode.
       delay(TREADMILL_BUTTON_PRESS_SIGNAL_TIME_MS);
 
       // digitalWrite(pin, HIGH);
-      if (!write(OUTPUT_PORT0, 0xff)) return false; //0-low 1-high
+      if (!write(OUTPUT_PORT0, 0xff))
+        return false; //0-low 1-high
       // pinMode(pin, INPUT);
-      if (!write(CONFIG_PORT0, 0xff)) return false; //0-output 1-input
-    }
-    else {
+      if (!write(CONFIG_PORT0, 0xff))
+        return false; //0-output 1-input
+    } else {
       uint8_t port1Bit = (line & 0xff00) >> 8;
       DEBUG_PRINTF("GPIOExtenderAW9523: pressEvent(0x%x) -> 0x%x port1=0x%x ~x%x\n", static_cast<uint32_t>(eventButton),
                    line, port1Bit, ~port1Bit);
       // pinMode(pin, OUTPUT);
-      if (!write(CONFIG_PORT1, ~port1Bit)) return false; //0-output 1-input
+      if (!write(CONFIG_PORT1, ~port1Bit))
+        return false; //0-output 1-input
       // digitalWrite(pin, LOW);
-      if (!write(OUTPUT_PORT1, ~port1Bit)) return false; //0-low 1-high
+      if (!write(OUTPUT_PORT1, ~port1Bit))
+        return false; //0-low 1-high
 
 #warning Remove delay and schedule last part later in some way and go back to "main" loop mode.
       delay(TREADMILL_BUTTON_PRESS_SIGNAL_TIME_MS);
 
       // digitalWrite(pin, HIGH);
-      if (!write(OUTPUT_PORT1, 0xff)) return false; //0-low 1-high
+      if (!write(OUTPUT_PORT1, 0xff))
+        return false; //0-low 1-high
       // pinMode(pin, INPUT);
-      if (!write(CONFIG_PORT1, 0xff)) return false; //0-output 1-input
+      if (!write(CONFIG_PORT1, 0xff))
+        return false; //0-output 1-input
     }
     return true;
   }
@@ -647,7 +664,6 @@ uint8_t GPIOExtenderAW9523::read(uint8_t reg, bool i2cHandled)
     //I2C_0.end();
   }
   return ret;
-
 }
 
 uint8_t GPIOExtenderAW9523::read(uint8_t reg)
@@ -663,8 +679,8 @@ bool GPIOExtenderAW9523::write(uint8_t reg, uint8_t data)
   wire->beginTransmission(AW9523_ADDR);
   wire->write(reg);
   wire->write(data);
-  uint8_t ret = wire->endTransmission();  // 0 if OK
-//  I2C_0.end();
+  uint8_t ret = wire->endTransmission(); // 0 if OK
+  //  I2C_0.end();
   if (ret != 0) {
     DEBUG_PRINTF("GPIOExtenderAW9523 ERROR: write reg: 0x%x value:0x%x -> Error: 0x%x\n", reg, data, ret);
     return false;
@@ -683,20 +699,29 @@ bool GPIOExtenderAW9523::begin()
     return false;
   }
 
-  if (!write(OUTPUT_PORT0, 0xff)) return false; //0-low 1-high
-  if (!write(OUTPUT_PORT1, 0xff)) return false; //0-low 1-high
+  if (!write(OUTPUT_PORT0, 0xff))
+    return false; //0-low 1-high
+  if (!write(OUTPUT_PORT1, 0xff))
+    return false; //0-low 1-high
 
   // All input
-  if (!write(CONFIG_PORT0, 0xff)) return false; //0-output 1-input
-  if (!write(CONFIG_PORT1, 0xff)) return false; //0-output 1-input
-
-  if (!write(CTL, 0x08)) return false; //0000x000  0-Open Drain 1-Push-Pull
-
-  if (!write(INT_PORT0, 0xff)) return false; //0-enable 1-disable
-  if (!write(INT_PORT1, 0xff)) return false; //0-enable 1-disable
-
-  if (!write(LED_MODE_SWITCH0, 0xff)) return false; //0-LED mode 1-GPIO mode
-  if (!write(LED_MODE_SWITCH1, 0xff)) return false; //0-LED mode 1-GPIO mode
+  if (!write(CONFIG_PORT0, 0xff))
+    return false; //0-output 1-input
+  if (!write(CONFIG_PORT1, 0xff))
+    return false; //0-output 1-input
+
+  if (!write(CTL, 0x08))
+    return false; //0000x000  0-Open Drain 1-Push-Pull
+
+  if (!write(INT_PORT0, 0xff))
+    return false; //0-enable 1-disable
+  if (!write(INT_PORT1, 0xff))
+    return false; //0-enable 1-disable
+
+  if (!write(LED_MODE_SWITCH0, 0xff))
+    return false; //0-LED mode 1-GPIO mode
+  if (!write(LED_MODE_SWITCH1, 0xff))
+    return false; //0-LED mode 1-GPIO mode
   enabled = true;
   getPins();
   return true;
@@ -718,7 +743,7 @@ uint16_t GPIOExtenderAW9523::getPins(void)
     uint8_t port0 = read(INPUT_PORT0, true);
     uint8_t port1 = read(INPUT_PORT1, true);
 
-//    I2C_0.end();
+    //    I2C_0.end();
     return ((port1 << 8) | port0);
   }
   return 0;
@@ -748,19 +773,31 @@ void initHardware(void)
   initSensors();
 }
 
-const char* getRstReason(esp_reset_reason_t r) {
-  switch(r) {
-    case ESP_RST_UNKNOWN:    return "ESP_RST_UNKNOWN";   //!< Reset reason can not be determined
-    case ESP_RST_POWERON:    return "ESP_RST_POWERON";   //!< Reset due to power-on event
-    case ESP_RST_EXT:        return "ESP_RST_EXT";       //!< Reset by external pin (not applicable for ESP32)
-    case ESP_RST_SW:         return "ESP_RST_SW";        //!< Software reset via esp_restart
-    case ESP_RST_PANIC:      return "ESP_RST_PANIC";     //!< Software reset due to exception/panic
-    case ESP_RST_INT_WDT:    return "ESP_RST_INT_WDT";   //!< Reset (software or hardware) due to interrupt watchdog
-    case ESP_RST_TASK_WDT:   return "ESP_RST_TASK_WDT";  //!< Reset due to task watchdog
-    case ESP_RST_WDT:        return "ESP_RST_WDT";       //!< Reset due to other watchdogs
-    case ESP_RST_DEEPSLEEP:  return "ESP_RST_DEEPSLEEP"; //!< Reset after exiting deep sleep mode
-    case ESP_RST_BROWNOUT:   return "ESP_RST_BROWNOUT";  //!< Brownout reset (software or hardware)
-    case ESP_RST_SDIO:       return "ESP_RST_SDIO";      //!< Reset over SDIO
+const char* getRstReason(esp_reset_reason_t r)
+{
+  switch (r) {
+  case ESP_RST_UNKNOWN:
+    return "ESP_RST_UNKNOWN"; //!< Reset reason can not be determined
+  case ESP_RST_POWERON:
+    return "ESP_RST_POWERON"; //!< Reset due to power-on event
+  case ESP_RST_EXT:
+    return "ESP_RST_EXT"; //!< Reset by external pin (not applicable for ESP32)
+  case ESP_RST_SW:
+    return "ESP_RST_SW"; //!< Software reset via esp_restart
+  case ESP_RST_PANIC:
+    return "ESP_RST_PANIC"; //!< Software reset due to exception/panic
+  case ESP_RST_INT_WDT:
+    return "ESP_RST_INT_WDT"; //!< Reset (software or hardware) due to interrupt watchdog
+  case ESP_RST_TASK_WDT:
+    return "ESP_RST_TASK_WDT"; //!< Reset due to task watchdog
+  case ESP_RST_WDT:
+    return "ESP_RST_WDT"; //!< Reset due to other watchdogs
+  case ESP_RST_DEEPSLEEP:
+    return "ESP_RST_DEEPSLEEP"; //!< Reset after exiting deep sleep mode
+  case ESP_RST_BROWNOUT:
+    return "ESP_RST_BROWNOUT"; //!< Brownout reset (software or hardware)
+  case ESP_RST_SDIO:
+    return "ESP_RST_SDIO"; //!< Reset over SDIO
   }
   return "INVALID";
 }
diff --git a/src/net-control.cpp b/src/net-control.cpp
index d892be6..a0c5b0a 100644
--- a/src/net-control.cpp
+++ b/src/net-control.cpp
@@ -27,11 +27,11 @@ TODO: Maybe we want to split this up in different files later? Lets see how it g
 */
 #define NIMBLE
 #include <ArduinoJson.h>
-#include <LittleFS.h>
-#include <PubSubClient.h>
 #include <ESPAsyncWebServer.h> //Local WebServer used to serve the configuration portal
 #include <ESPAsyncWiFiManager.h> //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
 #include <ElegantOTA.h>
+#include <LittleFS.h>
+#include <PubSubClient.h>
 #include <esp_mac.h>
 
 #include "common.h"
@@ -54,7 +54,6 @@ bool bleClientConnected = false;
 bool bleClientConnectedPrev = false;
 //bool stopWatchRunning = false;
 
-
 #ifdef MQTT_USE_SSL
 WiFiClientSecure espClient;
 #else
@@ -104,18 +103,12 @@ enum topics_t {
   MQTT_NUM_TOPICS
 };
 
-String mqtt_topics[]{"home/treadmill/%MQTTDEVICEID%/setconfig",
-  "home/treadmill/%MQTTDEVICEID%/state",
-  "home/treadmill/%MQTTDEVICEID%/version",
-  "home/treadmill/%MQTTDEVICEID%/ipaddr",
-  "home/treadmill/%MQTTDEVICEID%/rst",
-  "home/treadmill/%MQTTDEVICEID%/speed",
-  "home/treadmill/%MQTTDEVICEID%/rpm",
-  "home/treadmill/%MQTTDEVICEID%/incline",
-  "home/treadmill/%MQTTDEVICEID%/y_angle",
-  "home/treadmill/%MQTTDEVICEID%/dist",
-  "home/treadmill/%MQTTDEVICEID%/elegain"
-};
+String mqtt_topics[]{"home/treadmill/%MQTTDEVICEID%/setconfig", "home/treadmill/%MQTTDEVICEID%/state",
+                     "home/treadmill/%MQTTDEVICEID%/version",   "home/treadmill/%MQTTDEVICEID%/ipaddr",
+                     "home/treadmill/%MQTTDEVICEID%/rst",       "home/treadmill/%MQTTDEVICEID%/speed",
+                     "home/treadmill/%MQTTDEVICEID%/rpm",       "home/treadmill/%MQTTDEVICEID%/incline",
+                     "home/treadmill/%MQTTDEVICEID%/y_angle",   "home/treadmill/%MQTTDEVICEID%/dist",
+                     "home/treadmill/%MQTTDEVICEID%/elegain"};
 
 #ifdef ASYNC_TCP_SSL_ENABLED
 // if using board_build.embed_txtfiles instead of spiffs -> that would not require the callback for:
@@ -129,11 +122,11 @@ extern const uint8_t server_key_start[] asm("_binary_server_key_start");
 // note: Fitness Machine Feature is a mandatory characteristic (property_read)
 #define FTMSService BLEUUID((uint16_t)0x1826)
 
-BLEServer* pServer               = NULL;
-BLECharacteristic* pTreadmill    = NULL;
-BLECharacteristic* pFeature      = NULL;
+BLEServer* pServer = NULL;
+BLECharacteristic* pTreadmill = NULL;
+BLECharacteristic* pFeature = NULL;
 BLECharacteristic* pControlPoint = NULL;
-BLECharacteristic* pStatus       = NULL;
+BLECharacteristic* pStatus = NULL;
 BLEAdvertisementData advert;
 BLEAdvertisementData scan_response;
 BLEAdvertising* pAdvertising;
@@ -167,8 +160,7 @@ void loopHandleBLE()
 #ifndef NO_DISPLAY
     gfxUpdateHeader();
 #endif
-  }
-  else if (!bleClientConnected && bleClientConnectedPrev) {
+  } else if (!bleClientConnected && bleClientConnectedPrev) {
     bleClientConnectedPrev = false;
     logText("BT Client disconnected!\n");
 #ifndef NO_DISPLAY
@@ -227,14 +219,14 @@ void updateBLEdata(void)
   uint16_t inst_grade = 0;
   uint16_t inst_elevation_gain = 0;
   uint8_t treadmillData[34] = {};
-  uint16_t flags = 0x0018;  // b'000000011000
+  uint16_t flags = 0x0018; // b'000000011000
   //                             119876543210
   //                             20
 
   // get speed and incline ble ready
   uint16_t inst_speed = kmph * 100; // kilometer per hour with a resolution of 0.01
   inst_incline = incline * 10; // percent with a resolution of 0.1
-  inst_grade   = gradeDeg * 10;
+  inst_grade = gradeDeg * 10;
   inst_elevation_gain = elevationGain * 10;
 
   // now data is filled starting at bit0 and appended for the
@@ -302,8 +294,7 @@ void initWifi()
   if (!res) {
     isWifiAvailable = false;
     logText("failed\n");
-  }
-  else {
+  } else {
     isWifiAvailable = true;
     //if you get here you have connected to the WiFi
     ipAddr = WiFi.localIP().toString();
@@ -528,12 +519,12 @@ void notifyClientsWebSockets()
 {
   StaticJsonDocument<256> doc;
 
-  doc["speed"]          = kmph;
-  doc["incline"]        = incline;
+  doc["speed"] = kmph;
+  doc["incline"] = incline;
   doc["speed_interval"] = configTreadmill.speed_interval_step;
-  doc["sensor_mode"]    = speedInclineMode;
-  doc["distance"]       = totalDistance / 1000;
-  doc["elevation"]      = elevationGain;
+  doc["sensor_mode"] = speedInclineMode;
+  doc["distance"] = totalDistance / 1000;
+  doc["elevation"] = elevationGain;
   //doc["running"]      = stopWatchRunning;
   DEBUG_PRINTF("notifyClientsWebSockets: kmph=%f", kmph);
 
@@ -555,7 +546,7 @@ void handleWebSocketMessage(uint8_t* data, size_t len)
   }
 
   const char* command = doc["command"]; // e.g. "speed_interval"
-  const char* value   = doc["value"];   // e.g. "0.5", "down"
+  const char* value = doc["value"]; // e.g. "0.5", "down"
 
   if (strcmp(command, "sensor_mode") == 0) {
     if (strcmp(value, "speed") == 0)

@lefty01 lefty01 merged commit 20d2a5f into main Jan 6, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants