Ciao,in un void da quando ho aggiunto il codice con il comando [ ?h ] non mi funziona più il comando [ ?P ].
Il comando ?P,mi permette di conoscere data/ora del rtc.
Il comando ?h,mi permette di conoscere i valore scritti in e2prom degli indirizzi 5,6,7,8.
Non Capisco,dove sbaglio.
Grazie,allego il void del codice.
void RTC_Seriale () {
// Wait for incoming data on serial port
if (Serial.available() > 0) {
// Read the incoming character
char incoming_char = Serial.read();
// End of line?
if(incoming_char == '
) {
//
// Lista Comandi
//
// ?? Verifica Trasmissione TxRx
if(serial_buffer[0] == '?' && serial_buffer[1] == '?')
Serial.println("Trasmissione OK");
// ?V Versione File
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'V')
Serial.println(VERSION);
// ?P Richiesta Giorno/Data/Ora Attuale
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'P') {
DateTime now = RTC.now();
char time_string[20];
sprintf(time_string, "Giorno [ %01d ] Data [ %02d/%02d/%d ] Ora [ %02d:%02d:%02d ]",
now.dayOfTheWeek(),
now.day(), now.month(), now.year(),
now.hour(), now.minute(), now.second());
Serial.println(time_string);
}
// ?R Rifasamento Data/Ora da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'R') {
String time_string = String(serial_buffer);
int day = time_string.substring(2, 4).toInt();
int month = time_string.substring(4, 6).toInt();
int year = time_string.substring(6, 10).toInt();
int hour = time_string.substring(10, 12).toInt();
int minute = time_string.substring(12, 14).toInt();
int second = time_string.substring(14, 16).toInt();
RTC.adjust(DateTime(year, month, day, hour, minute, second));
Serial.println("RTC Rifasato");
}
// ?H Imposta Selezione Fasce On / Off da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'H') {
String time_string = String(serial_buffer);
int hour_on = time_string.substring(2, 4).toInt();
int minute_on = time_string.substring(4, 6).toInt();
int hour_off = time_string.substring(6, 8).toInt();
int minute_off = time_string.substring(8, 10).toInt();
address = 5;
value = hour_on ;
EEPROM.write(address, value);
address = 6;
value = minute_on ;
EEPROM.write(address, value);
address = 7;
value = hour_off ;
EEPROM.write(address, value);
address = 8;
value = minute_off ;
EEPROM.write(address, value);
Serial.println("Impostata Selezione Oraria");
}
//
// Quando aggiungo questo pezzo di codice non funziona il comando ?P
//
// ?h Richiesta Parametri Selezione Fasce On / Off impostati
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'h') {
String time_string = String(serial_buffer);
int hour_on = time_string.substring(2, 4).toInt();
int minute_on = time_string.substring(4, 6).toInt();
int hour_off = time_string.substring(6, 8).toInt();
int minute_off = time_string.substring(8, 10).toInt();
address = 5;
value = EEPROM.read(address);
Serial.print ("Ora di Start : ");
Serial.print (value);
Serial.println (" ");
address = 6;
value = EEPROM.read(address);
Serial.print ("Minuti di Start : ");
Serial.print (value);
Serial.println (" ");
address = 7;
value = EEPROM.read(address);
Serial.print ("Ora di Stop : ");
Serial.print (value);
Serial.println (" ");
address = 8;
value = EEPROM.read(address);
Serial.print ("Minuti di Stop : ");
Serial.print (value);
Serial.println (" ");
Serial.println("Parametri Selezione Fasce On / Off impostati");
}
//////////////////////////////////////////////////////////////////////////////////////////////
// ?r Richiesta Variabili L/S da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'r') {
for (int address = 0; address <= 4; address++) {
value = EEPROM.read(address);
Serial.print(F("Step\t = \t"));
Serial.print( char('a'+address) );
Serial.print(F("\t ; \t Valore \t = \t"));
Serial.println(value, DEC);
delay(100);
if (address == 4) {
address = 0;
Serial.println();
break;
}
}
}
// ?w Imposta Variabili L/S da Terminale Operatore
else if(serial_buffer[0] == '?' && serial_buffer[1] == 'w') {
String time_string = String(serial_buffer);
int attendiS31 = time_string.substring(2, 3).toInt();
int attendiSdom = time_string.substring(3, 4).toInt();
int attendiL31 = time_string.substring(4, 5).toInt();
int attendiLdom = time_string.substring(5, 6).toInt();
int read_write = time_string.substring(6, 7).toInt();
address = 0;
value = attendiS31 ;
EEPROM.write(address, value);
address = 1;
value = attendiSdom ;
EEPROM.write(address, value);
address = 2;
value = attendiL31 ;
EEPROM.write(address, value);
address = 3;
value = attendiSdom ;
EEPROM.write(address, value);
address = 4;
value = read_write ;
EEPROM.write(address, value);
Serial.println("Variabili L/S Rifasate");
}
//////////////////////////////////////////////////////////////////////////////////////////////
// Reset the buffer
buffer_position = 0;
memset(serial_buffer, 0x00, BUFFER_SIZE);
}
// Carriage return, do nothing
else if(incoming_char == '\r');
// Normal character
else {
// Buffer full, we need to reset it
if(buffer_position == BUFFER_SIZE - 1) buffer_position = 0;
// Store the character in the buffer and move the index
serial_buffer[buffer_position] = incoming_char;
buffer_position++;
}
}
}