PadController/handelSerial.h

185 lines
4.2 KiB
C
Raw Normal View History

2022-08-21 14:00:32 +02:00
void handelSerial(){
String serialin = Serial.readStringUntil('\n');
if(rpiStatus == rpi_on){
rpiSince = millis();
}
if(rpiStatus == rpi_starting){
rpiStatus = rpi_on;
rpiSince = millis();
}
if(!serialin.startsWith("<"))return;
String command = serialin.substring(1,serialin.indexOf(">"));
String goonin = serialin.substring(serialin.indexOf(">")+1);
if(command == "ping"){
Serial.println("<ok>");
return;
}
if(command=="setBLE"){
changeMode(mode_bluetooth);
return;
}
if(command=="setNRF"){
changeMode(mode_radio);
//goonin == "0" //idel
if(goonin=="1"){ //scan
}
if(goonin=="2"){ //auto connect
}
return;
}
if(command=="readAnalogRaw"){
Serial.println(readAnalog(hextonum(goonin),true));
}
if(command=="readAnalog"){
Serial.println(readAnalog(hextonum(goonin)));
}
if(command=="setDEBUG"){
changeMode(mode_debug);
return;
}
if(command=="readMPU"){
if(NRFisConnected==1){
uint16_t buf = 1;
uint16_t kind = goonin.toInt();
if(kind>2){
Serial.println("<readMPU>error");
return;
}
buf |= kind<<8;
if(sendRCdata(&buf,2)){
Serial.println("<readMPU>send");
}else{
Serial.println("<readMPU>lost");
}
}else{
Serial.println("<readMPU>noconn");
}
return;
}
if(command=="readCOMP"){
if(NRFisConnected==1){
uint16_t buf = 2;
if(sendRCdata(&buf,2)){
Serial.println("<readCOMP>send");
}else{
Serial.println("<readCOMP>lost");
}
}else{
Serial.println("<readCOMP>noconn");
}
return;
}
if(command=="readGNSS"){
if(NRFisConnected==1){
uint16_t buf = 3;
uint16_t kind = goonin.toInt();
if(kind>7){
Serial.println("<readGNSS>error");
return;
}
buf |= kind<<8;
if(sendRCdata(&buf,2)){
Serial.println("<readGNSS>send");
}else{
Serial.println("<readGNSS>lost");
}
}else{
Serial.println("<readGNSS>noconn");
}
return;
}
if(command=="readAnalogDesc"){
if(NRFisConnected==1){
uint16_t buf = 50;
uint16_t kind = goonin.toInt();
if(kind>11){
Serial.println("<readAnalogDesc>error");
return;
}
buf |= kind<<8;
if(sendRCdata(&buf,2)){
Serial.println("<readAnalogDesc>send");
}else{
Serial.println("<readAnalogDesc>lost");
}
}else{
Serial.println("<readAnalogDesc>noconn");
}
return;
}
if(command=="readButtonDesc"){
if(NRFisConnected==1){
uint16_t buf = 51;
uint16_t kind = goonin.toInt();
if(kind>31){
Serial.println("<readButtonDesc>error");
return;
}
buf |= kind<<8;
if(sendRCdata(&buf,2)){
Serial.println("<readButtonDesc>send");
}else{
Serial.println("<readButtonDesc>lost");
}
}else{
Serial.println("<readButtonDesc>noconn");
}
return;
}
if(command=="getARC"){
if(NRFisConnected==1){
Serial.print("<getARC>");
Serial.println(radio.getARC());
}else{
Serial.println("<getARC>noconn");
}
return;
}
if(command=="loadCalibrationData"){
loadCalibrationData(goonin);
}
if(command=="loadLEDProgram"){
loadLEDProgram(goonin);
}
if(command=="putBLEProgram0"){
BLEProgramCache[0] = goonin;
preferences.putString("BLEPchache_0",goonin);
}
if(command=="putBLEProgram1"){
BLEProgramCache[1] = goonin;
preferences.putString("BLEPchache_1",goonin);
}
if(command=="putBLEProgram2"){
BLEProgramCache[2] = goonin;
preferences.putString("BLEPchache_2",goonin);
}
if(command=="putBLEProgram3"){
BLEProgramCache[3] = goonin;
preferences.putString("BLEPchache_3",goonin);
}
if(command=="putBLEProgram4"){
BLEProgramCache[4] = goonin;
preferences.putString("BLEPchache_4",goonin);
}
if(command=="BLEnextProgram"){
BLEnextProgram();
}
if(command=="BLEgetProgramId"){
Serial.print("<BLEgetProgramId>");
Serial.println(BLEProgramActive);
}
if(command=="BLEsetProgramId"){
Serial.print("<BLEgetProgramId>");
BLEProgramActive = goonin.toInt()-1;
BLEnextProgram();
}
if(command=="reset"){
preferences.clear();
ESP.restart();
}
}