Skip to content

Commit

Permalink
Added support for serial lost
Browse files Browse the repository at this point in the history
Continuing with the support for serial connections, the app detects if
the connection has been lost, removes the port from the list and shows
an error message.
  • Loading branch information
frivolas committed Nov 10, 2016
1 parent f9cb2c6 commit 0f8632c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 17 additions & 1 deletion TinyTerm.pde
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,24 @@ void refreshSerial(){
}
println("Adding port "+ detectedPort + " to the list");
serialPortsList.addItem(detectedPort, numberofPorts);
} else if(Serial.list().length < numberofPorts){
myTerminal.append(theTime() + "Added port: " + detectedPort + " to the list of connections... \n");
} else if((Serial.list().length < numberofPorts) && deviceDetected){
// We lost the connection
println("Lost a port, refresh list");
deviceDetected = false;
// compare the current Serial list with the original list
for(int i=0;i<numberofPorts;i++){
for(int j=0;j<Serial.list().length;j++){
if(Serial.list()[j].equals(portNames[i])){
detectedPort=portNames[i]; // we lost this port
break;
}
}
}
println("Need to remove " + detectedPort + " from the list");
myTerminal.append(theTime() + "Lost connection on port: " + detectedPort + "\n");
myTerminal.append(theTime() + "Please connect a device to continue ... \n");
myTerminal.scroll(1);
}

}
Binary file modified build/TinyTerm.class
Binary file not shown.
16 changes: 15 additions & 1 deletion build/source/TinyTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,22 @@ public void refreshSerial(){
}
println("Adding port "+ detectedPort + " to the list");
serialPortsList.addItem(detectedPort, numberofPorts);
} else if(Serial.list().length < numberofPorts){
myTerminal.append(theTime() + "Added port: " + detectedPort + " to the list of connections... \n");
} else if((Serial.list().length < numberofPorts) && deviceDetected){
// We lost the connection
println("Lost a port, refresh list");
deviceDetected = false;
// compare the current Serial list with the original list
for(int i=0;i<numberofPorts;i++){
for(int j=0;j<Serial.list().length;j++){
if(Serial.list()[j].equals(portNames[i])){
detectedPort=portNames[i]; // we lost this port
break;
}
}
}
println("Need to remove " + detectedPort + " from the list");
myTerminal.append(theTime() + "Lost connection on port: " + detectedPort + "\n");
}

}
Expand Down

0 comments on commit 0f8632c

Please sign in to comment.