Skip to content

Commit c0e830f

Browse files
committed
Battery alarm block at 550 for USB plug-in power
1 parent 68aad66 commit c0e830f

File tree

1 file changed

+52
-30
lines changed

1 file changed

+52
-30
lines changed

HandRemote/Firmware/HandRemote/HandRemote.ino

Lines changed: 52 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
* @remarks Version 2017.04.26
55
* @todo
66
* - Implement Firmata for Base/Desktop operation
7-
* - Make so default on Set is Opposite of last reading
87
* @authors
98
* tgit23 01/2017 Original
109
**********************************************************************************************************************/
@@ -72,14 +71,17 @@ unsigned long last_bpress = 0; // Track last button press time
7271
unsigned long last_change = 0; // Track last status iteration time
7372
int idx = 0; // Track Menu index item
7473
int SubIdx = 0; // Track current menu value item
74+
int ButtonHeld = 0; // Increment values by 10 when button is held
7575
bool AlarmActive = false; // Track if an Active Alarm is present
76+
bool bIterating = false; // Alarm only active while iterating the menu
7677
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7778

7879
//=====================================================================================================================
7980
//------------------------------ MENU STRUCTURE ( CONFIGURABLE ) ------------------------------------------------------
8081
//=====================================================================================================================
8182
//---[ MENU-ITEMS USED IN THE FIRMWARE ]--
8283
#define MONITOR 0 // Menu[MONITOR] tells the firmware to monitor only selected or all pumps
84+
#define BATT 1 // Menu[BATT] monitors the battery voltage level
8385
#define PUMPIDX 2 // Menu[PUMPIDX] the Menu-index of Selected Pump-Controller
8486

8587
#define NUM_MENU_ITEMS 7 //<<<<<<<<<<<<<<< MUST MATCH NUMBER OF MENU ITEMS DEFINED !!!!!!!!!!!!!!!!!!
@@ -129,9 +131,9 @@ void SetupMenu() {
129131
Menu[MONITOR].LastOptionIdx = 1; // Last Option Index defined - Number of Options - 1
130132

131133
//-----------------------------------------
132-
Menu[1].Text = "Battery(B)"; // Create a menu item for monitoring the Battery
133-
Menu[1].Location = HAND_PIN+ A+1; // Battery level is gotten from the Hand-Remote pin A1
134-
Menu[1].Sub[LOALARM].ID = 'b'; // A Low Alarm is identified by a lower-case 'b'
134+
Menu[BATT].Text = "Battery(B)"; // Create a menu item for monitoring the Battery
135+
Menu[BATT].Location = HAND_PIN+ A+1; // Battery level is gotten from the Hand-Remote pin A1
136+
Menu[BATT].Sub[LOALARM].ID = 'b'; // A Low Alarm is identified by a lower-case 'b'
135137

136138
//-------------------------------------------------------------------------------------------------------------------
137139
Menu[PUMPIDX].Text = "Pump"; // Menu Item used to select the Pump-Controller
@@ -333,23 +335,26 @@ void GetItem(int i = -1) {
333335
if ( i == PUMPIDX && Menu[i].Sub[MAIN].State == VALID ) { // New Pump Selection
334336
SetPump( Menu[i].Option[ Menu[i].Sub[MAIN].Value ].Value ); // SetPump(TRANSCEIER_ID)
335337
}
336-
337-
if ( Menu[i].Sub[LOALARM].State == ON && Menu[i].Sub[LOALARM].ID != NULL ) { // Check the LOALARM
338-
if ( Menu[i].LastOptionIdx > 0 ) {
339-
AlarmActive = ( Menu[i].Sub[MAIN].Value == Menu[i].Sub[LOALARM].Value ); // Option Compare EQUALS
340-
} else {
341-
AlarmActive = ( Menu[i].Sub[MAIN].Value < Menu[i].Sub[LOALARM].Value ); // Value Compare LESS-THAN
338+
339+
if ( bIterating ) {
340+
if ( Menu[i].Sub[LOALARM].State == ON && Menu[i].Sub[LOALARM].ID != NULL ) { // Check the LOALARM
341+
if ( Menu[i].LastOptionIdx > 0 ) {
342+
AlarmActive = ( Menu[i].Sub[MAIN].Value == Menu[i].Sub[LOALARM].Value ); // Option Compare EQUALS
343+
} else {
344+
AlarmActive = ( Menu[i].Sub[MAIN].Value < Menu[i].Sub[LOALARM].Value ); // Value Compare LESS-THAN
345+
}
346+
if ( i == BATT && Menu[i].Sub[MAIN].Value < 550 ) AlarmActive = false; // Disable BATT for USB Plug-In
342347
}
343-
}
344348

345-
if ( Menu[i].Sub[HIALARM].State == ON && Menu[i].Sub[HIALARM].ID != NULL ) { // Check the HIALARM
346-
if ( Menu[i].LastOptionIdx > 0 ) {
347-
AlarmActive = ( Menu[i].Sub[MAIN].Value != Menu[i].Sub[HIALARM].Value ); // Option Compare NOT-EQUAL
348-
} else {
349-
AlarmActive = ( Menu[i].Sub[MAIN].Value > Menu[i].Sub[HIALARM].Value ); // Value Compare GREATER-THAN
349+
if ( Menu[i].Sub[HIALARM].State == ON && Menu[i].Sub[HIALARM].ID != NULL ) { // Check the HIALARM
350+
if ( Menu[i].LastOptionIdx > 0 ) {
351+
AlarmActive = ( Menu[i].Sub[MAIN].Value != Menu[i].Sub[HIALARM].Value ); // Option Compare NOT-EQUAL
352+
} else {
353+
AlarmActive = ( Menu[i].Sub[MAIN].Value > Menu[i].Sub[HIALARM].Value ); // Value Compare GREATER-THAN
354+
}
350355
}
356+
if ( AlarmActive ) tone(SBUZZ,Menu[i].Sub[LOALARM].ToneHz); // Sound Buzzer
351357
}
352-
if ( AlarmActive ) tone(SBUZZ,Menu[i].Sub[LOALARM].ToneHz); // Sound Buzzer
353358
}
354359
}
355360

@@ -535,9 +540,9 @@ void loop(){
535540

536541
//--- Iterate Menu while Idle --------------------------------
537542
if(bpress == NONE) {
538-
if ( millis() - last_bpress > START_STATUS_ITERATE &&
539-
millis() - last_change > ITERATE_EVERY && !AlarmActive ) {
540-
543+
ButtonHeld = 0;
544+
if ( millis() - last_bpress > START_STATUS_ITERATE) bIterating = true;
545+
if ( bIterating && millis() - last_change > ITERATE_EVERY && !AlarmActive ) {
541546
SubIdx = MAIN; // Switch to 'MAIN' menu items
542547
int i = idx; // Mark current idx
543548

@@ -563,11 +568,14 @@ void loop(){
563568
last_change=millis(); // Record time for next iteration
564569
LCD_display(); // Update the display
565570
}
566-
} else { last_bpress = millis(); } // Record time for Start Iteration (Idle time)
571+
572+
} else {
567573

568574
//--- Process Button Press -----------------------------------
569-
if(bpress !=NONE) {
570-
noTone(SBUZZ);AlarmActive = false; // Turn off any alarms at button press
575+
last_bpress = millis(); } // Record time for next Start of Iteration (Idle time)
576+
noTone(SBUZZ); // Shut off any sound for alarms
577+
AlarmActive = false; // Turn off any alarms at button press
578+
bIterating = false; // Stop Iterating Menu Items
571579

572580
//------- ( SELECT ) -------
573581
if (bpress == SELECT) {
@@ -585,10 +593,15 @@ void loop(){
585593
if ( Menu[idx].Sub[MAIN].State != VALID ) GetItem(); // Retreive Value
586594

587595
} else { // ELSE
588-
Menu[idx].Sub[SubIdx].Value++; // Change Value up
589-
if ( Menu[idx].LastOptionIdx>0 &&
590-
Menu[idx].Sub[SubIdx].Value > Menu[idx].LastOptionIdx) {
591-
Menu[idx].Sub[SubIdx].Value = 0; } // Option - Boundary Check
596+
if ( Menu[idx].LastOptionIdx>0 ) {
597+
Menu[idx].Sub[SubIdx].Value++; // Move to next option
598+
if ( Menu[idx].Sub[SubIdx].Value > Menu[idx].LastOptionIdx ) {
599+
Menu[idx].Sub[SubIdx].Value = 0; } // Option - Boundary Check
600+
} else if ( ButtonHeld < 5 ) {
601+
Menu[idx].Sub[SubIdx].Value++; // Change Value up 1
602+
} else {
603+
Menu[idx].Sub[SubIdx].Value = Menu[idx].Sub[SubIdx].Value + 10; // Change Value up 10
604+
}
592605
}
593606

594607
//------- ( DOWN ) -------
@@ -600,10 +613,18 @@ void loop(){
600613
idx++; }
601614
if ( idx>NUM_MENU_ITEMS-1 ) idx=0; // Preform boundary check
602615
if ( SubIdx == MAIN && Menu[idx].Sub[MAIN].State != VALID ) GetItem();
616+
603617
} else { // ELSE
604-
Menu[idx].Sub[SubIdx].Value--; // Change Value down
605-
if ( Menu[idx].LastOptionIdx>0 && Menu[idx].Sub[SubIdx].Value < 0)
606-
Menu[idx].Sub[SubIdx].Value = Menu[idx].LastOptionIdx; // Boundary Check
618+
if ( Menu[idx].LastOptionIdx>0 ) {
619+
Menu[idx].Sub[SubIdx].Value--; // Move Option down one
620+
if ( Menu[idx].Sub[SubIdx].Value < 0) {
621+
Menu[idx].Sub[SubIdx].Value = Menu[idx].LastOptionIdx; } // Option - Boundary Check
622+
} else if ( ButtonHeld < 5 ) {
623+
Menu[idx].Sub[SubIdx].Value--; // Change Value down 1
624+
} else {
625+
Menu[idx].Sub[SubIdx].Value = Menu[idx].Sub[SubIdx].Value - 10; // Change Value down 10
626+
}
627+
if ( Menu[idx].Sub[SubIdx].Value < 0 ) Menu[idx].Sub[SubIdx].Value = 0; // Stop change at 0
607628
}
608629

609630
//------- ( RIGHT ) -------
@@ -631,6 +652,7 @@ void loop(){
631652

632653
// Update Display
633654
LCD_display();
655+
ButtonHeld++;
634656
}
635657
#endif
636658
}

0 commit comments

Comments
 (0)