Initial commit

This commit is contained in:
Eljakim Herrewijnen (DBS) 2022-07-03 17:08:00 +02:00
commit deb8b3b4a8
6 changed files with 229 additions and 0 deletions

Binary file not shown.

38
control_usb.py Normal file
View File

@ -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

30
static/main.css Normal file
View File

@ -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;
}

67
static/scripts.js Normal file
View File

@ -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() {
};

47
templates/index.html Normal file
View File

@ -0,0 +1,47 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Deur bewaker</title>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Almarai:wght@800&amp;family=Nunito+Sans&amp;display=swap" />
<!-- <link rel="stylesheet" src="/static/main.css"/> -->
<link rel="stylesheet" href="/static/main.css">
<script type="text/javascript" src="https://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="/static/scripts.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
</head>
<body>
<div class="title_header">
<h1>Deurbewaking</h1>
</div>
<div class="grid-container">
<div class="grid-item"></div>
<div class="turret_button" onclick="Up()">Up</div>
<div class="grid-item"></div>
<div class="turret_button" onclick="Left()">Left</div>
<div class="fire_button" onclick="Fire()">Fire</div>
<div class="turret_button" onclick="Right()">Right</div>
<div class="grid-item"></div>
<div class="turret_button" onclick="Down()">Down</div>
<div class="grid-item"></div>
</div>
<!-- <div class="default_container">
<div class="turret_button" onclick="Up()">Up</div>
<div class="turret_button" onclick="Left()">Left</div>
<div class="fire_button" onclick="Fire()">Fire</div>
<div class="turret_button" onclick="Right()">Right</div>
<div class="turret_button" onclick="Down()">Down</div>
</div> -->
</body>
</html>

47
webserver.py Normal file
View File

@ -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()