From deb8b3b4a877ebbfdb02642b490609001eb6b91f Mon Sep 17 00:00:00 2001 From: "Eljakim Herrewijnen (DBS)" Date: Sun, 3 Jul 2022 17:08:00 +0200 Subject: [PATCH] Initial commit --- __pycache__/control_usb.cpython-38.pyc | Bin 0 -> 1913 bytes control_usb.py | 38 ++++++++++++++ static/main.css | 30 +++++++++++ static/scripts.js | 67 +++++++++++++++++++++++++ templates/index.html | 47 +++++++++++++++++ webserver.py | 47 +++++++++++++++++ 6 files changed, 229 insertions(+) create mode 100644 __pycache__/control_usb.cpython-38.pyc create mode 100644 control_usb.py create mode 100644 static/main.css create mode 100644 static/scripts.js create mode 100644 templates/index.html create mode 100644 webserver.py diff --git a/__pycache__/control_usb.cpython-38.pyc b/__pycache__/control_usb.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b0a9b5e9df533c0045b005e13de2543477ea299 GIT binary patch literal 1913 zcmcIl&2H2%5VrHP>u$TH{DVNK2oChpJtHAhi2@h2LO?;v#Y!{Y*4=DU#tsO?iE`x~ z=&=&dzzgsOxpLZ9;KWR}E4HGjaHylqc;boY%jcQNMz`A$G`@fPx~U@}ey}k+LNeCq zb}T@E%tbQMGLelPBtfIYBzi0$fbf%ma4$$=(}HLi;5`%XiKGqkxmbzEw2SCxEN4eR z#v0vjorDp*GwmuN_#~1LLWoF55JQV}3~f-PTQCP5(ruWB1=0$-ut<6i&QPSKy1U^v zAC!g1GS3ZWl6IaBp3}#Q2XwnW2`_f!P7@Hq&%p2+eZ-X$&Zqse2F36 zm(Zf;YmMDvTZ(4h-WQUnq2TSly>(LvyR;<4N{}cEFHHd@CUX{^VhL5|-=BYyRz
amE78=^z!p%4VBXZ7muX&^hlsS(W$X0NU}16%Xx|vr zY34~M7r^*5+djIOoOQ=6n*vd-Du^wv#$pEAs>OJYM8n^hlj$J97OAA0 zdCaxPv~UB1sMv`=cOvF#Rx4j28o#l7hAhV~i$5?=UH%huJjKg;26L;AT?&Kz#SLcU z*ke9@q?8fI;_OU7te0<#bL2BcdgUm)znxAOE0@oSSf7}IzjzW>b~;_G&8h#D*ZB!$ z&+OK=zcK^%>T$$2UZ;z8`CpiQ?#tb4GhmO+0(LrGtPQDuW%e**A6YavPQuDg{gn>) zk|G@$t?Q1~BWjg7&lj|QU8VVC1-ZlESr+G6aE9S!7FSs?Ei*OVR67?sa%po@a9nmu zDy72d)vR&sQECgVsRIY4t3&tB)seR&lPGR=+>eoeh>bg5r&%3T?zmvJx;FuTpNo1L OkvgIZ7OyMW3Vs0r5RuUU literal 0 HcmV?d00001 diff --git a/control_usb.py b/control_usb.py new file mode 100644 index 0000000..d377ef5 --- /dev/null +++ b/control_usb.py @@ -0,0 +1,38 @@ +import os +import sys +import time +import usb.core + +class UsbController(): + 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 turretUp(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x02,0x00,0x00,0x00,0x00,0x00,0x00]) + + def turretDown(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00]) + + def turretLeft(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x04,0x00,0x00,0x00,0x00,0x00,0x00]) + + def turretRight(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x08,0x00,0x00,0x00,0x00,0x00,0x00]) + + def turretStop(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x20,0x00,0x00,0x00,0x00,0x00,0x00]) + + def turretFire(self): + self.dev.ctrl_transfer(0x21,0x09,0,0,[0x02,0x10,0x00,0x00,0x00,0x00,0x00,0x00]) + + +if __name__ == '__main__': + us = UsbController() + if 1: + pass + diff --git a/static/main.css b/static/main.css new file mode 100644 index 0000000..f628eba --- /dev/null +++ b/static/main.css @@ -0,0 +1,30 @@ + +.grid-container { + display: grid; + gap: 1px; + grid-template-columns: repeat(3, 1fr); + } + +.fire_button { + padding: 10px; + background-color: #ccc; + padding: 2%; + margin: 1%; + background-color: gray; +} + +.fire_button:hover{ + background-color: red; +} + +.turret_button{ + padding: 10px; + background-color: #ccc; + padding: 2%; + margin: 1%; + background-color: #808080; +} + +.turret_button:hover{ + background-color: green; +} \ No newline at end of file diff --git a/static/scripts.js b/static/scripts.js new file mode 100644 index 0000000..7bcf7bc --- /dev/null +++ b/static/scripts.js @@ -0,0 +1,67 @@ +function Fire() { + $.ajax({ + type: "GET", + url: "/fire", + success: function(results) { + console.log("ok!") + }, + error: function(error) { + console.log(error) + } + }); +} + +function Up() { + $.ajax({ + type: "GET", + url: "/up", + success: function(results) { + console.log("ok!") + }, + error: function(error) { + console.log(error) + } + }); + } +function Down() { + $.ajax({ + type: "GET", + url: "/down", + success: function(results) { + console.log("ok!") + }, + error: function(error) { + console.log(error) + } + }); + } + +function Left() { + $.ajax({ + type: "GET", + url: "/left", + success: function(results) { + console.log("ok!") + }, + error: function(error) { + console.log(error) + } + }); + } + +function Right() { + $.ajax({ + type: "GET", + url: "/right", + success: function(results) { + console.log("ok!") + }, + error: function(error) { + console.log(error) + } + }); + } + +window.onload = function() { + +}; \ No newline at end of file diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..c7499f4 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,47 @@ + + + + + + + Deur bewaker + + + + + + + + + + + + + +
+

Deurbewaking

+
+ +
+
+
Up
+
+
Left
+
Fire
+
Right
+
+
Down
+
+
+ + + + + \ No newline at end of file diff --git a/webserver.py b/webserver.py new file mode 100644 index 0000000..4963730 --- /dev/null +++ b/webserver.py @@ -0,0 +1,47 @@ +from control_usb import UsbController +from flask import Flask, render_template +import time +WAIT_TIME = .4 + +app = Flask(__name__) +dev = UsbController() + +@app.route('/') +def index(): + return render_template('index.html') + +@app.route('/fire') +def fire(): + dev.turretFire() + return "Fired" + +@app.route('/up') +def up(): + dev.turretUp() + time.sleep(WAIT_TIME) + dev.turretStop() + return "Up" + +@app.route('/down') +def down(): + dev.turretDown() + time.sleep(WAIT_TIME) + dev.turretStop() + return "Down" + +@app.route('/left') +def left(): + dev.turretLeft() + time.sleep(WAIT_TIME) + dev.turretStop() + return "Left" + +@app.route('/right') +def right(): + dev.turretRight() + time.sleep(WAIT_TIME) + dev.turretStop() + return "Right" + +if __name__ == "__main__": + app.run()