Skip to content

Commit

Permalink
Moved global variables to static local
Browse files Browse the repository at this point in the history
  • Loading branch information
GargiMan committed Dec 15, 2023
1 parent 55414b6 commit 1c1f3f6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion GlBoard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ VescUart VESC;
BluetoothSerial BT_PORT;
Preferences preferences;

bool hasClient = false;
int maxLightPower = pow(2, PWM_RESOLUTION) - 1;

void debug_message(const char *fmt, ...);
Expand Down Expand Up @@ -87,6 +86,7 @@ void setup() {
void loop() {

// update bluetooth connection status
static bool hasClient = false;
if (hasClient != BT_PORT.hasClient()) {
hasClient = BT_PORT.hasClient();
debug_message("Client %s", hasClient ? "connected" : "disconnected");
Expand Down
17 changes: 7 additions & 10 deletions GlControl.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

BluetoothSerial BT_PORT;

bool isConnected = false;

uint8_t lastPower = 0;
uint8_t power = 0;
bool reverse = false;
bool hold = false;
Expand All @@ -31,12 +28,6 @@ bool mode = false;
int modeThrottle = MAX_THROTTLE_POWER;
int modeBrake = MAX_BRAKE_POWER;

unsigned long lastTimeFrontLightButtonPressed = 0;
unsigned long lastTimeRearLightButtonPressed = 0;
unsigned long lastTimeHoldButtonPressed = 0;
unsigned long lastTimeDirectionSwitchButtonPressed = 0;
unsigned long lastTimeModeSwitchButtonPressed = 0;

void debug_message(const char *fmt, ...);
void throw_bt_buffer();
void verify_architecture();
Expand Down Expand Up @@ -80,6 +71,7 @@ void setup() {
void loop() {

// update bluetooth connection status
static bool isConnected = false;
if (isConnected != BT_PORT.connected()) {
isConnected = BT_PORT.connected();
debug_message("Server %s", isConnected ? "connected" : "disconnected");
Expand All @@ -92,6 +84,7 @@ void loop() {
read_inputs();

// send control data
static uint8_t lastPower = 0;
if (power != 0 || lastPower != power) {
lastPower = power;
send_control_data();
Expand Down Expand Up @@ -276,7 +269,7 @@ void send_config_data() {

void read_inputs() {
// read hold power button

static unsigned long lastTimeHoldButtonPressed = 0;
if (pinReadGPIO(HOLD_POWER_BUTTON_PIN)) {
lastTimeHoldButtonPressed = millis();
hold = true;
Expand All @@ -286,20 +279,23 @@ void read_inputs() {
}

// read front light button
static unsigned long lastTimeFrontLightButtonPressed = 0;
if (pinReadGPIO(FRONT_LIGHT_BUTTON_PIN) && millis() - lastTimeFrontLightButtonPressed > BUTTON_HOLD_TIME) {
lastTimeFrontLightButtonPressed = millis();
frontLight = true;
debug_message("Front light button pressed");
}

// read rear light button
static unsigned long lastTimeRearLightButtonPressed = 0;
if (pinReadGPIO(REAR_LIGHT_BUTTON_PIN) && millis() - lastTimeRearLightButtonPressed > BUTTON_HOLD_TIME) {
lastTimeRearLightButtonPressed = millis();
rearLight = true;
debug_message("Rear light button pressed");
}

// read mode button
static unsigned long lastTimeModeSwitchButtonPressed = 0;
if (pinReadGPIO(MODE_SWITCH_BUTTON_PIN) && millis() - lastTimeModeSwitchButtonPressed > BUTTON_HOLD_TIME) {
lastTimeModeSwitchButtonPressed = millis();
mode = true;
Expand Down Expand Up @@ -335,6 +331,7 @@ void read_inputs() {
}

// read direction button
static unsigned long lastTimeDirectionSwitchButtonPressed = 0;
if (pinReadGPIO(DIRECTION_SWITCH_BUTTON_PIN) && millis() - lastTimeDirectionSwitchButtonPressed > BUTTON_HOLD_TIME) {
lastTimeDirectionSwitchButtonPressed = millis();
reverse = !reverse;
Expand Down

0 comments on commit 1c1f3f6

Please sign in to comment.