commit deb8b3b4a877ebbfdb02642b490609001eb6b91f Author: Eljakim Herrewijnen (DBS) Date: Sun Jul 3 17:08:00 2022 +0200 Initial commit diff --git a/__pycache__/control_usb.cpython-38.pyc b/__pycache__/control_usb.cpython-38.pyc new file mode 100644 index 0000000..7b0a9b5 Binary files /dev/null and b/__pycache__/control_usb.cpython-38.pyc differ 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()