Skip to content

Commit

Permalink
Fixes to Aux operation
Browse files Browse the repository at this point in the history
Shows battery voltage on startup
Clears blinking when switching pages
No longer blinks second line (if not info page)
  • Loading branch information
tomcourt authored and tomcourt committed Aug 5, 2017
1 parent f0c69ab commit c62f531
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
48 changes: 26 additions & 22 deletions enguino/controlAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ bool dimAux;
bool didHoldKey;
bool didChangeDim;

void changePage(byte page) {
if (page != auxPage) {
blinkAux[0] = blinkAux[1] = 0;
auxPage = page;
}
}


void updateAlerts() {
for (byte i=AUX_STARTUP_PAGES; i<N(auxDisplay); i++) {
AuxDisplay *a = auxDisplay + i;
for (byte j=0; j<2; j++) {
const Sensor *s = a->sensor[j];
byte b = alertState(s, 0);
byte b = alertStateNow(s, 0);
if (s->pin & DUAL_BIT)
b |= alertState(s, 1);
b |= alertStateNow(s, 1);
a->alertState[j] = b;
}
}
Expand All @@ -44,16 +50,16 @@ void checkForAlerts(bool warning) {
// work backward to higher priority alerts
for (byte i=N(auxDisplay)-1; i>=AUX_STARTUP_PAGES; i--) {
AuxDisplay *a = auxDisplay + i;
bool isInfoPage = a->sensor[0] != a->sensor[1];
bool isInfoPage = (a->sensor[0] != a->sensor[1]);
if (warning) {
bool b = (a->alertState[1] & WARNING_ANY);
if (isInfoPage)
b = b || (a->alertState[0] & WARNING_ANY);
b = (b || (a->alertState[0] & WARNING_ANY));
if (b) {
alertStatus = STATUS_WARNING;
if (a->warning != -1) {
a->warning = 1;
auxPage = i;
changePage(i);
}
}
}
Expand All @@ -62,7 +68,7 @@ void checkForAlerts(bool warning) {
alertStatus = STATUS_CAUTION;
if (a->caution != -1) {
a->caution = 1;
auxPage = i;
changePage(i);
}
}
}
Expand All @@ -74,29 +80,30 @@ void checkForAlerts(bool warning) {
void showAuxPage() {
AuxDisplay *a = auxDisplay + auxPage;
for (byte n=0; n<2; n++) {
bool isInfoPage = (a->sensor[0] != a->sensor[1]);
if (a->alertState[n] & WARNING_ANY) {
alertStatus = STATUS_WARNING;
if (blinkAux[n] == 0)
if (blinkAux[n] == 0 && (isInfoPage || n==0))
blinkAux[n] = 1;
}
else
else if (blinkAux[n] != -1)
blinkAux[n] = 0;
commandLED(n, (blinkAux[n] == 1) ? HT16K33_BLINK_1HZ : HT16K33_BLINK_OFF);

const Sensor *s = a->sensor[n];
if (n==0 && a->literal[0]) {
byte t[4];
memcpy(t,a->literal,4);
if (a->alertState[n])
t[3] = (a->alertState[1] & (WARNING_LOW | CAUTION_LOW)) ? LED_L : LED_H;
printLED(n,t);
if (a->alertState[0] & (WARNING_ANY|CAUTION_ANY))
t[3] = ((a->alertState[0] & (WARNING_LOW | CAUTION_LOW)) ? LED_L : LED_H);
printLED(0,t);
}
else if (s->pin & DUAL_BIT)
printLEDFuel(scaleValue(s, readSensor(s,0)), scaleValue(s, readSensor(s,1))); // Show the dual fuel gauge
else if (s) {
short v = scaleValue(s, readSensor(s));
short v = scaleValue(s, readSensor(s));
printLED(n,v, s->decimal);
}
}
}
}

Expand Down Expand Up @@ -136,13 +143,10 @@ inline void buttonPress() {
ackAlert();
}
else {
if (ackAlert())
auxPage = AUX_STARTUP_PAGES;
else {
auxPage++;
if (auxPage >= N(auxDisplay))
auxPage = AUX_STARTUP_PAGES;
}
if (ackAlert() || auxPage >= N(auxDisplay)-1)
changePage(AUX_STARTUP_PAGES);
else
changePage(auxPage+1);
}
}

Expand All @@ -151,7 +155,7 @@ inline void buttonHold() {
blinkAux[0] = blinkAux[1] = 0;
for (byte i=AUX_STARTUP_PAGES; i<N(auxDisplay); i++)
auxDisplay[i].warning = auxDisplay[i].caution = 0;
auxPage = AUX_STARTUP_PAGES;
changePage(AUX_STARTUP_PAGES);
didHoldKey = true;
}

Expand Down Expand Up @@ -180,6 +184,6 @@ inline void checkAuxSwitch() {

if (switchUp > SHOW_DEFAULT_AUX_PAGE_TIMEOUT*8) {
if (auxDisplay[auxPage].warning <=0 && auxDisplay[auxPage].caution <= 0)
auxPage = AUX_STARTUP_PAGES;
changePage(AUX_STARTUP_PAGES);
}
}
8 changes: 6 additions & 2 deletions enguino/enguino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ EthernetServer server(80); // Port 80 is HTTP
EthernetClient client;

// #define DEBUG // checks RAM usage
#define SIMULATE_SENSORS 3 // number of simulated sensor 'states', press enter in serial monitor to advace state
// #define SIMULATE_SENSORS 3 // number of simulated sensor 'states', press enter in serial monitor to advace state
// #define BOUNDING_BOX // shows a box around each instrumment and around the viewable area of the page. Use to help arrange gauges.

// sketches don't like typdef's so they are in in this header file instead
Expand Down Expand Up @@ -88,7 +88,11 @@ void setup() {

tcTempSetup();

delay(1); // delay to allow LED display chip to startup
// init ADC values for battery voltage
for(byte i=0; i<4; i++)
updateADC();

// 1ms needed to delay to allow LED display chip to startup
printLEDSetup();

for (auxPage=0; auxPage<AUX_STARTUP_PAGES; auxPage++) {
Expand Down
2 changes: 1 addition & 1 deletion enguino/printGauges.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ short scaleMark(const Sensor *s, short val) {

void printGaugeRawValue(short x, short y, const Sensor *s, short val, byte pinOffset) {
print_g_translate(x, y);
byte alert = alertState(s, pinOffset);
byte alert = alertStateNow(s, pinOffset);
if (alert) {
print_P(F("'<rect width='1000' height='500' rx='90' ry='90' fill='"));
if (alert & WARNING_ANY)
Expand Down
2 changes: 1 addition & 1 deletion enguino/sensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ short scaleValue(const Sensor *s, short val) {
return multiplyAndScale(s->vfactor,val+s->voffset, divisor);
}

byte alertState(const Sensor *s, byte offset) {
byte alertStateNow(const Sensor *s, byte offset) {
byte b = 0;
if (s) {
short v = scaleValue(s, readSensor(s,offset));
Expand Down
Binary file not shown.

0 comments on commit c62f531

Please sign in to comment.