Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ It also requires that you run it as root unless you want to spend an afternoon p

* Use arrow keys aim.
* Press return to fire.

## Controlling from the terminal:

cd stormLauncher
chmod +x turret.py
sudo ./turret.py <"left" | "right" | "up" | "down" | "fire"> <duration of movement in milliseconds>

* If the first argument equals "fire", second argument is completely optional.
101 changes: 101 additions & 0 deletions turret.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/python

import os
import sys
import time
import pygame
import usb.core

cmdargs = []
initialTime = 0

class launchControl():
def __init__(self):
self.dev = usb.core.find(idVendor=0x2123, idProduct=0x1010)
if self.dev is None:
raise ValueError('Launcher not found.')
if self.dev.is_kernel_driver_active(0) is True:
self.dev.detach_kernel_driver(0)
self.dev.set_configuration()

def loopMovement(self, movement):
while (True):
if (time.time() - initialTime) > movement:
self.turretStop()
break

def turretUp(self, movement):
print("Turret Up.")
self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

self.loopMovement(movement)

def turretDown(self, movement = 1000):
print("Turret Down.")
self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

self.loopMovement(movement)

def turretLeft(self, movement):
print("Turret Left.")
self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

self.loopMovement(movement)

def turretRight(self, movement):
print("Turret Right.")
self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

self.loopMovement(movement)

def turretStop(self):
print("Turret Stop.")
self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])

def turretFire(self):
print("FIRE!")

self.dev.ctrl_transfer(0x21, 0x09, 0, 0, [0x02, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])


def commandControl(cmdargs):

# Get the total number of args passed to the turret.py
total = len(cmdargs)

if total >= 2 and str.lower(cmdargs[1]) == "fire":
launchControl().turretFire()
return

if total < 3:
print("sudo ./turret.py <\"left\" | \"right\" | \"up\" | \"down\"> <duration of movement in milliseconds>")
return

command = str.lower(cmdargs[1])

movement = int(cmdargs[2]) / 1000.0

global initialTime
initialTime = time.time();

if command == "left":
launchControl().turretLeft(movement)

if command == "right":
launchControl().turretRight(movement)

if command == "up":
launchControl().turretUp(movement)

if command == "down":
launchControl().turretDown(movement)

if __name__ == '__main__':

if not os.geteuid() == 0:
sys.exit("Script must be run as root.")

# Get the arguments list
cmdargs = sys.argv

commandControl(cmdargs)