diff options
| author | Yuval Adam <yuv.adm@gmail.com> | 2011-09-23 13:21:29 +0300 |
|---|---|---|
| committer | Yuval Adam <yuv.adm@gmail.com> | 2011-09-23 13:21:29 +0300 |
| commit | 402ab35b1e5961c84f9882c5b5d56d3c93acfb05 (patch) | |
| tree | 127a0eb8b11eb5bb4b3a332aead4635de67f22fb | |
| parent | 69588759ecab0bd4936a7029028b09870034a82a (diff) | |
added event handling for 18 and 19
| -rw-r--r-- | roombacomm-client/src/com/hackingroomba/roombacomm/BetterRoomba.java | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/roombacomm-client/src/com/hackingroomba/roombacomm/BetterRoomba.java b/roombacomm-client/src/com/hackingroomba/roombacomm/BetterRoomba.java index 5a09a48..b14545a 100644 --- a/roombacomm-client/src/com/hackingroomba/roombacomm/BetterRoomba.java +++ b/roombacomm-client/src/com/hackingroomba/roombacomm/BetterRoomba.java @@ -43,11 +43,27 @@ public class BetterRoomba implements SerialPortEventListener { @Override synchronized public void serialEvent(SerialPortEvent e) { try { - System.out.println("Serial event: " + e.getEventType()); - System.out.println("Data available: " + String.valueOf(input.available())); + System.out.print("Serial event " + e.getEventType() + ": "); + + if (isr.ready()) { + int c = isr.read(); + if (c == 18) { + for (int i=0; i<6; i++) { + System.out.print(isr.read() + " "); + } + } + if (c == 19) { + System.out.print(c + " "); + int bytes = isr.read(); + for (int i=0; i<bytes; i++) { + System.out.print(isr.read() + " "); + } + System.out.print("[" + isr.read() + "] "); + } + } + else + System.out.println("For some weird reason the buffer ain't ready."); - while (isr.ready()) - System.out.print(isr.read() + ", "); System.out.println("--"); } catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); |
