Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/*
* Neue Uhrzeit von serieller Schnittstelle lesen
*/
int setClock(int oldCounter) {
char in;
in = Serial.read();
Serial.print(in);
if ((in == 10 || in == 13) && (recv_size > 0)) {
parse_cmd(recv, recv_size);
recv_size = 0;
recv[0] = 0;
return 0;
} else if (in < 48 || in > 122) { ; // ignore ~[0-9A-Za-z]
} else if (recv_size > BUFF_MAX - 2) { // drop lines that are too long
// drop
recv_size = 0;
recv[0] = 0;
} else if (recv_size < BUFF_MAX - 2) {
recv[recv_size] = in;
recv[recv_size + 1] = 0;
recv_size += 1;
}
return oldCounter;
}
/*
* Eingegebene Uhrzeit parsen und DS3231 entsprechend setzen
*/
void parse_cmd(char *cmd, int cmdsize) {
uint8_t i;
uint8_t reg_val;
char buff[BUFF_MAX];
struct ts t;
//snprintf(buff, BUFF_MAX, "cmd was '%s' %d\n", cmd, cmdsize);
//Serial.print(buff);
// TssmmhhWDDMMYYYY aka set time
if (cmd[0] == 84 && cmdsize == 16) {
//T355720619112011
t.sec = inp2toi(cmd, 5);
t.min = inp2toi(cmd, 3);
t.hour = inp2toi(cmd, 1);
t.wday = cmd[7] - 48;
t.mday = inp2toi(cmd, 8);
t.mon = inp2toi(cmd, 10);
t.year = inp2toi(cmd, 12) * 100 + inp2toi(cmd, 14);
DS3231_set(t);
Serial.println("OK");
resetStrip();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.