mirror of https://github.com/rusefi/speeduino.git
Initial work on comms
This commit is contained in:
parent
92f96291ba
commit
80320240c1
|
@ -0,0 +1,8 @@
|
||||||
|
#include <Serial.h>
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
|
void command();
|
||||||
|
void sendValues();
|
||||||
|
void saveConfig();
|
||||||
|
void sendPage();
|
||||||
|
void testComm();
|
|
@ -0,0 +1,109 @@
|
||||||
|
void command()
|
||||||
|
{
|
||||||
|
switch (Serial.read())
|
||||||
|
{
|
||||||
|
case 'A': // send 22 bytes of realtime values
|
||||||
|
sendValues(22);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'B': // store to eeprom
|
||||||
|
saveConfig();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'C': // test communications
|
||||||
|
testComm();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'P': // set the current page
|
||||||
|
digitalWrite(10, HIGH);
|
||||||
|
digitalWrite(9, LOW);
|
||||||
|
digitalWrite(13, LOW);
|
||||||
|
Serial.read(); //Not doing anything with this currently, but need to read the 2nd byte from the buffer
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'R': // send 39 bytes of realtime values
|
||||||
|
sendValues(39);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'S': // send code version
|
||||||
|
Serial.write(ms_version);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'Q': // send code version
|
||||||
|
digitalWrite(9, LOW);
|
||||||
|
digitalWrite(10, LOW);
|
||||||
|
digitalWrite(13, LOW);
|
||||||
|
Serial.write(ms_version);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'V': // send VE table and constants
|
||||||
|
digitalWrite(9, LOW);
|
||||||
|
digitalWrite(10, LOW);
|
||||||
|
digitalWrite(13, HIGH);
|
||||||
|
sendPage();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'W': // receive new VE or constant at 'W'+<offset>+<newbyte>
|
||||||
|
digitalWrite(9, HIGH);
|
||||||
|
digitalWrite(10, LOW);
|
||||||
|
digitalWrite(13, LOW);
|
||||||
|
Serial.read();
|
||||||
|
Serial.read(); //Not doing anything with this currently, but need to read the next 2 bytes from the buffer
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendValues(int length)
|
||||||
|
{
|
||||||
|
byte response[22];
|
||||||
|
|
||||||
|
response[0] = (uint8_t)1; //rtc.sec;
|
||||||
|
|
||||||
|
boolean a = 0; //inj_port1.status;
|
||||||
|
boolean b = 0; //inj_port2.status;
|
||||||
|
response[1] = ((a & 0x01) << 0) | ((a & 0x02) << 1) | ((a & 0x04) << 1) | ((b & 0x01) << 1) | ((b & 0x02) << 3) | ((b & 0x04) << 3); //squirt
|
||||||
|
|
||||||
|
response[2] = 0; // Engine Status
|
||||||
|
response[3] = 0x00; //baro
|
||||||
|
response[4] = 0x00; //map
|
||||||
|
response[5] = 0x00; //mat
|
||||||
|
response[6] = 0x00; //Coolant
|
||||||
|
response[7] = 0x00; //TPS
|
||||||
|
response[8] = 0x00; //battery voltage
|
||||||
|
response[9] = 0x00; //O2
|
||||||
|
response[10] = 0x00; //Exhaust gas correction (%)
|
||||||
|
response[11] = 0x00; //Air Correction (%)
|
||||||
|
response[12] = 0x00; //Warmup enrichment (%)
|
||||||
|
response[13] = (rpm / 100); //rpm / 100
|
||||||
|
response[14] = 0x00; //Pulsewidth 1 divided by 10 (in ms)
|
||||||
|
response[15] = 0x00; //acceleration enrichment (ms)
|
||||||
|
response[16] = 0x00; //Barometer correction (%)
|
||||||
|
response[17] = 0x00; //Total GammaE (%)
|
||||||
|
response[18] = 0x00; //Current VE 1 (%)
|
||||||
|
response[19] = 0x00; //Pulsewidth 2 divided by 10 (in ms)
|
||||||
|
response[20] = 0x00; //mCurrent VE 2 (%)
|
||||||
|
response[21] = 0x00; //Idle
|
||||||
|
|
||||||
|
Serial.write(response, (size_t)22);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveConfig()
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void sendPage()
|
||||||
|
{
|
||||||
|
Serial.write((uint8_t *)&fuelTable.values, sizeof(fuelTable.values));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testComm()
|
||||||
|
{
|
||||||
|
Serial.write(1);
|
||||||
|
return;
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ Need to calculate the req_fuel figure here, preferably in pre-processor macro
|
||||||
#include "table.h"
|
#include "table.h"
|
||||||
#include "testing.h"
|
#include "testing.h"
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
|
#include "comms.h"
|
||||||
|
|
||||||
#include "fastAnalog.h"
|
#include "fastAnalog.h"
|
||||||
#include "digitalIOPerformance.h"
|
#include "digitalIOPerformance.h"
|
||||||
|
@ -116,6 +117,10 @@ void setup() {
|
||||||
dummyIgnitionTable(&ignitionTable);
|
dummyIgnitionTable(&ignitionTable);
|
||||||
initialiseScheduler();
|
initialiseScheduler();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
|
//Setup some LEDs for testing
|
||||||
|
pinMode(10, OUTPUT);
|
||||||
|
pinMode(9, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
|
@ -133,7 +138,7 @@ void loop()
|
||||||
rpm = US_IN_MINUTE / revolutionTime;
|
rpm = US_IN_MINUTE / revolutionTime;
|
||||||
}
|
}
|
||||||
//Serial.print("RPM: "); Serial.println(rpm);
|
//Serial.print("RPM: "); Serial.println(rpm);
|
||||||
rpm = 1000;
|
//rpm = 1000;
|
||||||
//Get the current MAP value
|
//Get the current MAP value
|
||||||
int MAP = 20; //Placeholder
|
int MAP = 20; //Placeholder
|
||||||
int TPS = 20; //Placeholder
|
int TPS = 20; //Placeholder
|
||||||
|
@ -184,6 +189,12 @@ void loop()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Check for any requets from serial
|
||||||
|
if (Serial.available() > 0)
|
||||||
|
{
|
||||||
|
command();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Serial.println(VE);
|
//Serial.println(VE);
|
||||||
//Serial.print("VE: ");
|
//Serial.print("VE: ");
|
||||||
|
|
Loading…
Reference in New Issue