Skip to content

Commit

Permalink
Added simulator
Browse files Browse the repository at this point in the history
Changed int’s to short’s in code. Consistent use of const and other
code cleanups.
  • Loading branch information
tomcourt authored and tomcourt committed Aug 4, 2017
1 parent d9dc69e commit f0c69ab
Show file tree
Hide file tree
Showing 22 changed files with 1,186 additions and 351 deletions.
71 changes: 35 additions & 36 deletions enguino/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
// User configuration for enguino
// ------------------------------
// This configuration file assumes Carburated Lycoming O-360 or O-320 with Van's Aircraft sensors. Fuel level senders are Van's for the RV-6.
// Confirm the yellow and red line (cauation and warning) numbers are correct for your engine. Confirm that your sensors are compatible.
// Confirm the yellow and red line (cauation and warning) numbers are correct for your engine. Confirm that your sensors are compatible.
// And most importanly confirm that your fuel gauges are correctly reflect fuel in the tank from full to empty.

// This file is part of Enguino.
//
//
// Enguino is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// Enguino is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Enguino. If not, see <http:https://www.gnu.org/licenses/>.

Expand All @@ -38,12 +38,12 @@
// -----------------------------
// The sensors are scaled using the following formula, are scaled as follow: y = factor * (adc + offset).
// All of these numbers must be integers. Factors are represented as a ratio with an integer numerator and a denominator of 8192.
// Some numeric values are multipled by 10 and then have a decimal point added when displayed.
// Some numeric values are multipled by 10 and then have a decimal point added when displayed.
// SCALE(1.) returns the raw values (ADC, RPM's). SCALE(range/full_scale) returns a value from 0 to range.
// The gauge pointers vary from 0 to 1000. Use GMIN() and GRNG to set the graphs b and m values based on lowest input and input range (hi-low) respectively.
// The gauge pointers vary from 0 to 1000. Use GMIN() and GRNG to set the graphs b and m values based on lowest input and input range (hi-low) respectively.
// Manifold pressure sensor = P(inch) = V(full) * 32.811 + 3.117 or V = (P-3.117)/32.811

// sensor-type range
// sensor-type range
// -------------- --------
// st_r240to33 0 - 1000 proportional on resistance of sensor forming resistor divider
// st_v240to33 0 - 1000 proportional on voltage of sensor forming resistor divider
Expand All @@ -57,58 +57,58 @@
// st_unit unit values, RPM, fuel flow, hobbs

// sensor-type, pin, decimal, voffset, vfactor, goffset, gfactor,lowWarning,lowCaution,highCaution,highWarning
const Sensor oilpS = { st_v240to33, 1, 0, 0, SCALE(.100), 0, SCALE(1.), 25, 55, 9999, 95 };
const Sensor oilpS = { st_v240to33, 1, 0, 0, SCALE(.100), 0, SCALE(1.), 25, 55, 9999, 95 };
const Sensor oiltS = { st_thermistorF, 2, 0, 0, SCALE(.100), GMIN(50*10), GRNG(200*10), -1, 140, 9999, 250 };
const Sensor voltS = { st_volts, 0, 1, 0, SCALE(.200), GMIN(100*fromV), GRNG(60*fromV), 110, 130, 9999, 160 };
const Sensor fuelpS = { st_v240to33, 3, 1, 0, SCALE(.150), 0, SCALE(150./100.), 5, 20, 60, 80 };
const Sensor fuellS = { st_v240to33, DUAL(4), 1, 0, SCALE(.160), 0, SCALE(1.), 25, 50, 9999, 999 };
const Sensor fuellS = { st_v240to33, DUAL(4), 1, 0, SCALE(.160), 0, SCALE(1.), 25, 50, 9999, 999 };
const Sensor tachS = { st_unit, TACH_SENSOR, 0, 0, SCALE(1.), GMIN(0), GRNG(3000), -1, 500, 9999, 2700 };
const Sensor mapS = { st_volts, 8, 1, 102, SCALE(.32811), GMIN(210),GRNG(1000*25/32.811), -1, -1, 9999, 9999 };
const Sensor chtS = { st_k_type_tcF, 16, 0, 0, SCALE(.25), GMIN(100*4), GRNG(400*4), -1, 150, 400, 500 };
const Sensor mapS = { st_volts, 8, 1, 102, SCALE(.32811), GMIN(210),GRNG(1000*25/32.811), -1, -1, 9999, 9999 };
const Sensor chtS = { st_k_type_tcF, 16, 0, 0, SCALE(.25), GMIN(100*4), GRNG(400*4), -1, 150, 400, 500 };
const Sensor egtS = { st_k_type_tcF, 20, 0, 0, SCALE(.25), GMIN(1000*4), GRNG(600*4), -1, -1, 9999, 9999 };
const Sensor fuelfS = { st_unit, FUELF_SENSOR, 1, 0, SCALE(1.), GMIN(0), GRNG(150), -1, -1, 9999, 9999 };
const Sensor fuelrS = { st_unit, FUELR_SENSOR, 1, 0, SCALE(1.), GMIN(0), GRNG(400), -1, -1, 9999, 9999 };
const Sensor hobbsS = { st_unit, HOBBS_SENSOR, 1, 0, SCALE(1.), GMIN(0), GRNG(1000), -1, -1, 9999, 9999 };

// Label and gradations
// Label and gradations
// --------------------
string oilpLV[] = { "80", "60", "40", "20" };
const int oilpLP[] = { VSEG(80./100.), VSEG(60./100.), VSEG(40./100.), VSEG(20./100.) };
const short oilpLP[] = { VSEG(80./100.), VSEG(60./100.), VSEG(40./100.), VSEG(20./100.) };
string oiltLV[] = { "200", "150", "100" };
const int oiltLP[] = { VSEG(150./200.), VSEG(100./200.), VSEG(50./200.) }; // offset and range offset by 50 deg-F
const short oiltLP[] = { VSEG(150./200.), VSEG(100./200.), VSEG(50./200.) }; // offset and range offset by 50 deg-F
string voltLV[] = { "14", "12" };
const int voltLP[] = { VSEG(4./6.), VSEG(2./6.) }; // offset and range offset by 10 volts
const short voltLP[] = { VSEG(4./6.), VSEG(2./6.) }; // offset and range offset by 10 volts
string fuelpLV[] = { "8", "6", "4", "2" };
const int fuelpLP[] = { VSEG(8./10.), VSEG(6./10.), VSEG(4./10.), VSEG(2./10.) };
const short fuelpLP[] = { VSEG(8./10.), VSEG(6./10.), VSEG(4./10.), VSEG(2./10.) };
string fuellLV[] = { "15", "10", "5", "2.5" };
const int fuellLP[] = { VSEG(15./16.), VSEG(10./16.), VSEG(5./16.), VSEG(2.5/16.) };
const short fuellLP[] = { VSEG(15./16.), VSEG(10./16.), VSEG(5./16.), VSEG(2.5/16.) };
string chtLV[] = { "200&deg;F", "300&deg;F", "400&deg;F" };
const int chtLP[] = { HSEG(100./400.), HSEG(200./400.), HSEG(300./400.) }; // offset and range offset by 100 deg-F
const short chtLP[] = { HSEG(100./400.), HSEG(200./400.), HSEG(300./400.) }; // offset and range offset by 100 deg-F
string egtLV[] = { "1150&deg;", "1300&deg;", "1450&deg;" };
const int egtLP[] = { HSEG(150./600.), HSEG(300./600.), HSEG(450./600.) }; // offset and range offset by 1000 deg-F
const short egtLP[] = { HSEG(150./600.), HSEG(300./600.), HSEG(450./600.) }; // offset and range offset by 1000 deg-F

// Color regions
// -------------
string oilpRC[] = { red, yellow, green, red };
int oilpRP[] = { VSEG(25./100.), VSEG(55./100.), VSEG(95./100.), VSEG(1) };
short oilpRP[] = { VSEG(25./100.), VSEG(55./100.), VSEG(95./100.), VSEG(1) };
string oiltRC[] = { yellow, green, red };
int oiltRP[] = { VSEG(40./200.), VSEG(196./200.), VSEG(1) }; // offset and range offset by 50 deg-F
short oiltRP[] = { VSEG(40./200.), VSEG(196./200.), VSEG(1) }; // offset and range offset by 50 deg-F
string voltRC[] = { red, yellow, green, yellow, red };
int voltRP[] = { VSEG(1./6.), VSEG(3./6.), VSEG(5./6.), VSEG(5.9/6.), VSEG(1) }; // offset and range offset by 10 volts
short voltRP[] = { VSEG(1./6.), VSEG(3./6.), VSEG(5./6.), VSEG(5.9/6.), VSEG(1) }; // offset and range offset by 10 volts
string fuelpRC[] = { red, yellow, green, yellow, red };
int fuelpRP[] = { VSEG(.5/10.), VSEG(2./10.), VSEG(6./10.), VSEG(8./10.), VSEG(1) };
short fuelpRP[] = { VSEG(.5/10.), VSEG(2./10.), VSEG(6./10.), VSEG(8./10.), VSEG(1) };
string fuellRC[] = { red, yellow, green };
int fuellRP[] = { VSEG(2.5/16.), VSEG(5./16.), VSEG(1) };
short fuellRP[] = { VSEG(2.5/16.), VSEG(5./16.), VSEG(1) };
string tachRC[] = { yellow, green, red };
int tachRP[] = { ARCX(500./3000.), ARCX(2700./3000.), ARCX(1), // x
ARCY(500./3000.), ARCY(2700./3000.), ARCY(1), // y
short tachRP[] = { ARCX(500./3000.), ARCX(2700./3000.), ARCX(1), // x
ARCY(500./3000.), ARCY(2700./3000.), ARCY(1), // y
0, 0, 0 }; // arc segmenet is > 180 degrees
string mapRC[] = { green };
int mapRP[] = { ARCX(1), // x
short mapRP[] = { ARCX(1), // x
ARCY(1), // y
1 }; // arc segmenet is > 180 degrees
string chtRC[] = { yellow, green, yellow, red };
int chtRP[] = { HSEG(50./400.), HSEG(300./400.), HSEG(395./400.), HSEG(1) }; // offset and range offset by 100 deg-F
short chtRP[] = { HSEG(50./400.), HSEG(300./400.), HSEG(395./400.), HSEG(1) }; // offset and range offset by 100 deg-F

// Gauge layout for screen
// -----------------------
Expand All @@ -119,7 +119,7 @@ const Gauge gauges[] = {
{bank+1750, 0, gs_vert, "OIL", "TEMP", "&deg;F", oiltLV, oiltLP, N(oiltLV), oiltRC, oiltRP, N(oiltRC), &oiltS},
{bank+3500, 0, gs_vert, "", "VOLT", "volt", voltLV, voltLP, N(voltLV), voltRC, voltRP, N(voltRC), &voltS},
{bank+5250, 0, gs_vert, "FUEL", "PRES", "psi", fuelpLV, fuelpLP, N(fuelpLV), fuelpRC, fuelpRP, N(fuelpRC), &fuelpS},
{bank+7000, 0, gs_pair, "FUEL", "", "gal", fuellLV, fuellLP, N(fuellLV), fuellRC, fuellRP, N(fuellRC), &fuellS},
{bank+7000, 0, gs_pair, "FUEL", "", "gal", fuellLV, fuellLP, N(fuellLV), fuellRC, fuellRP, N(fuellRC), &fuellS},
{100, 0, gs_round, "TACH", "", "rpm", 0, 0, 0, tachRC, tachRP, N(tachRC), &tachS},
{100, 3200, gs_round, "MP", "", "in-hg", 0, 0, 0, mapRC, mapRP, N(mapRC), &mapS},
{2950, 6150, gs_horiz, "CHT", "", "", chtLV, chtLP, N(chtLV), chtRC, chtRP, N(chtRC), &chtS},
Expand All @@ -131,18 +131,17 @@ const Gauge gauges[] = {
// ----------------------------
// Layout is text, top-sensor, bottom-sensor. Sensor value is displayed in the top line if text is blank, otherwise top sensor is used to show warning/caution and low/high on top line
AuxDisplay auxDisplay[] = {
AUX(H,o,b,b, 0, &hobbsS),
AUX(b,A,t, , &voltS, &voltS),
AUX(H,o,b,b, 0, &hobbsS),
AUX(b,A,t, , &voltS, &voltS),
AUX( , , , , &tachS, &fuellS), // default page
AUX(O,P, , , &oilpS, &oilpS),
AUX(O,t, , , &oiltS, &oiltS),
AUX(F,P, , , &fuelpS, &fuelpS),
AUX(A,L,t, , &voltS, &voltS),
AUX(O,P, , , &oilpS, &oilpS),
AUX(O,t, , , &oiltS, &oiltS),
AUX(F,P, , , &fuelpS, &fuelpS),
AUX(A,L,t, , &voltS, &voltS),
};

// number of pages shown on startup, immedietly after the startup pages is the default page
#define AUX_STARTUP_PAGES 2

// seconds before aux goes back to default page (assuming no un-acknowleged alerts), max. value 30
#define SHOW_DEFAULT_AUX_PAGE_TIMEOUT 10

70 changes: 35 additions & 35 deletions enguino/controlAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
// Implements the user interface/alerting system for the Aux Display.
//
// This file is part of Enguino.
//
//
// Enguino is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// Enguino is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Enguino. If not, see <http:https://www.gnu.org/licenses/>.



byte auxPage = 0;
signed char blinkAux[2];
byte auxPage = 0;
signed char blinkAux[2];
bool dimAux;
bool didHoldKey;
bool didChangeDim;
Expand All @@ -31,11 +31,11 @@ void updateAlerts() {
for (byte i=AUX_STARTUP_PAGES; i<N(auxDisplay); i++) {
AuxDisplay *a = auxDisplay + i;
for (byte j=0; j<2; j++) {
Sensor *s = a->sensor[j];
const Sensor *s = a->sensor[j];
byte b = alertState(s, 0);
if (s->pin & DUAL_BIT)
b |= alertState(s, 1);
a->alertState[j] = b;
a->alertState[j] = b;
}
}
}
Expand All @@ -45,9 +45,9 @@ void checkForAlerts(bool warning) {
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) {
if (warning) {
bool b = (a->alertState[1] & WARNING_ANY);
if (isInfoPage)
if (isInfoPage)
b = b || (a->alertState[0] & WARNING_ANY);
if (b) {
alertStatus = STATUS_WARNING;
Expand All @@ -72,37 +72,38 @@ void checkForAlerts(bool warning) {


void showAuxPage() {
AuxDisplay *a = auxDisplay + auxPage;
for (byte n=0; n<2; n++) {
AuxDisplay *a = auxDisplay + auxPage;
for (byte n=0; n<2; n++) {
if (a->alertState[n] & WARNING_ANY) {
alertStatus = STATUS_WARNING;
if (blinkAux[n] == 0)
if (blinkAux[n] == 0)
blinkAux[n] = 1;
}
else
blinkAux[n] = 0;
commandLED(n, (blinkAux[n] == 1) ? HT16K33_BLINK_1HZ : HT16K33_BLINK_OFF);

Sensor *s = a->sensor[n];
int v = scaleValue(s, readSensor(s));
else
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);
printLED(n,t);
}
else if (s->pin & DUAL_BIT)
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)
else if (s) {
short v = scaleValue(s, readSensor(s));
printLED(n,v, s->decimal);
}
}
}



bool ackAlert() {
if (auxDisplay[auxPage].warning > 0) {
if (auxDisplay[auxPage].warning > 0) {
auxDisplay[auxPage].warning = -1;
auxDisplay[auxPage].caution = -1;
return true;
Expand Down Expand Up @@ -147,8 +148,8 @@ inline void buttonPress() {

// Hold (reshow all alerts)
inline void buttonHold() {
blinkAux[0] = blinkAux[1] = 0;
for (byte i=AUX_STARTUP_PAGES; i<N(auxDisplay); i++)
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;
didHoldKey = true;
Expand All @@ -157,29 +158,28 @@ inline void buttonHold() {
// 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;
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)
if (switchPress < 8)
buttonPress();
switchPress = 0;
didChangeDim = false;
didHoldKey = false;
}
if (switchDown >= 24 && !didChangeDim)

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

if (switchUp > SHOW_DEFAULT_AUX_PAGE_TIMEOUT*8) {
if (auxDisplay[auxPage].warning <=0 && auxDisplay[auxPage].caution <= 0)
auxPage = AUX_STARTUP_PAGES;
}
auxPage = AUX_STARTUP_PAGES;
}
}

Loading

0 comments on commit f0c69ab

Please sign in to comment.