So I’ve been using Putty to talk with Arduino Micro and I have only 4 Commands or actually Char X, S, C & R
R is a resume command and the X is the exit command, I echo the Serial.read to the terminal because I had automatic resumes that seem to occur without reason
The code which works resumes ckSerialIn() if it receives a char it does not understand, so it’s doing what it’s suppose to. However, I noticed on the output of the terminal when I physically send X to stop everything and don’t touch my keyboard or mouse the loop resumes again and the chars I get are
[
2
8
~
Is there some significance to this [28~???
void loop()
{
char keypress;
int idx;
//digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
//Serial.print("state in ");
//Serial.println(state);
//jumper not installed
if (digitalRead(FREE_RUN)){
if (state == FREERUN){
state = mIDLE;
digitalWrite(OP_SHDN_L, OP_OFF);
//Serial.println("enter state mIDLE"); //Debug
}
}else{
if ((state == mIDLE) & !SERCONTROL){
state = FREERUN;
digitalWrite(OP_SHDN_L, OP_ON);
//Serial.println("state mIDLE Entering FREERUN"); //Debug
}
}
//SCK Jumper J8 to force calibration;
if (!digitalRead(CAL_MODE)){
if (state != CALMENU){
state = initCALMENU; //cal mode
//Serial.println("state initCALMENU"); //Debug
}else{
state != CALMENU;
//Serial.println("state CALMENU"); //Debug
}
}
if (Serial.available() > 0){
//digitalWrite(Debug_IO11, HIGH);
keypress = ckSerialIn( Serial.read() ); //Serial.read(); //rev 1.5
//Serial.end(); // Ends the serial communication once all data is received
//Serial.begin(19200); // Re-establishes serial communication , this causes deletion of anything previously stored in the buffer or cache
//if (keypress == 'F'){
// SERCONTROL = true;
// }
if (SERCONTROL == false){
//Serial.println(state); //Debug
Serial.println("Timer Stopped V"+Version);
//Serial.println(keypress); //Debug
Serial.println("cmd R resume, S reset or C cal status or move jumper from J9 to J8 for cal menu");
//Serial.end(); // Ends the serial communication once all data is received
//Serial.begin(19200); // Re-establishes serial communication , this causes deletion of anything previously stored in the buffer or cache
}
Serial.println(FR_INTERVAL);
SERCONTROL = true;
t.stop(tickEvent);
state = mIDLE;
digitalWrite(OP_SHDN_L, OP_OFF);
//keypress = Serial.read(); //rev 1.5 moved to serial available() above
//digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
//delay(100);
//digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
switch(keypress){
case ('R'): //resume rev 1.3
Serial.println("Freerun Started");
tickEvent = t.every(FR_INTERVAL, doFreeRun);
state = FREERUN;
digitalWrite(OP_SHDN_L, OP_ON);
SERCONTROL = false;
pinMode(Background, OUTPUT); //Pre //rev 1.4 //rev 1.71
digitalWrite(Background, HIGH); //rev 1.4
break;
case ('S'): //reset arduino stats rev 1.3
Serial.println("Reset Stats");
//reset usedCapacity to 0.0
for (idx = 0;idx < 8; idx++){
battery[idx].usedCapacity = 0.0;
}
cycles = 0;
break; //rev 1.2 added missing break
case ('C'): // get cal and status info rev 1.3
doPrintCalib();
break;
}
//digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
}
//digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
switch (state){
case (initCALMENU): //Hardware selected Jumper
delay(500);
LoadSettings();
clearAndHome();
drawCalMenu(0);
state = CALMENU;
digitalWrite(OP_SHDN_L, OP_OFF);
break;
case CALMENU:
serviceCalMenu();
break;
case mIDLE:
break;
case PULSE: // pin input trigger
// digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
//delay(100);
// digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
doFreeRun();
delay(10); //100ms debounce/holdoff why are we adding a delay here?
state = mIDLE; //wait for the next trigger
break;
case FREERUN: //timer trigger
t.update();
break;
}
digitalWrite(Debug_IO11, HIGH); //Debug IO13 pin 18
digitalWrite(Debug_IO11, LOW); //Debug IO13 pin 18
}
/*
* ckSerialIn ()
* @Desc - Sanitizes the LabView input, by validation of characters
* in the event of an invalid character this function cmd
* "R" for Resume cmd.
* @Parm - chr character input
* @retn - returns character
*
*/
char ckSerialIn( char chr )
{
Serial.println(chr); //Debug
switch(chr){ //Sanitize USB Input
case ('X'): return 'X'; break;// exit cmd for loop()
case ('S'): return 'S'; break;// reset arduino stats
case ('C'): return 'C'; break;// get cal and status info
case ('R'): return 'R'; break;// resume cmd if sent
default: return 'R'; break;// resume cmd for if anything else is sent
}
//new code, make this function universal for all user input
//change parameter declaration to string and return will be string
//I think we can cast from string to char or int but need to check.
}