Skip to content

Commit

Permalink
Switch and dimming added
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcourt authored and tomcourt committed Jul 6, 2017
1 parent 24bb108 commit 4e61b79
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 35 deletions.
51 changes: 30 additions & 21 deletions enguino/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ const char *red = "red";
// Some numberic values are multipled by 10 and then have a decimal point added when displayed.
// The MX macro converts a floating point factor for m into an integer factor. The gauge pointers vary from 0 to 1000.
// Use GB() and GMX to set the graphs b and m values based on lowest input and input range (hi-low) respectively.
//
const Sensor opS = { st_r240to33, 0, MX(0.1), 0, MX(1.0), 1}; // 0 - 100
const Sensor otS = { st_thermistorF, 0, MX(.1), GB(50*10), GMX(200*10), 2}; // 50 - 250
const Sensor vtS = { st_volts, 0, MX(ADCtoV10), GB(100*V10toADC), GMX(60*V10toADC), 0}; // 100 - 160 (10 - 16)
const Sensor fpS = { st_r240to33, 0, MX(0.1), 0, MX(1.0), 3}; // 0 - 100 (0 - 10)
const Sensor flS = { st_r240to33, 0, MX(0.16), 0, MX(1.0), 4}; // 0 - 160 (0 - 16)
const Sensor taS = { st_tachometer, 0, MX(1.), 0, GMX(3000), 15}; // 0 - 3000
const Sensor maS = { st_volts, 100, 2000, 0, 8008, -1}; // 100 - 350 (10 - 35)
const Sensor chS = { st_k_type_tcF, 0, MX(.25), GB(100*4), GMX(400*4), 16}; // 100 - 500, input is .25 deg. F
const Sensor egS = { st_k_type_tcF, 0, MX(.25), GB(1000*4), GMX(600*4), 20}; // 1000 - 1600,input is .25 deg. F

// sensor-type, pin, decimal, voffset, vfactor, moffset, mfactor, lowAlarm, lowAlert, highAlert, highAlarm
const Sensor vtS = { st_volts, 0, 1, 0, MX(ADCtoV10), GB(100*V10toADC), GMX(60*V10toADC), 110, 130, 9999, 160 };
const Sensor opS = { st_r240to33, 1, 0, 0, MX(0.1), 0, MX(1.0), 25, 55, 95, 95 };
const Sensor otS = { st_thermistorF, 2, 0, 0, MX(.1), GB(50*10), GMX(200*10), -1, 140, 9999, 250 };
const Sensor fpS = { st_r240to33, 3, 1, 0, MX(0.1), 0, MX(1.0), 5, 20, 60, 80 };
const Sensor flS = { st_r240to33, 4, 1, 0, MX(0.16), 0, MX(1.0), 25, 50, 9999, 999 };
const Sensor taS = { st_tachometer, 15, 0, 0, MX(1.), 0, GMX(3000), -1, 500, 9999, 2700 };
const Sensor maS = { st_volts, -1, 1, 100, 2000, 0, 8008, -1, -1, 9999, 9999 };
const Sensor chS = { st_k_type_tcF, 16, 0, 0, MX(.25), GB(100*4), GMX(400*4), -1, 150, 400, 500 };
const Sensor egS = { st_k_type_tcF, 20, 0, 0, MX(.25), GB(1000*4), GMX(600*4), -1, -1, 9999, 9999 };

// Labels
// ------
Expand Down Expand Up @@ -78,16 +79,24 @@ int chRP[] = { 1000, 6000, 7940, 8000 };
// -----------------------
#define bank 3500 // bank of misc vertical gauges
const Gauge gauges[] = {
// x, y, style, decimal, label1, label2, units, labVal, labPt,num, regClr, regPt, num, sensor
{bank+0, 0, gs_vert, 0, "OIL", "PRES", "psi", opLV, opLP, N(opLV), opRC, opRP, N(opRC), &opS},
{bank+1750, 0, gs_vert, 0, "OIL", "TEMP", "°F", otLV, otLP, N(otLV), otRC, otRP, N(otRC), &otS},
{bank+3500, 0, gs_vert, 1, "", "VOLT", "volt", vtLV, vtLP, N(vtLV), vtRC, vtRP, N(vtRC), &vtS},
{bank+5250, 0, gs_vert, 1, "FUEL", "PRES", "psi", fpLV, fpLP, N(fpLV), fpRC, fpRP, N(fpRC), &fpS},
{bank+7000, 0, gs_pair, 1, "FUEL", "", "gal", flLV, flLP, N(flLV), flRC, flRP, N(flRC), &flS},
{100, 0, gs_round, 0, "TACH", "", "rpm", 0, 0, 0, taRC, taRP, N(taRC), &taS},
{100, 3200, gs_round, 1, "MP", "", "in-hg", 0, 0, 0, maRC, maRP, N(maRC), &maS},
{2950, 6150, gs_horiz, 0, "CHT", "", "", chLV, chLP, N(chLV), chRC, chRP, N(chRC), &chS},
{2950, 6150, gs_aux, 0, "EGT", "", "", egLV, egLP, N(egLV), 0, 0, 0, &egS},
{800, 6700, gs_infobox,0, "", "", "", 0, 0, 0, 0, 0, 0, 0}
// x, y, style, label1, label2, units, labVal, labPt, num, regClr, regPt, num, sensor
{bank+0, 0, gs_vert, "OIL", "PRES", "psi", opLV, opLP, N(opLV), opRC, opRP, N(opRC), &opS},
{bank+1750, 0, gs_vert, "OIL", "TEMP", "°F", otLV, otLP, N(otLV), otRC, otRP, N(otRC), &otS},
{bank+3500, 0, gs_vert, "", "VOLT", "volt", vtLV, vtLP, N(vtLV), vtRC, vtRP, N(vtRC), &vtS},
{bank+5250, 0, gs_vert, "FUEL", "PRES", "psi", fpLV, fpLP, N(fpLV), fpRC, fpRP, N(fpRC), &fpS},
{bank+7000, 0, gs_pair, "FUEL", "", "gal", flLV, flLP, N(flLV), flRC, flRP, N(flRC), &flS},
{100, 0, gs_round, "TACH", "", "rpm", 0, 0, 0, taRC, taRP, N(taRC), &taS},
{100, 3200, gs_round, "MP", "", "in-hg", 0, 0, 0, maRC, maRP, N(maRC), &maS},
{2950, 6150, gs_horiz, "CHT", "", "", chLV, chLP, N(chLV), chRC, chRP, N(chRC), &chS},
{2950, 6150, gs_aux, "EGT", "", "", egLV, egLP, N(egLV), 0, 0, 0, &egS},
{800, 6650, gs_infobox,"", "", "", 0, 0, 0, 0, 0, 0, 0}
};

// Guage layout for aux display
const AuxDisplay auxdisplay[2] = {
{ .sensor = {&taS, 0} },
{ .sensor = {&taS, 0} }


};

14 changes: 11 additions & 3 deletions enguino/egTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ enum SensorType {st_r240to33, st_thermistorF, st_thermistorC, st_volts, st_k_typ

typedef struct {
SensorType type;
signed char pin;
byte decimal; // add decimal point 'decimal' positons from the right (0 is integer)
int voffset; // used to display reading, int_reading has 'decimal' point shifted right
int vfactor; // int_reading = multiply * sensor >> divisor + offset
int moffset; // used to calculate marker position
int mfactor; // 0-4000 vertical gauge, 0-8000 horizontal gauge, 0-2400 round gauge
signed char pin;
int lowAlarm;
int lowAlert;
int highAlert;
int highAlarm;
} Sensor;

enum GaugeStyle { gs_vert, gs_pair, gs_round, gs_horiz, gs_aux, gs_infobox };
Expand All @@ -43,8 +48,6 @@ typedef struct {
int y;
GaugeStyle style;

byte decimal; // add decimal point 'decimal' positons from the right (0 is integer)

string label1;
string label2;
string units;
Expand All @@ -62,4 +65,9 @@ typedef struct {

enum GaugeColor { gc_green, gc_yellow, gc_red };

typedef union {
struct { byte a,b,c,d; } literal;
struct { Sensor *s; word zero; } sensor;
} AuxDisplay;


30 changes: 28 additions & 2 deletions enguino/enguino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ volatile bool tachDidPulse;
volatile int rpm[4];
volatile byte rpmP;

bool dim;
bool didKeyDown;

// Performance 'print' functions to ethernet 'client' (includes flush)
#include "printEthernet.h"

Expand Down Expand Up @@ -194,6 +197,7 @@ void tachIRQ() {




void setup() {
// Serial.begin(9600);
// while (!Serial)
Expand All @@ -206,8 +210,15 @@ void setup() {
printLED(0,LED_TEXT(h,o,b,b));
printLED(1,ee_status.hobbs>>2,1);
delay(1000);
printLED(0,LED_TEXT( ,b,A,t));
printLED(1,scaleValue(&vtS, readSensor(&vtS)),1);
delay(1000);

attachInterrupt(digitalPinToInterrupt(2),tachIRQ,RISING);

pinMode(0, INPUT_PULLUP);
// attachInterrupt(digitalPinToInterrupt(0),switchIRQ,FALLING);

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Expand All @@ -216,7 +227,22 @@ void setup() {


void loop() {
// listen for incoming clients
// listen for incoming clients
if (switchPress) {
if (!didKeyDown) {
// !!!!! show next item
}
switchPress = 0;
didKeyDown = false;
}
if (switchDown >= 32) {
if (!didKeyDown)
dim = !dim;
for (byte line=0; line<2; line++)
commandLED(line, dim?HT16K33_BRIGHT_MIN:HT16K33_BRIGHT_MAX);
didKeyDown = true;
}

client = server.available();
if (client) {
// an http request ends with a blank line
Expand Down Expand Up @@ -285,7 +311,7 @@ void loop() {
tachDidPulse = false;
else
memset(rpm, 0, sizeof(rpm));
engineRunning = scaleValue(&vtS, readSensor(&vtS)) > 130 || rpm > 0; // greater than 13.0 volts means engine is running
engineRunning = scaleValue(&vtS, readSensor(&vtS)) > 130; // greater than 13.0 volts means engine is running

if (engineRunning) {
if (--hobbsCount == 0) {
Expand Down
24 changes: 16 additions & 8 deletions enguino/printGauges.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void printVertical(const Gauge *g, bool showLabels=true, byte pinOffset=0) {
}

print_P(F("<text x='600' y='5500' class='value'>"));
print(scaleValue(g->sensor, val), g->decimal);
print(scaleValue(g->sensor, val), g->sensor->decimal);
print_text_close();

if (val != FAULT) {
Expand Down Expand Up @@ -142,7 +142,7 @@ void printHorizontal(const Gauge *g, int count) {
print_P(F("<text x='500' y='"));
print(offset+800);
print_P(F("' class='value' alignment-baseline='central'>"));
print(scaleValue(g->sensor, val), g->decimal);
print(scaleValue(g->sensor, val), g->sensor->decimal);
print_text_close();

if (val != FAULT) {
Expand Down Expand Up @@ -203,7 +203,7 @@ void printAuxHoriz(const Gauge *g, int count) {
print_P(F("<text x='9700' y='"));
print(offset + 800);
print_P(F("' class='value' alignment-baseline='central'>"));
print(scaleValue(g->sensor, val), g->decimal);
print(scaleValue(g->sensor, val), g->sensor->decimal);
print_text_close();

if (val != FAULT) {
Expand Down Expand Up @@ -324,7 +324,7 @@ void printRound(const Gauge *g) {
}

print_P(F("<text x='0' y='350' class='value'>"));
print(scale, g->decimal);
print(scale, g->sensor->decimal);
print_text_close();

print_P(F("<text x='0' y='700' class='unit'>"));
Expand All @@ -341,7 +341,7 @@ void printRound(const Gauge *g) {

void printInfoBox() {
#ifdef BOUNDING_BOX
print_P(F("<rect x='0' y='0' width='1600' height='600' fill='none' stroke='orange'/>\n"));
print_P(F("<rect x='0' y='0' width='1600' height='2800' fill='none' stroke='orange'/>\n"));
#endif

print_P(F("<g width='1600' height='600' onClick=\"javascript:"));
Expand All @@ -357,9 +357,17 @@ void printInfoBox() {
print_P(F("Cancel"));
else
print_P(F("Lean"));

print_P(F("</text></g>\n"
"<text x='800' y='1200' class='value'>Hobbs: "));
print_P(F("</text></g>\n"));

print_P(F("<text x='800' y='1300' class='value'>GPH: "));
print(0, 1);
print_text_close();

print_P(F("<text x='800' y='2100' class='value'>Tot: "));
print(ee_status.fuel >> 2, 1);
print_text_close();

print_P(F("<text x='800' y='2800' style='text-anchor:middle; font-size:300px;'>Hobb: "));
if (ee_status.hobbs1k)
print(ee_status.hobbs1k);
print(ee_status.hobbs >> 2, 1);
Expand Down
1 change: 1 addition & 0 deletions enguino/printLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

#define LED_DP 0x80 // decimal point
#define LED__ 0x40 // minus sign
#define LED_ 0x0 // blank

#define LED_A 0x77
#define LED_b 0x7c
Expand Down
2 changes: 1 addition & 1 deletion enguino/printWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void printSetupPage() {
"<input type='number' name='n' pattern='[0-9]*'/>\n"
"<input type='submit'/><br>\n"
"<br>\n"
"<input type='button' value='Tanks Filled' onClick=\"javascript:location.assign('/?x=f&n=9999');\"/>\n"
"<input type='button' value='Tanks Filled' onClick=\"javascript:location.assign('/?x=a&n=9999');\"/>\n"
"<input type='button' value='Cancel' style='float:right;' onClick=\"javascript:location.assign('/');\"/\n"
"</form>\n"
"</html>\n"
Expand Down
16 changes: 16 additions & 0 deletions enguino/tcTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ volatile int tcTemp[9]; // in quarter deg. C, tcTemp[8] is the interal refere

volatile byte eighthSecondCount = 0;

volatile byte switchDown; // use this for detecting a key held down for a period of time
volatile byte switchUp;
volatile byte switchPress; // use this to detect a short keypress, then reset to 0

int readSPI() {
word v = 0;
for (byte i=16; i!=0; i--) {
Expand Down Expand Up @@ -62,6 +66,18 @@ SIGNAL(TIMER0_COMPA_vect)
// begin conversion
digitalWrite(PINCS, HIGH);
// ... wait 100 mS for conversion to complete

if (digitalRead(0)) {
if (++switchUp > 2) {
switchUp = 2;
if (switchDown)
switchPress = switchDown;
switchDown = 0;
}
}
else {
++switchDown;
}
}
else if (ms == 121) { // spec says 100mS, IRQ's are a bit slower, so this is >100mS
// stop conversion, start serial interface
Expand Down

0 comments on commit 4e61b79

Please sign in to comment.