J'ai donc regardé de plus prèt et modifier avec mes valeurs/code, je n'ai pas réussi/pas compris :
const uint8_t SendPC[] = {6,29,0,29,0x7F,29,0x7A,29,0xF,29,0x1E,29,0x3A,29,0x1D,29,75,29,39,29,79,29,0x1F,29,0x7D,29,0x7B,29,74,29,76,29,38,29,70,29,0x6F,0}; // pas obligatoirement des caractères
const uint8_t localBufferSize = sizeof(SendPC); // attention faire -1 si vous utilisez une c-string pour initialiser la phrase magique
uint8_t localBuffer[localBufferSize]; // buffer circulaire de la bonne taille
boolean gotSendPC()
{
boolean SendFound = false;
static byte index = 0; // là où on est en train d'écrire dans le buffer circulaire
while (Serial2.available() > 0) {
localBuffer[index] = (uint8_t) Serial2.read();
SendFound = true;
for (int i = 0; i < localBufferSize; i++) {
if (localBuffer[(index + 1 + i) % localBufferSize] != SendPC[i]) {
SendFound = false;
break; // pas la peine de continuer, le buffer n'est pas bon
}
}
index++; // le prochain caractère ira dans cette case
if (index == localBufferSize) index = 0; // on boucle dans le buffer circulaire
if (SendFound) break;
}
return SendFound;
}
void setup() {
Serial.begin(115200);
Serial2.begin(9600);
// pas nécessaire pour une variable globale mais pour vous montrer comment faire
// si vous aviez besoin de mettre le buffer à vide
// memset(localBuffer, '\0', localBufferSize);
}
void loop() {
static boolean foundSendPC = false;
if (!foundSendPC) {
foundSendPC = gotSendPC(); // on va voir si on a reçu la phrase
if (foundSendPC) {
Serial.println("Display Gauges Actived");
} else {
// *******************************************************************
// ici vous faites ce que vous voulez, en attendant la phrase magique
// *******************************************************************
// *******************************************************************
}
} else {
// *******************************************************************
// ici vous faites ce que vous voulez, on a reçu la phrase magique
// *******************************************************************
// *******************************************************************
}
}
Il peut aussi être grand comme programme par rapport à ce que je dois faire ?
Voici mon programme fonctionnel en version light:
/* R13 Consult Auto Transmission By 200sx200*/
boolean recept = false;
boolean displayP = false;
byte display1[37];//Open Display
//Consult
byte consult[28];
//int gauges
int tps;
int sped;
// Led remplace solenoid
const int Solenoid_A = 31;
const int Solenoid_B = 33;
const int Solenoid_Clutch = 35;
const int Solenoid_Lockup = 37;
//const int Solenoid_Pressure = 39;
// on when pin is high
// off when pin is low
const int SON = LOW;
const int SOFF = HIGH;
//vitesse
int vitesse = 1;
//setup
void setup() {
Serial.begin(9600);
Serial2.begin(9600);
Serial3.begin(9600);
pinMode(Solenoid_A, OUTPUT); //solenoid A
pinMode(Solenoid_B, OUTPUT); //solenoid B
pinMode(Solenoid_Clutch, OUTPUT); //solenoid Overrun Clutch
pinMode(Solenoid_Lockup, OUTPUT); //solenoid Lock-up
//pinMode(Solenoid_Pressure, OUTPUT); //solenoid Line Pressure
}
void loop() {
if ( recept == false) {
displayO();
}
while (recept == true) {
Serial2.readBytes(consult, 28);
if (consult[0] == 0xFF) {
byteconsult();
//Print();
//-----------------------------Gearbox----------------------------------//
if (recept == true) {
byteconsult();
if (tps >= 3) { // 100% => D1->D2->D3->D4
if (sped < 10) {
Vitesse1();
}
if (sped > 10 && sped <= 14) { //OEM=45->49
Vitesse2();
}
}
}
//-----------------------------Gearbox----------------------------------//
}
}
}//End Loop
//-----------------------Open Display-----------------------//
void displayO() {
Serial3.readBytes(display1, 37);
if ((display1[0] == 6) && (display1[1] == 41) && (display1[3] == 41) && (display1[35] == 41)) {
Serial.println("Open Display detected");
recept = true;
}
}
void byteconsult() {
//Speed kph
sped = consult[4] * 2;
//Throttle Position voltage
tps = consult[11];
tps = ((tps * 20) / 1000.0);
}
void Print() {
Serial.print("Speed kph="); Serial.println(sped);
Serial.print("Throttle="); Serial.println(tps);
}
// 1 => BC
void Vitesse1() {
Serial.println("Vitesse1");
digitalWrite(Solenoid_A, SON);
digitalWrite(Solenoid_B, SON);
digitalWrite(Solenoid_Clutch, SON);
digitalWrite(Solenoid_Lockup, SOFF);
//digitalWrite(Solenoid_Pressure, SOFF);
}
// 2 => ABDEG
void Vitesse2() {
Serial.println("Vitesse2");
digitalWrite(Solenoid_A, SOFF);
digitalWrite(Solenoid_B, SON);
digitalWrite(Solenoid_Clutch, SON);
digitalWrite(Solenoid_Lockup, SOFF);
//digitalWrite(Solenoid_Pressure, SOFF);
}
Sur la fonction Display(), il n'y aura pas d'octet supplémentaire possible(provenance PC).