From 947b3126adee00fdc547996ec749e0514a36fe57 Mon Sep 17 00:00:00 2001 From: Sam Adams Date: Fri, 5 Sep 2014 15:24:05 +0100 Subject: [PATCH 1/5] added some deps and moved steps out to json --- README.md | 1 + commands.json | 26 ++++++++++++++++++++++++++ requirements.txt | 1 + retaliation.py | 43 +++++++++---------------------------------- 4 files changed, 37 insertions(+), 34 deletions(-) create mode 100644 commands.json create mode 100644 requirements.txt diff --git a/README.md b/README.md index c31f524..35b4121 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ in this video. It may work with other models but I've only tested with this one. * Python 2.6+ * Python PyUSB Support (on Mac use brew to "brew install libusb") + * ```pip install -r requirements.txt``` * Should work on Windows, Mac and Linux Thanks to the dev team at PaperCut (working on print diff --git a/commands.json b/commands.json new file mode 100644 index 0000000..8890039 --- /dev/null +++ b/commands.json @@ -0,0 +1,26 @@ +{ + "ben" : [ + ["led", 1], + ["right", 2100], + ["up", 700], + ["fire", 1], + ["led", 0], + ["zero", 0] + ], + "shaun" : [ + ["led", 1], + ["right", 2450], + ["up", 550], + ["fire", 1], + ["led", 0], + ["zero", 0] + ], + "sam" : [ + ["led", 1], + ["right", 1950], + ["up", 500], + ["fire", 1], + ["led", 0], + ["zero", 0] + ] +} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1cd0447 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pyusb==1.0.0b1 diff --git a/retaliation.py b/retaliation.py index 763c829..6acf086 100755 --- a/retaliation.py +++ b/retaliation.py @@ -83,44 +83,20 @@ import usb.core import usb.util +import json + ########################## CONFIG ######################### # -# Define a dictionary of "command sets" that map usernames to a sequence -# of commands to target the user (e.g their desk/workstation). It's -# suggested that each set start and end with a "zero" command so it's +# Json structure representing targets. +# It's suggested that each set start and end with a "zero" command so it's # always parked in a known reference location. The timing on move commands # is milli-seconds. The number after "fire" denotes the number of rockets # to shoot. # -COMMAND_SETS = { - "will" : ( - ("zero", 0), # Zero/Park to know point (bottom-left) - ("led", 1), # Turn the LED on - ("right", 3250), - ("up", 540), - ("fire", 4), # Fire a full barrage of 4 missiles - ("led", 0), # Turn the LED back off - ("zero", 0), # Park after use for next time - ), - "tom" : ( - ("zero", 0), - ("right", 4400), - ("up", 200), - ("fire", 4), - ("zero", 0), - ), - "chris" : ( # That's me - just dance around and missfire! - ("zero", 0), - ("right", 5200), - ("up", 500), - ("pause", 5000), - ("left", 2200), - ("down", 500), - ("fire", 1), - ("zero", 0), - ), -} +json_data = open('./commands.json') +COMMAND_SETS = json.load(json_data) +json_data.close() # # The UDP port to listen to Jenkins events on (events are generated/supplied @@ -259,9 +235,8 @@ def run_command(command, value): def run_command_set(commands): - for cmd, value in commands: - run_command(cmd, value) - + for cmd in commands: + run_command(cmd[0], cmd[1]) def jenkins_target_user(user): match = False From 1a0d5438ce8805c9cf84c06b9400ce0a60f8535f Mon Sep 17 00:00:00 2001 From: Sam Adams Date: Fri, 5 Sep 2014 16:54:02 +0100 Subject: [PATCH 2/5] fixed so the commands json is relative to root --- retaliation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/retaliation.py b/retaliation.py index 6acf086..485cf91 100755 --- a/retaliation.py +++ b/retaliation.py @@ -84,6 +84,7 @@ import usb.util import json +import os ########################## CONFIG ######################### @@ -94,7 +95,8 @@ # is milli-seconds. The number after "fire" denotes the number of rockets # to shoot. # -json_data = open('./commands.json') +curr_dir = os.path.dirname(os.path.realpath(__file__)) +json_data = open(curr_dir + '/commands.json') COMMAND_SETS = json.load(json_data) json_data.close() @@ -157,7 +159,7 @@ def usage(): def setup_usb(): # Tested only with the Cheeky Dream Thunder # and original USB Launcher - global DEVICE + global DEVICE global DEVICE_TYPE DEVICE = usb.core.find(idVendor=0x2123, idProduct=0x1010) @@ -171,7 +173,7 @@ def setup_usb(): else: DEVICE_TYPE = "Thunder" - + # On Linux we need to detach usb HID first if "Linux" == platform.system(): @@ -266,7 +268,7 @@ def read_url(url): def jenkins_get_responsible_user(job_name): # Call back to Jenkins and determin who broke the build. (Hacky) # We do this by crudly parsing the changes on the last failed build - + changes_url = JENKINS_SERVER + "/job/" + job_name + "/lastFailedBuild/changes" changedata = read_url(changes_url) @@ -302,7 +304,7 @@ def jenkins_wait_for_event(): jenkins_target_user(target) except: pass - + def main(args): From ab36a8e762cbe545d315422020d5f625930b2123 Mon Sep 17 00:00:00 2001 From: Shaun Donnelly Date: Mon, 8 Sep 2014 09:50:46 +0100 Subject: [PATCH 3/5] Added doorway setting --- commands.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/commands.json b/commands.json index 8890039..08d105d 100644 --- a/commands.json +++ b/commands.json @@ -22,5 +22,13 @@ ["fire", 1], ["led", 0], ["zero", 0] + ], + "doorway" : [ + ["led", 1], + ["right", 1400], + ["up", 700], + ["fire", 1], + ["led", 0], + ["zero", 0] ] } From 94f6cffed823aabd37357b3793ffda6d3e42f42d Mon Sep 17 00:00:00 2001 From: Shaun Donnelly Date: Mon, 8 Sep 2014 10:00:32 +0100 Subject: [PATCH 4/5] Changed accuracy --- commands.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands.json b/commands.json index 08d105d..7f2e515 100644 --- a/commands.json +++ b/commands.json @@ -23,9 +23,9 @@ ["led", 0], ["zero", 0] ], - "doorway" : [ + "interloper" : [ ["led", 1], - ["right", 1400], + ["right", 1100], ["up", 700], ["fire", 1], ["led", 0], From 9e4b01191fcd031b0d984a4f37a6f75af8fcfc17 Mon Sep 17 00:00:00 2001 From: Sam Adams Date: Mon, 8 Sep 2014 11:13:18 +0100 Subject: [PATCH 5/5] updated so commands file is ignored and original comments are in json (which i know shouldn't be there, but they are useful) --- .gitignore | 1 + README.md | 12 ++++++------ commands-example.json | 28 ++++++++++++++++++++++++++++ commands.json | 34 ---------------------------------- 4 files changed, 35 insertions(+), 40 deletions(-) create mode 100644 .gitignore create mode 100644 commands-example.json delete mode 100644 commands.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..822a4a8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +commands.json \ No newline at end of file diff --git a/README.md b/README.md index 35b4121..ee2261d 100644 --- a/README.md +++ b/README.md @@ -52,12 +52,12 @@ in this video. 2. Download the retaliation.py script onto the system connected to your missile launcher. - 3. Modify your `COMMAND_SETS` in the `retaliation.py` script to define your targeting - commands for each one of your build-braking coders (their user ID as listed - in Jenkins). A command set is an array of move and fire commands. It is recommend - to start each command set with a "zero" command. This parks the launcher in a known - position (bottom-left). You can then use "up" and "right" followed by a time (in - milliseconds) to position your fire. + 3. Copy `commands-example.json` to `commands.json` (removing comments) and use it to + define your targeting commands for each one of your build-braking coders (their user + ID as listed in Jenkins). A command set is an array of move and fire commands. + It is recommend to start each command set with a "zero" command. This parks the + launcher in a known position (bottom-left). You can then use "up" and "right" + followed by a time (in milliseconds) to position your fire. You can test a set by calling retaliation.py with the target name. e.g.: diff --git a/commands-example.json b/commands-example.json new file mode 100644 index 0000000..db24851 --- /dev/null +++ b/commands-example.json @@ -0,0 +1,28 @@ +{ + "will" : [ + ["zero", 0], // Zero/Park to know point (bottom-left) + ["led", 1], // Turn the LED on + ["right", 3250], + ["up", 540], + ["fire", 4], // Fire a full barrage of 4 missiles + ["led", 0], // Turn the LED back off + ["zero", 0] // Park after use for next time + ], + "tom" : [ + ["zero", 0], + ["right", 4400], + ["up", 200], + ["fire", 4], + ["zero", 0] + ], + "chris" : [ // That's me - just dance around and missfire! + ["zero", 0], + ["right", 5200], + ["up", 500], + ["pause", 5000], + ["left", 2200], + ["down", 500], + ["fire", 1], + ["zero", 0] + ] +} \ No newline at end of file diff --git a/commands.json b/commands.json deleted file mode 100644 index 7f2e515..0000000 --- a/commands.json +++ /dev/null @@ -1,34 +0,0 @@ -{ - "ben" : [ - ["led", 1], - ["right", 2100], - ["up", 700], - ["fire", 1], - ["led", 0], - ["zero", 0] - ], - "shaun" : [ - ["led", 1], - ["right", 2450], - ["up", 550], - ["fire", 1], - ["led", 0], - ["zero", 0] - ], - "sam" : [ - ["led", 1], - ["right", 1950], - ["up", 500], - ["fire", 1], - ["led", 0], - ["zero", 0] - ], - "interloper" : [ - ["led", 1], - ["right", 1100], - ["up", 700], - ["fire", 1], - ["led", 0], - ["zero", 0] - ] -}