Skip to content

Commit

Permalink
New Aux display code changes
Browse files Browse the repository at this point in the history
New aux display is a custom circuit board with a single HT16k33
controller.  It has 3 buttons: Last - Ack - Next.  It is much more
compact, it fits in a 2.25” instrument hole. Schematics, board layout
and 3d files for an enclosure are coming.
  • Loading branch information
tomcourt authored and tomcourt committed Nov 7, 2017
1 parent e8aff25 commit 0c9c692
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 227 deletions.
Binary file modified MagnetoP-Lead.numbers
Binary file not shown.
42 changes: 22 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,28 +171,30 @@ The supply is rated for 1000 ma. The Leonardo uses 82 mA (confirmed by testing).

The SD card on the Leonardo can not be used with the thermocouple board attached as they both use pin D4. The thermocouple board also interferes with 4 of the analog inputs. The Leonardo itself also interferes with one of the analog inputs.

**Leonardo/Yún Pin Mapping to Enguino Production**

| Arduino | 32U4 | Use |IRQ|Analog|Counter| Assign Leo | Assign Yún |
|---------|-------|--------------|---|------|-------|------------|------------|
| D0 | PD2 | Serial RX | * | | | Tach-1 | reserved |
| D1 | PD3 | Serial TX | * | | | Tach-2 | reserved |
| D2 | PD1 | SDA | * | | | SDA | Tach-1 |
| D3 | PD0 | SCL | * | | | SCL | Tach-2 |
| D4 | PD4 | Analog 6 | | A6 | | Volt divide| Volt divide|
| D5 | PC6 | | | | | | SDA |
| D6 | PD7 |Analog 6/Count| | A7 | * | MAP | Fuel-F |
| D7 | PE6 |Handshake(Yún)| * | | | Fuel-F | reserved |
| D8 | PB4 | Analog 8 | | A8 | | Generic | Generic |
| D9 | PB5 | Analog 9 | | A9 | | Generic | Generic |
| D10 | PB6 | Ethernet(Leo)| | A10 | | reserved | MAP |
| D11 | PB7 | | | | | | SCL |
| D12 | PD6 | Analog 11 | | A11 | * | Ammeter | Ammeter |
| D13 | PC7 | LED | | | | | ||
**Arduino Pin Mapping to Enguino Production**

| Arduino | 32U4 | Use |IRQ|Analog|Counter| Assign Leo | Alternate |
|---------|-------|---------------|---|------|-------|------------|--------------|
| D0 | PD2 | Serial RX/IRQ | * | | | Tach-1 | |
| D1 | PD3 | Serial TX/IRQ | * | | | Tach-2 | |
| D2 | PD1 | SDA/IRQ | * | | | SDA | Tach-1 |
| D3 | PD0 | SCL/IRQ | * | | | SCL | Tach-2 |
| D4 | PD4 | Analog 6 | | A6 | | Volt divide| |
| D5 | PC6 | | | | | | SDA |
| D6 | PD7 |Analog 7/Count | | A7 | * | MAP |Fuel-F/generic|
| D7 | PE6 | IRQ | * | | | Fuel-F | |
| D8 | PB4 | Analog 8 | | A8 | | Generic | |
| D9 | PB5 | Analog 9 | | A9 | | Ammeter | generic |
| D10 | PB6 | Ethernet(Leo) | | A10 | | Ethernet | MAP |
| D11 | PB7 | | | | | | SCL |
| D12 | PD6 |Analog 11/Count| | A11 | * | Generic | Fuel-Flow2 |
| D13 | PC7 | LED | | | | | ||

* Leonardo ETH needs D10 for communications
* Yún needs D0, D1 and D7 for communication
* Leonardo uses IRQ for fuel flow, Yún uses hardware counter instead
* Tach needs an IRQ
* Fuel flow can either be IRQ or counters
* Fuel flow is either a dedicated pin or an analog pin w. 1k pull up & capacitor shorted
* Alternate generic is instead of MAP and Ammeter available on kit form

With the tach, assume 2 pulses per revolution at 2700 RPM the tach will max out at 90/cps so as long as IRQ disable time is <11ms no error should be expected. For the fuel flow with a k-factor of 68,000 and 13GPH it will max out at 250/cps so IRQ disable time must be <4ms.

Expand Down
156 changes: 71 additions & 85 deletions enguino/controlAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@


byte auxPage = 0;
signed char blinkAux[2];
signed char blinkAux; // -1=active,acknowledged, 1=active,blinking
bool dimAux;
bool didHoldKey;
bool didChangeDim;

void changePage(byte page) {
if (page != auxPage) {
blinkAux[0] = blinkAux[1] = 0;
blinkAux = 0;
auxPage = page;
}
}
Expand All @@ -46,69 +44,77 @@ void updateAlerts() {
}
}

void checkForAlerts(bool warning) {

void checkForAlerts() {
// 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]);
if (warning) {
bool b = (a->alertState[1] & WARNING_ANY);
if (isInfoPage)
b = (b || (a->alertState[0] & WARNING_ANY));
if (b) {
alertStatus = STATUS_WARNING;
if (a->warning != -1) {
a->warning = 1;
changePage(i);
}
bool b = (a->alertState[1] & WARNING_ANY);
if (isInfoPage)
b = (b || (a->alertState[0] & WARNING_ANY));
if (b) {
masterAlertStatus = STATUS_WARNING;
if (a->warning != -1) {
a->warning = 1;
changePage(i);
}
}
else {
if (!isInfoPage && (a->alertState[1] & CAUTION_ANY)) { // no caution check on info pages
alertStatus = STATUS_CAUTION;
if (a->caution != -1) {
a->caution = 1;
changePage(i);
}
}
}

if (masterAlertStatus != STATUS_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 b = (a->alertState[1] & CAUTION_ANY);
if (isInfoPage)
b = (b || (a->alertState[0] & CAUTION_ANY));
if (b)
masterAlertStatus = STATUS_CAUTION;
}
}
}



void showAuxPage() {
AuxDisplay *a = auxDisplay + auxPage;
bool ack = (blinkAux == -1);
blinkAux = 0;
alertStatus = STATUS_NORMAL;
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 && (isInfoPage || n==0))
blinkAux[n] = 1;
blinkAux = (ack ? -1 : 1);
}
else if (blinkAux[n] != -1)
blinkAux[n] = 0;
commandLED(n, (blinkAux[n] == 1) ? HT16K33_BLINK_1HZ : HT16K33_BLINK_OFF);
else if ((a->alertState[n] & CAUTION_ANY) && alertStatus == STATUS_NORMAL)
alertStatus = STATUS_CAUTION;
}
commandLED((blinkAux == 1) ? HT16K33_BLINK_1HZ : HT16K33_BLINK_OFF);

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



bool ackAlert() {
if (auxDisplay[auxPage].warning > 0) {
auxDisplay[auxPage].warning = -1;
Expand All @@ -122,68 +128,48 @@ bool ackAlert() {
return false;
}


bool ackBlink() {
bool ack = false;
if (blinkAux[0] > 0) {
blinkAux[0] = -1;
if (blinkAux > 0) {
blinkAux = -1;
ack = true;
}
if (blinkAux[1] > 0) {
blinkAux[1] = -1;
if (blinkAux > 0) {
blinkAux = -1;
ack = true;
}
return ack;
}



// Press (acknowedge/next-page)
inline void buttonPress() {
if (ackBlink()) {
ackAlert();
}
else {
if (ackAlert() || auxPage >= N(auxDisplay)-1)
inline void checkSwitches() {
switch (readKeys()) {
case LAST_BIT | NEXT_BIT:
dimAux = !dimAux;
commandLED(dimAux?HT16K33_BRIGHT_MIN:HT16K33_BRIGHT_MAX);
changePage(AUX_STARTUP_PAGES);
else
changePage(auxPage+1);
}
}

// Hold (reshow all alerts)
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;
changePage(AUX_STARTUP_PAGES);
didHoldKey = true;
}

// Long hold (toggle dim and bright)
inline void buttonLongHold() {
dimAux = !dimAux;
for (byte line=0; line<2; line++)
commandLED(line, dimAux?HT16K33_BRIGHT_MIN:HT16K33_BRIGHT_MAX);
didChangeDim = true;
didHoldKey = false;
}

inline void checkAuxSwitch() {
if (switchPress > 0) {
if (switchPress < 8)
buttonPress();
switchPress = 0;
didChangeDim = false;
didHoldKey = false;
}

if (switchDown >= 24 && !didChangeDim)
buttonLongHold();
else if (switchDown >= 8 && !didHoldKey)
buttonHold();

if (switchUp > SHOW_DEFAULT_AUX_PAGE_TIMEOUT*8) {
if (auxDisplay[auxPage].warning <=0 && auxDisplay[auxPage].caution <= 0)
break;
case NEXT_BIT:
if (auxPage >= N(auxDisplay)-1)
changePage(AUX_STARTUP_PAGES);
else
changePage(auxPage+1);
break;
case ACK_BIT:
if (ackBlink())
ackAlert();
changePage(AUX_STARTUP_PAGES);
break;
case LAST_BIT:
if (auxPage <= AUX_STARTUP_PAGES)
changePage(N(auxDisplay)-1);
else
changePage(auxPage-1);
break;
}
// if (displayTimeout > SHOW_DEFAULT_AUX_PAGE_TIMEOUT*8) {
// if (auxDisplay[auxPage].warning <=0 && auxDisplay[auxPage].caution <= 0)
// changePage(AUX_STARTUP_PAGES);
// }
}
19 changes: 10 additions & 9 deletions enguino/enguino.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Copyright 2017, Thomas Court
//
// This file is part of Enguino.
Expand Down Expand Up @@ -100,9 +101,7 @@ void setup() {
showAuxPage();
delay(2000);
}

switchPress = 0;
}
}



Expand All @@ -111,6 +110,8 @@ void loop() {
if (Serial.read() >= 0) {
if (++simState >= SIMULATE_SENSORS)
simState = 0;
Serial.print("test-");
Serial.println(simState);
}
#endif

Expand All @@ -121,7 +122,7 @@ void loop() {

updateADC();

checkAuxSwitch();
checkSwitches();

// every half second
// -----------------
Expand All @@ -131,14 +132,14 @@ void loop() {
updateRPM();
engineRunning = isEngineRunning();

updateAlerts();

if (engineRunning) {
alertStatus = STATUS_NORMAL;
updateAlerts();
checkForAlerts(false);
checkForAlerts(true);
masterAlertStatus = STATUS_NORMAL;
checkForAlerts();
}
else
alertStatus = STATUS_WARNING;
masterAlertStatus = STATUS_WARNING;

showAuxPage();

Expand Down
Loading

0 comments on commit 0c9c692

Please sign in to comment.