Skip to content

Commit

Permalink
Fixed i2c halting, blanks display if link lost
Browse files Browse the repository at this point in the history
  • Loading branch information
tomcourt authored and tomcourt committed Jul 5, 2017
1 parent 7a1176b commit 24bb108
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
2 changes: 1 addition & 1 deletion enguino/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ const Gauge gauges[] = {
{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},
{300, 6750, gs_infobox,0, "", "", "", 0, 0, 0, 0, 0, 0, 0}
{800, 6700, gs_infobox,0, "", "", "", 0, 0, 0, 0, 0, 0, 0}
};

20 changes: 12 additions & 8 deletions enguino/enguino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ int readSensor(const Sensor *s, byte n = 0) {
// RPM's are occasionaly screwed up because of IRQ latency.
// Throw out highest and lowest and average the middle 2
noInterrupts();
sort(rpm, sizeof(rpm)/sizeof(int));
v = (rpm[1]+rpm[2])>>1;
int r[4];
memcpy(r, rpm, sizeof(rpm));
interrupts();
sort(r, sizeof(r)/sizeof(int));
v = (r[1]+r[2])>>1;
}
else if (p < 16) {
v = analogRead(p);
Expand Down Expand Up @@ -202,8 +204,7 @@ void setup() {
// setup LED last to allow 1mS for HT16K33
printLEDSetup();
printLED(0,LED_TEXT(h,o,b,b));
delay(1000);
printLED(0,ee_status.hobbs>>2,1);
printLED(1,ee_status.hobbs>>2,1);
delay(1000);

attachInterrupt(digitalPinToInterrupt(2),tachIRQ,RISING);
Expand Down Expand Up @@ -276,17 +277,16 @@ void loop() {
// close the connection:
client.stop();
}


if (eighthSecondCount == 4)
goto halfSecond;
if (eighthSecondCount >= 8) {
if (tachDidPulse)
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

printLED(0,scaleValue(&taS, readSensor(&taS)),0);
// printLEDFuel(scaleValue(&flS, readSensor(&flS,0)), scaleValue(&flS, readSensor(&flS,1)));

if (engineRunning) {
if (--hobbsCount == 0) {
if (++(ee_status.hobbs) > 39999) {
Expand All @@ -299,5 +299,9 @@ void loop() {
}

eighthSecondCount -= 8;

halfSecond:
printLED(0,scaleValue(&taS, readSensor(&taS)),0);
printLEDFuel(scaleValue(&flS, readSensor(&flS,0)), scaleValue(&flS, readSensor(&flS,1)));
}
}
2 changes: 1 addition & 1 deletion enguino/printGauges.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void printInfoBox() {
print_P(F("Lean"));

print_P(F("</text></g>\n"
"<text x='800' y='1100' class='unit' fill='black'>Hobbs: "));
"<text x='800' y='1200' class='value'>Hobbs: "));
if (ee_status.hobbs1k)
print(ee_status.hobbs1k);
print(ee_status.hobbs >> 2, 1);
Expand Down
9 changes: 5 additions & 4 deletions enguino/printLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ byte colon; // used for showing alarm status by wiring a red/green LED onto th
#define STATUS_NORMAL 0x8

void writeI2C(byte line, byte *buffer, byte len) {
if (!i2c_start((I2C_ADDRESS | (line<<1)) | I2C_WRITE))
return;
if (!i2c_start((I2C_ADDRESS | (line<<1)) | I2C_WRITE))
goto stop;
while (len--) {
if (!i2c_write(*buffer++))
return;
goto stop;
}
stop:
i2c_stop();
}

Expand Down Expand Up @@ -132,7 +133,7 @@ void printLEDRawHalfDigits(byte offset, word number) {
void printLEDSetup() {
i2c_init();

for (byte line=0; line<1; line++) {
for (byte line=0; line<2; line++) {
commandLED(line, HT16K33_OSCILATOR_ON);
commandLED(line, HT16K33_BLINK_OFF);
commandLED(line, HT16K33_BRIGHT_MAX);
Expand Down
15 changes: 13 additions & 2 deletions enguino/printWeb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ void printHomePage() {
"var xhttp = new XMLHttpRequest();\n"
"xhttp.open('GET',u,true);\n"
"xhttp.onreadystatechange = function() {\n"
"if (this.readyState == 4 && this.status==200)\n"
"if (this.readyState == 4 && this.status==200) {\n"
"document.getElementById('dyn').innerHTML=this.responseText;\n"
"}\n"
"};\n"
"xhttp.ontimeout = function() { xhttp.abort() };\n"
"xhttp.ontimeout = function() {\n"
"xhttp.abort();\n"
"document.getElementById('dyn').innerHTML='';"
"};\n"
"xhttp.timeout=900;\n"
"xhttp.send();\n"
"}\n"
Expand Down Expand Up @@ -54,6 +58,13 @@ void printHomePage() {
"</body>\n"
"</html>\n"
));

// greying engine screen when connection fails can be done by replacing "document.getElementById('dyn').innerHTML='';" with
// "document.getElementById('over').style.display='';\n"
// and add "document.getElementById('over').style.display='none';\n" when dynamic content is loaded
// and add the following to style and html respectively
// ".overc { background-color:black; opacity:0.8; z-index:20; height:100%; width:100%; background-repeat:no-repeat; background-position:center; position:absolute; top:0px; left:0px; transition:2.0s }\n"
// "<div id='over' class='overc'></div>\n"
}

void printSetupPage() {
Expand Down

0 comments on commit 24bb108

Please sign in to comment.