@Test public void testMacroCommands() { Light light = new Light("Living Room"); Stereo stereo = new Stereo("Livin Room"); LightOnCommand lightOnCommand = new LightOnCommand(light); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); LightOffCommand lightOffCommand = new LightOffCommand(light); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); Command[] partyOn = {lightOnCommand, stereoOnWithCDCommand}; Command[] partyOff = {lightOffCommand, stereoOffCommand}; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); RemoteControl remoteControl = new RemoteControl(); remoteControl.setCommand(0, partyOnMacro, partyOffMacro); System.out.println(remoteControl); System.out.println("-----Pushing macro on-----"); remoteControl.onButtonWasPushed(0); System.out.println("-----Pushing macro off-----"); remoteControl.offButtonWasPushed(0); }
public static void main(String[] args) { RemoteControl rc = new RemoteControl(); Light light = new Light(); Stereo stereo = new Stereo("livingroom"); Hottub hottub = new Hottub(); LightOnCommand loc = new LightOnCommand(light); LightOffCommand loffc = new LightOffCommand(light); StereoOnCommand soc = new StereoOnCommand(stereo); StereoOffCommand soffc = new StereoOffCommand(stereo); HottubOnCommand hoc = new HottubOnCommand(hottub); HottubOffCommand hoffc = new HottubOffCommand(hottub); Command[] partyOn = {loc, soc, hoc}; Command[] partyOff = {loffc, soffc, hoffc}; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); rc.setCommand(0, partyOnMacro, partyOffMacro); rc.onButtonWasPressed(0); rc.offButtonWasPressed(0); }
/** Main entry to the program. */ public static void main(String[] args) { RemoteControl remote = new RemoteControl(); RemoteDevice racecar = Bluetooth.getKnownDevice("Batmobile"); if (racecar == null) { System.out.println("No Such device existed"); System.exit(1); } BTConnection racecarConnection = Bluetooth.connect(racecar); if (racecarConnection == null) { System.out.println("Connection Failed"); System.exit(1); } else { System.out.println("Connected to Racecar"); } DataOutputStream dos = racecarConnection.openDataOutputStream(); try { System.out.println("Sending controller signal"); dos.writeInt(CONTROLLER_DEVICE); dos.flush(); System.out.println("Sent Controller signal"); } catch (Exception ex) { // Do nothing } remote.setRacecarConnection(racecarConnection); remote.setRacecarOutputStream(dos); // Waiting for flag to set us off here System.out.println("Waiting for Flag connection"); NXTConnection flagConnection = Bluetooth.waitForConnection(); System.out.println("Connected to flag"); DataInputStream dis = flagConnection.openDataInputStream(); try { int check = dis.readInt(); if (check == FLAG_SIGNAL) { System.out.println("Recived flag signal"); dos.writeInt(FLAG_SIGNAL); dos.flush(); System.out.println("sent flag signal to racecar"); dis.close(); remote.run(); } else { System.out.println("Did not recieve flag connection"); } } catch (Exception e) { } }
public static void serverLoop() { try { ss = new ServerSocket(RemoteControl.props.getInt("port", 11946)); } catch (IOException e) { log.severe("RemoteControl could not bind to port"); } try { while (loop) { Client c = RemoteControl.isParanoid() ? new SecureClient(ss.accept()) : new NormalClient(ss.accept()); clients.add(c); c.setName(c.getName().replace("Thread", "Client")); c.start(); } } catch (IOException e) { log.info("RemoteControl could not set up connection to client" + " or was disabled"); } catch (NullPointerException e) { // duhr, ss failed. } }
public static void main(String[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); GarageDoor garageDoor = new GarageDoor(light); GarageDoorOpenCommand doorUp = new GarageDoorOpenCommand(garageDoor); remote.setCommand(lightOn); remote.buttonPressed(); remote.setCommand(lightOff); remote.buttonPressed(); remote.setCommand(doorUp); remote.buttonPressed(); RemoteControl complexRemote = new RemoteControl(); Stereo stereo = new Stereo(); CD cd = new CD("Sgt. PepperÕs Lonely Hearts Club Band"); StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo, cd); StereoOffWithCDCommand stereoOff = new StereoOffWithCDCommand(stereo, cd); complexRemote.setCommand(0, lightOn, lightOff); complexRemote.setCommand(1, stereoOn, stereoOff); System.out.println(complexRemote); complexRemote.onButtonWasPushed(0); complexRemote.onButtonWasPushed(1); complexRemote.offButtonWasPushed(0); CeilingFan ceilingFan = new CeilingFan("Living Room"); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); complexRemote.setCommand(0, ceilingFanMedium, ceilingFanOff); complexRemote.setCommand(1, ceilingFanHigh, ceilingFanOff); complexRemote.setCommand(2, ceilingFanLow, ceilingFanOff); complexRemote.onButtonWasPushed(0); complexRemote.offButtonWasPushed(0); System.out.println(complexRemote); complexRemote.undoButtonWasPushed(); }