-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move equipment stop button related functions from Software.ino to equ…
…ipmentstopbutton folder
- Loading branch information
Showing
3 changed files
with
66 additions
and
47 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
51 changes: 51 additions & 0 deletions
51
Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.cpp
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,51 @@ | ||
#include "comm_equipmentstopbutton.h" | ||
#include "../../include.h" | ||
|
||
// Parameters | ||
#ifdef EQUIPMENT_STOP_BUTTON | ||
const unsigned long equipment_button_long_press_duration = | ||
15000; // 15 seconds for long press in case of MOMENTARY_SWITCH | ||
const unsigned long equipment_button_debounce_duration = 200; // 200ms for debouncing the button | ||
unsigned long timeSincePress = 0; // Variable to store the time since the last press | ||
DebouncedButton equipment_stop_button; // Debounced button object | ||
#endif | ||
|
||
// Initialization functions | ||
#ifdef EQUIPMENT_STOP_BUTTON | ||
void init_equipment_stop_button() { | ||
//using external pullup resistors NC | ||
pinMode(EQUIPMENT_STOP_PIN, INPUT); | ||
// Initialize the debounced button with NC switch type and equipment_button_debounce_duration debounce time | ||
initDebouncedButton(equipment_stop_button, EQUIPMENT_STOP_PIN, NC, equipment_button_debounce_duration); | ||
} | ||
#endif // EQUIPMENT_STOP_BUTTON | ||
|
||
// Main functions | ||
|
||
#ifdef EQUIPMENT_STOP_BUTTON | ||
void monitor_equipment_stop_button() { | ||
|
||
ButtonState changed_state = debounceButton(equipment_stop_button, timeSincePress); | ||
|
||
if (equipment_stop_behavior == LATCHING_SWITCH) { | ||
if (changed_state == PRESSED) { | ||
// Changed to ON – initiating equipment stop. | ||
setBatteryPause(true, false, true); | ||
} else if (changed_state == RELEASED) { | ||
// Changed to OFF – ending equipment stop. | ||
setBatteryPause(false, false, false); | ||
} | ||
} else if (equipment_stop_behavior == MOMENTARY_SWITCH) { | ||
if (changed_state == RELEASED) { // button is released | ||
|
||
if (timeSincePress < equipment_button_long_press_duration) { | ||
// Short press detected, trigger equipment stop | ||
setBatteryPause(true, false, true); | ||
} else { | ||
// Long press detected, reset equipment stop state | ||
setBatteryPause(false, false, false); | ||
} | ||
} | ||
} | ||
} | ||
#endif // EQUIPMENT_STOP_BUTTON |
14 changes: 14 additions & 0 deletions
14
Software/src/communication/equipmentstopbutton/comm_equipmentstopbutton.h
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,14 @@ | ||
#ifndef _COMM_EQUIPMENTSTOPBUTTON_H_ | ||
#define _COMM__COMM_EQUIPMENTSTOPBUTTON_H__H_ | ||
|
||
#include "../../include.h" | ||
|
||
#ifdef EQUIPMENT_STOP_BUTTON | ||
#include "../../devboard/utils/debounce_button.h" | ||
#endif | ||
|
||
void init_equipment_stop_button(); | ||
|
||
void monitor_equipment_stop_button(); | ||
|
||
#endif |