Implement light flashing for low battery alert / disabled debugging by default
This commit is contained in:
parent
81eab5e545
commit
55bd8aff3d
48
src/src.ino
48
src/src.ino
|
@ -15,10 +15,10 @@
|
|||
// Various defines / pins / etc
|
||||
// TWEAK THESE ACCORDINGLY
|
||||
// //////////
|
||||
#define DEBUG true
|
||||
#define DEBUG false
|
||||
#define INTERACTIVE_DEBUG false
|
||||
#define USE_SLEEP false
|
||||
#define SLEEP_INTERVAL 1000 // miliseconds
|
||||
#define USE_SLEEP true
|
||||
#define SLEEP_INTERVAL 500 // miliseconds
|
||||
#define ALERT_LEVEL 15 // battery alert level (%) [1-32% are valid values here]
|
||||
#define POT_BRIGHT A0
|
||||
#define POT_COLOR A1
|
||||
|
@ -32,7 +32,7 @@
|
|||
// Objects / values / etc
|
||||
// //////////
|
||||
MAX1704 fuelGauge;
|
||||
Metro timer = Metro(1000); // Timer for battery level alert (flashes pixels red or yellow [if red set]) to alert
|
||||
Metro timer = Metro(2000); // Timer for battery level alert (flashes pixels red or yellow [if red set]) to alert
|
||||
float charge_percent;
|
||||
uint8_t brightness;
|
||||
uint16_t raw_color;
|
||||
|
@ -54,6 +54,7 @@ void print_debug(); // Print debugging info if debug if debugging output is enab
|
|||
void read_values(); // Read values from various sensors/devices
|
||||
void do_low_power(); // Enable sleep / low power mode(s) as appropriate
|
||||
void pixel_update(); // Update pixel colors, on/off state, etc as appropriate
|
||||
bool show_low_battery_alert(); // Whether or not the low battery alert is to be shown
|
||||
ISR(WDT_vect) { Sleepy::watchdogEvent(); } // Setup the watchdog -- For sleepy
|
||||
|
||||
// //////////
|
||||
|
@ -141,6 +142,10 @@ void read_values() {
|
|||
// Update pixels appropriately (on/off, color, etc)
|
||||
// ///////////
|
||||
void pixel_update() {
|
||||
// Store temp variable for alert showing so it doesn't change mid-run
|
||||
// Metro timer is checked and is a method call that can/will change during this code block / method
|
||||
bool pix_show_alert = show_low_battery_alert();
|
||||
|
||||
// Set RGB array to values as appropriate
|
||||
if (white) {
|
||||
rgb[0] = rgb[1] = rgb[2] = 255;
|
||||
|
@ -150,20 +155,21 @@ void pixel_update() {
|
|||
color = map(raw_color, 0, 1024, 0, 360);
|
||||
hsvToRgb(color, 1, 1); // set rgb byte array
|
||||
}
|
||||
|
||||
// Set to red/yellow for alert if alerting and the timer has run out
|
||||
if (pix_show_alert) {
|
||||
if (color <= red_threshold && !white) {
|
||||
rgb[0] = 0;
|
||||
rgb[1] = rgb[2] = 255;
|
||||
}
|
||||
else {
|
||||
rgb[0] = 255;
|
||||
rgb[1] = rgb[2] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Set color accordingly
|
||||
for (uint8_t i=0; i<NEO_PIX_NUM; i++) {
|
||||
// Set to red/yellow for alert if alerting and the timer has run out
|
||||
if (fuelGauge.isAlerting() && timer.check() == 1) {
|
||||
if (color <= red_threshold) {
|
||||
rgb[0] = 0;
|
||||
rgb[1] = rgb[2] = 255;
|
||||
}
|
||||
else {
|
||||
rgb[0] = 255;
|
||||
rgb[1] = rgb[2] = 0;
|
||||
}
|
||||
}
|
||||
neopix.setPixelColor(i, neopix.Color(rgb[0], rgb[1], rgb[2]));
|
||||
}
|
||||
|
||||
|
@ -175,6 +181,11 @@ void pixel_update() {
|
|||
|
||||
// Apply changes
|
||||
neopix.show();
|
||||
|
||||
// Introduce brief delay so there is a visible flicker when alerting
|
||||
if (pix_show_alert) {
|
||||
delay(500);
|
||||
}
|
||||
}
|
||||
|
||||
// //////////
|
||||
|
@ -202,6 +213,13 @@ void do_low_power() {
|
|||
}
|
||||
}
|
||||
|
||||
// //////////
|
||||
// Figure out if the low battery alert needs to be shown
|
||||
// //////////
|
||||
bool show_low_battery_alert() {
|
||||
return fuelGauge.isAlerting() && timer.check() == 1;
|
||||
}
|
||||
|
||||
// //////////
|
||||
// Print debugging info
|
||||
// //////////
|
||||
|
|
Reference in a new issue