diff options
| author | Ido Hadanny <ido.hadanny@gmail.com> | 2011-09-22 21:30:13 +0300 |
|---|---|---|
| committer | Ido Hadanny <ido.hadanny@gmail.com> | 2011-09-22 21:30:13 +0300 |
| commit | 53b947df484159f5934898ba6c0aa69a9c869007 (patch) | |
| tree | 189d5903a67765c390de8f1e3423e6b80cde57d1 /roombacomm-client/src/processing-examples | |
| parent | 654ca6d59e99b5e72b05dfb917bc5888c4ba6b1b (diff) | |
added stuff
Diffstat (limited to 'roombacomm-client/src/processing-examples')
16 files changed, 641 insertions, 0 deletions
diff --git a/roombacomm-client/src/processing-examples/roombaring/roombaring.pde b/roombacomm-client/src/processing-examples/roombaring/roombaring.pde new file mode 100644 index 0000000..74aee3d --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaring/roombaring.pde @@ -0,0 +1,54 @@ +// +// roombaring -- +// +// 2006, Tod E. Kurt, tod@todbot.com, http://roombahacking.com/ +// + +import roombacomm.*; + +String rtttl = "tron:d=4,o=5,b=100:8f6,8c6,8g,e,8p,8f6,8c6,8g,8f6,8c6,8g,e,8p,8f6,8c6,8g,e.,2d"; + +String roombacommPort = "/dev/cu.KeySerial1"; +//String roombacommPort = "/dev/cu.BlueRadios-COM0-1"; + +RoombaCommSerial roombacomm = new RoombaCommSerial(); +if( ! roombacomm.connect( roombacommPort ) ) { + println("couldn't connect. goodbye."); System.exit(1); +} +println("Roomba startup"); +roombacomm.startup(); +roombacomm.control(); +roombacomm.pause(50); + +ArrayList notelist = RTTTLParser.parse( rtttl ); +int songsize = notelist.size(); +// if within the size of a roomba song, make the song, then play +if( songsize <= 16 ) { + println("creating a song with createSong()"); + int notearray[] = new int[songsize*2]; + int j=0; + for( int i=0; i< songsize; i++ ) { + Note note = (Note) notelist.get(i); + int sec64ths = note.duration * 64/1000; + notearray[j++] = note.notenum; + notearray[j++] = sec64ths; + } + roombacomm.createSong( 1, notearray ); + roombacomm.playSong( 1 ); +} +// otherwise, try to play it in realtime +else { + println("playing song in realtime with playNote()"); + int fudge = 20; + for( int i=0; i< songsize; i++ ) { + Note note = (Note) notelist.get(i); + int duration = note.duration; + int sec64ths = duration*64/1000; + if( sec64ths < 5 ) sec64ths = 5; + if( note.notenum != 0 ) + roombacomm.playNote( note.notenum, sec64ths ); + roombacomm.pause( duration + fudge ); + } +} +System.out.println("Disconnecting"); +roombacomm.disconnect(); diff --git a/roombacomm-client/src/processing-examples/roombatune/roombatune.pde b/roombacomm-client/src/processing-examples/roombatune/roombatune.pde new file mode 100644 index 0000000..56fa470 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombatune/roombatune.pde @@ -0,0 +1,111 @@ +// +// roombatune -- +// +// 2006, Tod E. Kurt, tod@todbot.com, http://roombahacking.com/ +// + +import mkv.MyGUI.*; +import roombacomm.*; + +// if you set roombaCommPort to null, it will bring up the port picker dialog +// if you set it to "testdummy", it will be a bring up a non-functioning test of the GUI +//String roombacommPort = "testdummy"; +String roombacommPort = "/dev/cu.KeySerial1"; +//String roombacommPort = "/dev/cu.BlueRadios-COM0-1"; +//String roombacommPort = null; + +RoombaCommSerial roombacomm; +int octave = 6; // which octave we're on when playing notes + +void setup() { + roombacommSetup(); +} + +void draw() { + if( roombacomm == null ) return; +} + +void keyPressed() { + + int note=-1; // -1 means no note yet + switch( key ) { + // pseudo-keyboard to play notes on + case 'a': note = 0; break; + case 'w': note = 1; break; + case 's': note = 2; break; + case 'e': note = 3; break; + case 'd': note = 4; break; + case 'f': note = 5; break; + case 't': note = 6; break; + case 'g': note = 7; break; + case 'y': note = 8; break; + case 'h': note = 9; break; + case 'u': note =10; break; + case 'j': note =11; break; + case 'k': note =12; break; + case 'o': note =13; break; + case 'l': note =14; break; + case 'z': octave--; break; // change octaves + case 'x': octave++; break; // change octaves + } + // we actually hit a note key + if( note >= 0 ) { + octave = (octave < 2) ? 2 : (octave > 9) ? 9 : octave; + note = note + ((octave+1)*12); + if( roombacomm != null ) + roombacomm.playNote( note, 10); + println("playing note: "+note+" (octave:"+octave+")"); + } + +} + +// +void roombacommPortSelected() +{ + roombacomm = new RoombaCommSerial(); + if( roombacommPort.equals("testdummy") ) return; // so we can test UI w/o Roomba + println("opening roomba serial port '" +roombacommPort+"'"); + if( ! roombacomm.connect( roombacommPort ) ) { + println("oh noes"); + } + println("Roomba startup"); + roombacomm.startup(); + roombacomm.control(); + roombacomm.pause(50); + println("Playing some notes"); + roombacomm.playNote( 72, 8 ); + roombacomm.pause( 200 ); + roombacomm.playNote( 72, 10 ); + roombacomm.pause( 200 ); +} + +void roombacommSetup() +{ + if( roombacommPort != null ) { + roombacommPortSelected(); + return; + } + + RoombaComm rc = new RoombaCommSerial(); // throwaway just to find ports + final String portlist[] = rc.listPorts(); // FIXME: should be made static + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + String port = (String) javax.swing.JOptionPane.showInputDialog( null, + "Select Roomba Port", + "RoombaTune", + javax.swing.JOptionPane.QUESTION_MESSAGE, + null, portlist, null); + if( port == null ) { + javax.swing.JOptionPane.showMessageDialog(null, "No port chosen, goodbye"); + System.exit(1); + } + roombacommPort = port; + roombacommPortSelected(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + }); +} diff --git a/roombacomm-client/src/processing-examples/roombaview/data/CourierNewPSMT-9.vlw b/roombacomm-client/src/processing-examples/roombaview/data/CourierNewPSMT-9.vlw Binary files differnew file mode 100644 index 0000000..77af18c --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/CourierNewPSMT-9.vlw diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_backward.png b/roombacomm-client/src/processing-examples/roombaview/data/but_backward.png Binary files differnew file mode 100644 index 0000000..aa0c5d2 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_backward.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_forward.png b/roombacomm-client/src/processing-examples/roombaview/data/but_forward.png Binary files differnew file mode 100644 index 0000000..b11d65b --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_forward.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_spinleft.png b/roombacomm-client/src/processing-examples/roombaview/data/but_spinleft.png Binary files differnew file mode 100644 index 0000000..4bdd361 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_spinleft.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_spinright.png b/roombacomm-client/src/processing-examples/roombaview/data/but_spinright.png Binary files differnew file mode 100644 index 0000000..c7a5c0d --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_spinright.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_stop.png b/roombacomm-client/src/processing-examples/roombaview/data/but_stop.png Binary files differnew file mode 100644 index 0000000..a78b6dc --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_stop.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_turnleft.png b/roombacomm-client/src/processing-examples/roombaview/data/but_turnleft.png Binary files differnew file mode 100644 index 0000000..f47c7ff --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_turnleft.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/but_turnright.png b/roombacomm-client/src/processing-examples/roombaview/data/but_turnright.png Binary files differnew file mode 100644 index 0000000..b554358 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/but_turnright.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/turnfrontleft.png b/roombacomm-client/src/processing-examples/roombaview/data/turnfrontleft.png Binary files differnew file mode 100644 index 0000000..01c1794 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/turnfrontleft.png diff --git a/roombacomm-client/src/processing-examples/roombaview/data/turnfrontright.png b/roombacomm-client/src/processing-examples/roombaview/data/turnfrontright.png Binary files differnew file mode 100644 index 0000000..a0d43d6 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/data/turnfrontright.png diff --git a/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI.zip b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI.zip Binary files differnew file mode 100644 index 0000000..3242bb7 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI.zip diff --git a/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/MyGUI_readme.txt b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/MyGUI_readme.txt new file mode 100755 index 0000000..2426fe2 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/MyGUI_readme.txt @@ -0,0 +1,51 @@ +MyGUI Library
+=======================
+Created by John Beech
+Contact: processing@mkv25.net
+Version: 0010
+=======================
+-Quick installation notes-
+
+Extract contents of this zip file to your processing directory /libraries/
+
+This should create the sub folder called MyGUI/ with MyGUI_readme.txt inside, and a folder
+called MyGUI/library/ with the file MyGUI.jar inside.
+
+=======================
+-Useage notes-
+
+Please see the Documentation files contained within the MyGUI.jar archive.
+
+Alternatively visit http://mkv25.net/MyGUI/doc/
+
+=======================
+-Version History-
+
+ver 0010 - 2005-04-01
+-Fixed Set abstract class MyGUIObject to public (from default) so that it can be extended from within Processing
+
+Ver 0009 - 2005-12-29
+-Fixed Arial-48.vlw moved to sub-folder /data/ inside .JAR, Processing now finds file.
+-Fixed MyGUIButton does not print message "MyGUIStyle has been set!" after setting a specific style.
+
+Ver 0008
+-Bug Arial-48.vlw not found by processing, please include this in your project/sketch folder to use MyGUI library.
+
+Ver 0007
+*Note First release as a library compiled using Eclipse
++Added Basic documentation written
++Added MyGUITextInput, which allows a user to enter and edit text in a field. No copy and paste support.
++Added MyGUICheckbox, check box object.
++Added MyGUIGroup, groups of objects can be moved/rotated
+-Changed MyGUI now inherits properties/methods from MyGUIGroup (see documentation)
+
+Ver 0006 < earlier
+*Note Original classes written from within Processing IDE including MyGUIButton, MyGUIButtonDrag, MyGuiImage, MyGUILabel, MyGUIPinSlider, MyGUIStyle. MyGUIObject used as an interface for compatable objects as well as containing basic box based hit detection code.
+
+=======================
+-Latest version-
+Please check http://mkv25.net/MyGUI/
+
+=======================
+-Credits-
+Created and designed by John Beech
\ No newline at end of file diff --git a/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/library/MyGUI.jar b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/library/MyGUI.jar Binary files differnew file mode 100755 index 0000000..7973ffa --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/libraries/MyGUI/library/MyGUI.jar diff --git a/roombacomm-client/src/processing-examples/roombaview/roombaview.pde b/roombacomm-client/src/processing-examples/roombaview/roombaview.pde new file mode 100644 index 0000000..4c03600 --- /dev/null +++ b/roombacomm-client/src/processing-examples/roombaview/roombaview.pde @@ -0,0 +1,425 @@ +// +// roombaview -- +// +// 2006, Tod E. Kurt, tod@todbot.com, http://roombahacking.com/ +// + +import mkv.MyGUI.*; +import roombacomm.*; + +// if you set roombaCommPort to null, it will bring up the port picker dialog +// if you set it to "testdummy", it will be a bring up a non-functioning test of the GUI +String roombacommPort = "testdummy"; +//String roombacommPort = "/dev/cu.KeySerial1"; +//String roombacommPort = "/dev/cu.BlueRadios-COM0-1"; +//String roombacommPort = null; + +RoombaCommSerial roombacomm; + +MyGUI gui; +MyGUIButton butForward, butBackward, butStop; +MyGUIButton butSpinLeft, butSpinRight, butTurnLeft, butTurnRight; +MyGUIButton butReset, butSafe, butFull, butSpy, butVacuum, butBeep; +MyGUIPinSlider sliderSpeed; +PFont fontA; +// all the colors used +color cBack = color(150); +color cOff = color(100); +color cWhl = color(80); +color cOn = color(255, 0, 0); +color cTxt = color(40); +color cGrid = color(120); +color cFlor = color(190); +color cStat = color(170); +color cBut = color(170,170,210); + +float rx,ry,rangle; // location of displayed roomba icon +float scalex = 0.4; // convert mm to pixels +float scaley = 0.4; // convert mm to pixels + +int frameCounter=0; + +// called once on startup +void setup() { + size(600, 500); + frameRate(5); + smooth(); + background(cFlor); + stroke(100); + ellipseMode(CENTER_RADIUS); + rectMode(CENTER); + // Initiate GUI objects + fontA = loadFont("CourierNewPSMT-9.vlw"); + textFont(fontA, 12); + fill(0); + gui = new MyGUI(this); + makeMoveButtons(width-75,height-100); + makeControlButtons(width-75,height-225); + + roombacommSetup(); + reset(); +} + +void reset() { + rx = width/2; + ry = height/2; + rangle = 0; +} + +// called 'framerate' times a second +void draw() { + frameCounter++; + background(cFlor); + fill(0); + stroke(100); + + drawGridlines(); + drawStatus(); + if( roombacomm != null ) { + computeRoombaLocation(); + drawRoombaStatus( rx, ry, rangle ); + updateRoombaState(); + } +} + +// +// Get roomba sensors and update display +// +void updateRoombaState() { + roombacomm.sensors(); +} + +// +void computeRoombaLocation() { + int distance = roombacomm.distance(); + float angle = roombacomm.angleInRadians(); + rangle = rangle - angle ; + rangle %= TWO_PI; + float dx = distance * sin(rangle); + float dy = distance * cos(rangle); + rx = rx + (dx * scaley); + ry = ry - (dy * scalex); + + // torroidial mapping, sir + if( rx > width ) rx = 0; + if( rx < 0 ) rx = width; + if( ry > height ) ry = 0; + if( ry < 0 ) ry = height; +} + +// +// +void actionPerformed(ActionEvent e) { + println("e="+e); + if( !roombacomm.connected() ) return; + String cmd = e.getActionCommand(); + Object src = e.getSource(); + + if( cmd.equals("speed-update") ) { + roombacomm.setSpeed( sliderSpeed.getValue() ); + return; + } + else if( src == butStop ) { + roombacomm.stop(); + } else if( src == butForward ) { + roombacomm.goForward(); + } else if( src == butBackward ) { + roombacomm.goBackward(); + } else if( src == butSpinLeft ) { + roombacomm.spinLeft(); + } else if( src == butSpinRight ) { + roombacomm.spinRight(); + } else if( src == butTurnLeft ) { + roombacomm.turnLeft(); + } else if( src == butTurnRight ) { + roombacomm.turnRight(); + } else if( src == butReset ) { + roombacomm.reset(); + reset(); + } else if( src == butSafe ) { + roombacomm.start(); + roombacomm.control(); + } else if( src == butFull ) { + roombacomm.start(); + roombacomm.control(); + roombacomm.full(); + } else if( src == butSpy ) { + roombacomm.start(); + roombacomm.clean(); // clean mode + } else if( src == butBeep ) { + int song[] = { 69,8, 72,18, 76,8}; + roombacomm.createSong(1, song ); + roombacomm.playSong(1); + } +} + +// +// called on key press +// +void keyPressed() { + if( key == CODED ) { + if( keyCode == UP ) + roombacomm.goForward(); + else if( keyCode == DOWN ) + roombacomm.goBackward(); + else if( keyCode == LEFT ) + roombacomm.spinLeft(); + else if( keyCode == RIGHT ) + roombacomm.spinRight(); + } + else if( keyCode == RETURN || keyCode == ENTER ) { + println("resetting"); + roombacomm.reset(); + reset(); + } + else if( key == ' ' ) { + roombacomm.stop(); + } + else if( key == '.' || key == '>' ) { + sliderSpeed.setValue( sliderSpeed.getValue() + 25 ); + roombacomm.setSpeed( sliderSpeed.getValue() ); + } + else if( key == '.' || key == '>' ) { + sliderSpeed.setValue( sliderSpeed.getValue() - 25 ); + roombacomm.setSpeed( sliderSpeed.getValue() ); + } +} + +// +// drawRoombaStatus -- called during every draw() +// draws a little virtual roomba with in-built sensor icons +// +void drawRoombaStatus(float posx, float posy, float angle) { + pushMatrix(); + translate( (int)posx,(int)posy); + rotate(angle); + smooth(); + textFont(fontA, 10); + textAlign(CENTER); + + fill(cBack); + strokeWeight(2); + stroke(100); + ellipseMode(CENTER_RADIUS); + //rectMode(CENTER); + ellipse(0,0, 50,50); + + fill(0); + stroke(cTxt); + strokeWeight(4); + text("cliff", 0, -30); + if( roombacomm.cliffLeft() ) stroke(cOn); + else stroke(cOff); + line(-35,-25, -40,-15); + if( roombacomm.cliffRight() ) stroke(cOn); + else stroke(cOff); + line( 35,-25, 40,-15); + + if( roombacomm.cliffFrontLeft() ) stroke(cOn); + else stroke(cOff); + line(-30,-30, -20,-30); + if( roombacomm.cliffFrontRight() ) stroke(cOn); + else stroke(cOff); + line( 30,-30, 20,-30); + + stroke(cTxt); + strokeWeight(7); + text("bump", 0,-17); + if( roombacomm.bumpLeft() ) stroke(cOn); + else stroke(cOff); + line(-25,-20, -20,-20); + if( roombacomm.bumpRight() ) stroke(cOn); + else stroke(cOff); + line( 25,-20, 20,-20); + + stroke(cTxt); + text("wheeldrop", 0,3); + if( roombacomm.wheelDropLeft() ) stroke(cOn); + else stroke(cWhl); + line(-35,8, -20, 8); + if( roombacomm.wheelDropRight() ) stroke(cOn); + else stroke(cWhl); + line( 35,8, 20, 8); + if( roombacomm.wheelDropCenter()) stroke(cOn); + else stroke(cWhl); + line(-2,-8, 2,-8); + + stroke(cTxt); + strokeWeight(5); + text("over",0,18); + if( roombacomm.motorOvercurrentDriveLeft() ) stroke(cOn); + else stroke(cOff); + line(-30,16, -20, 16); + if( roombacomm.motorOvercurrentDriveRight() ) stroke(cOn); + else stroke(cOff); + line( 30,16, 20, 16); + + stroke(cTxt); + strokeWeight(7); + text("dirt",0,42); + if( roombacomm.dirtLeft()>0 ) stroke(40,40,roombacomm.dirtLeft()); + else stroke(cOff); + line(-22,40,-18,40); + if( roombacomm.dirtRight()>0 ) stroke(40,40,roombacomm.dirtRight()); + else stroke(cOff); + line( 22,40, 18,40); + + popMatrix(); +} + +// called during each draw() +void drawStatus() { + fill(cStat); + rectMode(CENTER); + rect( width-75,height-125, 150,250 ); + + rectMode(CORNER); + rect(0,0, width,50); + fill(0); + textAlign(LEFT); + textFont(fontA,14); + String status = "unknown"; + int batt_percent=0, batt_charge=0, batt_volts=0, batt_mA=0, batt_cap=0; + if( roombacomm == null ) { + status = "not connected. no roomba. please restart."; + } else if( ! roombacomm.connected() ) { + status = "not connected. no roomba. please restart."; + } else if( ! roombacomm.sensorsValid() ) { + status = "connected. sensors invalid. unplugged?"; + } else if( roombacomm.safetyFault() ) { + status = "connected. safety fault. reposition roomba and reset."; + } else { + status = "connected. roomba detected. ok."; + } + if( roombacomm != null ) { + batt_mA = roombacomm.current(); + batt_volts = roombacomm.voltage(); + batt_charge = roombacomm.charge(); + batt_cap = roombacomm.capacity(); + batt_percent = (batt_cap == 0) ? 0 : (batt_charge*100)/batt_cap; + } + text(" status: "+status, 8,12); + text(" mode: "+((roombacomm==null)?"no roomba":roombacomm.modeAsString()), 8,24); + text("battery: "+batt_percent+"% ("+batt_charge+"/"+batt_cap+" mAh) voltage: " + +batt_volts+" mV @ "+batt_mA+" mA", 8,36); +} + +// called during each draw() +void drawGridlines() { + int gridspacing = 50; + stroke(cGrid); + strokeWeight(1); + for( int i=0; i< 15; i++ ) { + line(0, i*gridspacing, width, i*gridspacing); + line(i*gridspacing,0, i*gridspacing, height); + } +} + +// +void makeMoveButtons(int posx, int posy) { + MyGUIGroup buttonGroup = new MyGUIGroup(this, posx, posy); + buttonGroup.setStyle( new MyGUIStyle(this, cBut) ); + PImage forward = loadImage("but_forward.png"); + PImage backward = loadImage("but_backward.png"); + PImage spinleft = loadImage("but_spinleft.png"); + PImage spinright = loadImage("but_spinright.png"); + PImage stopit = loadImage("but_stop.png"); + PImage turnFL = loadImage("but_turnleft.png"); + PImage turnFR = loadImage("but_turnright.png"); + butForward = new MyGUIButton(this, 0,-45, forward); + butBackward = new MyGUIButton(this, 0, 45, backward); + butSpinLeft = new MyGUIButton(this,-45, 0, spinleft); + butSpinRight = new MyGUIButton(this, 45, 0, spinright); + butStop = new MyGUIButton(this, 0, 0, stopit); + butTurnLeft = new MyGUIButton(this,-45,-45, turnFL); + butTurnRight = new MyGUIButton(this, 45,-45, turnFR); + sliderSpeed = new MyGUIPinSlider(this, 0,80, 100,20, 0,500); + sliderSpeed.setValue(200); + sliderSpeed.setActionCommand("speed-update"); + + gui.add(buttonGroup); + //buttonGroup.add( label ); + buttonGroup.add( butForward ); + buttonGroup.add( butBackward ); + buttonGroup.add( butSpinLeft ); + buttonGroup.add( butSpinRight); + buttonGroup.add( butStop ); + buttonGroup.add( butTurnLeft ); + buttonGroup.add( butTurnRight ); + buttonGroup.add( sliderSpeed ); +} + +// +void makeControlButtons(int posx, int posy) { + MyGUIGroup buttonGroup = new MyGUIGroup(this, posx,posy); + buttonGroup.setStyle( new MyGUIStyle(this, cBut) ); + butReset = new MyGUIButton(this, -40, 25, "reset", 35,20 ); + butSafe = new MyGUIButton(this, 0, 25, "safe", 35,20 ); + butFull = new MyGUIButton(this, 40, 25, "full", 35,20 ); + butSpy = new MyGUIButton(this, -40, 0, "SPY", 35,20 ); + butBeep = new MyGUIButton(this, 40, 0, "beep", 35,20 ); +// butVacuum = new MyGUIButton(this, 40, 25, "vacuum", 35,20 ); + + gui.add( buttonGroup ); + buttonGroup.add( butReset ); + buttonGroup.add( butSafe ); + buttonGroup.add( butFull ); + buttonGroup.add( butSpy ); + buttonGroup.add( butBeep ); + //buttonGroup.add( butVacuum ); +} + +// +void roombacommPortSelected() +{ + roombacomm = new RoombaCommSerial(); + if( roombacommPort.equals("testdummy") ) return; // so we can test UI w/o Roomba + println("opening roomba serial port '" +roombacommPort+"'"); + if( ! roombacomm.connect( roombacommPort ) ) { + println("oh noes"); + } + println("Roomba startup"); + roombacomm.startup(); + roombacomm.control(); + roombacomm.pause(50); + println("Playing some notes"); + roombacomm.playNote( 72, 8 ); + roombacomm.pause( 200 ); + roombacomm.playNote( 72, 10 ); + roombacomm.pause( 200 ); +} + +// +// On startup, popup a dialog to choose roomba port +// +void roombacommSetup() +{ + if( roombacommPort != null ) { + roombacommPortSelected(); + return; + } + + RoombaComm rc = new RoombaCommSerial(); // throwaway just to find ports + final String portlist[] = rc.listPorts(); // FIXME: should be made static + javax.swing.SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + String port = (String) javax.swing.JOptionPane.showInputDialog( null, + "Select Roomba Port", + "RoombaView", + javax.swing.JOptionPane.QUESTION_MESSAGE, + null, portlist, null); + if( port == null ) { + javax.swing.JOptionPane.showMessageDialog(null, "No port chosen, goodbye"); + System.exit(1); + } + roombacommPort = port; + roombacommPortSelected(); + } + catch (Exception e) { + e.printStackTrace(); + } + } + } ); + +} |
