-
Notifications
You must be signed in to change notification settings - Fork 4
/
balance_beeper.cpp
51 lines (42 loc) · 1.32 KB
/
balance_beeper.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "beeper.cpp"
#define BEEPER_PIN 4
#define PLAY_STARTUP true
#define DUTY_CYCLE_ALERT 0.80 // 0 to disable
#define SWITCH_ERPM 1000 // 0 to disable
#define LOW_VOLTAGE 40.0 // 0 to disable
#define LOW_VOLTAGE_INTERVAL 30 * 1000 // every 30 seconds
class BalanceBeeper {
private:
Beeper beeper;
bool switchStateLatch = false;
long lastLowVoltageMillis = 0;
public:
BalanceBeeper() :
beeper(BEEPER_PIN){
}
void setup(){
beeper.setup();
if(PLAY_STARTUP){
beeper.queueThreeShort();
}
}
void loop(double dutyCycle, double erpm, uint16_t switchState, double voltage){
beeper.loop();
// Non latching beeps for Duty Cycle
if(fabsf(dutyCycle) > DUTY_CYCLE_ALERT && DUTY_CYCLE_ALERT > 0){
beeper.queueShortSingle();
}
// Latching beep for HALF footpad state
if(switchState == 1 && fabsf(erpm) > SWITCH_ERPM && SWITCH_ERPM > 0 && switchStateLatch == false){
switchStateLatch = true;
beeper.queueLongSingle();
}else if(switchState != 1){
switchStateLatch = false;
}
// Low voltage, time based repeat
if(voltage < LOW_VOLTAGE && LOW_VOLTAGE > 0 && lastLowVoltageMillis + LOW_VOLTAGE_INTERVAL < millis()){
beeper.queueSad();
lastLowVoltageMillis = millis();
}
}
};