Compare commits
14
Commits
86820ebfc6
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b84b2e84b | ||
|
|
073f1f3805 | ||
|
|
94f2e8c34e | ||
|
|
be72ed2dfd | ||
|
|
2e4a3e9e07 | ||
|
|
3500e29157 | ||
|
|
6c45e79137 | ||
|
|
da94ed3e15 | ||
|
|
46801a586f | ||
|
|
ccaee0bddd | ||
|
|
7d22bc3b86 | ||
|
|
ea4b383e66 | ||
|
|
a789310c2d | ||
|
|
3ed89ee6dc |
+19
-1
@@ -19,8 +19,26 @@ def order():
|
|||||||
candy3 = int(request.form['candy3'])
|
candy3 = int(request.form['candy3'])
|
||||||
candy4 = int(request.form['candy4'])
|
candy4 = int(request.form['candy4'])
|
||||||
print ("test {} {} {} {} ".format(candy1, candy2, candy3, candy4))
|
print ("test {} {} {} {} ".format(candy1, candy2, candy3, candy4))
|
||||||
|
params = []
|
||||||
|
s = {}
|
||||||
|
s['img_idx'] = 0
|
||||||
|
s['loaded'] = 0
|
||||||
|
s['required'] = candy1
|
||||||
|
test_candy_stat.append(s)
|
||||||
|
s['img_idx'] = 1
|
||||||
|
s['loaded'] = 0
|
||||||
|
s['required'] = candy2
|
||||||
|
test_candy_stat.append(s)
|
||||||
|
s['img_idx'] = 2
|
||||||
|
s['loaded'] = 0
|
||||||
|
s['required'] = candy3
|
||||||
|
test_candy_stat.append(s)
|
||||||
|
s['img_idx'] = 3
|
||||||
|
s['loaded'] = 0
|
||||||
|
s['required'] = candy4
|
||||||
|
test_candy_stat.append(s)
|
||||||
|
s.new_order(params)
|
||||||
return '{"status":"ok"}'
|
return '{"status":"ok"}'
|
||||||
#s.new_order(params)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
+31
-28
@@ -1,36 +1,39 @@
|
|||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
|
||||||
var quantitiy=0;
|
var quantitiy=0;
|
||||||
$('.quantity-right-plus').click(function(e){
|
$('.quantity-right-plus').click(function(e){
|
||||||
|
|
||||||
// Stop acting like a button
|
|
||||||
e.preventDefault();
|
|
||||||
// Get the field name
|
|
||||||
var quantity = parseInt($('#quantity').val());
|
|
||||||
|
|
||||||
// If is not undefined
|
|
||||||
|
|
||||||
$('#quantity').val(quantity + 1);
|
|
||||||
|
|
||||||
|
|
||||||
// Increment
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
$('.quantity-left-minus').click(function(e){
|
|
||||||
// Stop acting like a button
|
|
||||||
e.preventDefault();
|
|
||||||
// Get the field name
|
|
||||||
var quantity = parseInt($('#quantity').val());
|
|
||||||
|
|
||||||
// If is not undefined
|
|
||||||
|
|
||||||
// Increment
|
// Stop acting like a button
|
||||||
if(quantity>0){
|
e.preventDefault();
|
||||||
$('#quantity').val(quantity - 1);
|
// Get the field name
|
||||||
}
|
var quantity = parseInt( $(this).parent().siblings('input').val() ) ;
|
||||||
});
|
|
||||||
|
// If is not undefined
|
||||||
|
|
||||||
|
// $('#quantity').val(quantity + 1);
|
||||||
|
|
||||||
|
$(this).parent().siblings('input').val(quantity + 1)
|
||||||
|
|
||||||
|
|
||||||
|
// Increment
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.quantity-left-minus').click(function(e){
|
||||||
|
// Stop acting like a button
|
||||||
|
e.preventDefault();
|
||||||
|
// Get the field name
|
||||||
|
var quantity = parseInt( $(this).parent().siblings('input').val() ) ;
|
||||||
|
|
||||||
|
// If is not undefined
|
||||||
|
|
||||||
|
// Increment
|
||||||
|
if(quantity>0){
|
||||||
|
$(this).parent().siblings('input').val(quantity - 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function submitOrder(){
|
function submitOrder(){
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>Alepa Twitch Grabs Candy</title>
|
<title>Alepa Twitch Grabs Candy</title>
|
||||||
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
|
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
|
||||||
<script type="text/javascript" src="{{url_for('static', filename='picker.js')}}"></script>
|
<script type="text/javascript" src="{{url_for('static', filename='picker.js')}}"></script>
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h2>Simple Quantity increment buttons with Javascript </h2>
|
<h2>Choose your sweets with a wicked system made out of an awesome humanless deployment process</h2>
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-2">
|
||||||
Tasty treats
|
Tasty treats
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
@@ -84,10 +85,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-2">
|
<div class="col-lg-2 center-block ">
|
||||||
<div class="input-group">
|
<div class="input-group center-block">
|
||||||
<button class="btn btn-magick" onClick="submitOrder()">Place sweet order!</button>
|
<button class="btn btn-magick center-block" onClick="submitOrder()">Place sweet order!</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+27
-26
@@ -4,48 +4,48 @@
|
|||||||
HX711 scale;
|
HX711 scale;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(38400);
|
Serial.begin(115200);
|
||||||
Serial.println("HX711 Demo");
|
//Serial.println("HX711 Demo");
|
||||||
|
|
||||||
Serial.println("Initializing the scale");
|
//Serial.println("Initializing the scale");
|
||||||
// parameter "gain" is ommited; the default value 128 is used by the library
|
// parameter "gain" is ommited; the default value 128 is used by the library
|
||||||
// HX711.DOUT - pin #A1
|
// HX711.DOUT - pin #A1
|
||||||
// HX711.PD_SCK - pin #A0
|
// HX711.PD_SCK - pin #A0
|
||||||
scale.begin(2, 3);
|
scale.begin(2, 3);
|
||||||
|
|
||||||
Serial.println("Before setting up the scale:");
|
//Serial.println("Before setting up the scale:");
|
||||||
Serial.print("read: \t\t");
|
//Serial.print("read: \t\t");
|
||||||
Serial.println(scale.read()); // print a raw reading from the ADC
|
//Serial.println(scale.read()); // print a raw reading from the ADC
|
||||||
|
|
||||||
Serial.print("read average: \t\t");
|
//Serial.print("read average: \t\t");
|
||||||
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
|
//Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
|
||||||
|
|
||||||
Serial.print("get value: \t\t");
|
//Serial.print("get value: \t\t");
|
||||||
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
|
//Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
|
||||||
|
|
||||||
Serial.print("get units: \t\t");
|
//Serial.print("get units: \t\t");
|
||||||
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
|
//Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
|
||||||
// by the SCALE parameter (not set yet)
|
// by the SCALE parameter (not set yet)
|
||||||
|
|
||||||
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
|
scale.set_scale(2280.f); // this value is obtained by calibrating the scale with known weights; see the README for details
|
||||||
scale.tare(); // reset the scale to 0
|
scale.tare(); // reset the scale to 0
|
||||||
|
|
||||||
Serial.println("After setting up the scale:");
|
//Serial.println("After setting up the scale:");
|
||||||
|
|
||||||
Serial.print("read: \t\t");
|
//Serial.print("read: \t\t");
|
||||||
Serial.println(scale.read()); // print a raw reading from the ADC
|
//Serial.println(scale.read()); // print a raw reading from the ADC
|
||||||
|
|
||||||
Serial.print("read average: \t\t");
|
//Serial.print("read average: \t\t");
|
||||||
Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
|
//Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
|
||||||
|
|
||||||
Serial.print("get value: \t\t");
|
//Serial.print("get value: \t\t");
|
||||||
Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
|
//Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
|
||||||
|
|
||||||
Serial.print("get units: \t\t");
|
//Serial.print("get units: \t\t");
|
||||||
Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
|
//Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
|
||||||
// by the SCALE parameter set with set_scale
|
// by the SCALE parameter set with set_scale
|
||||||
|
|
||||||
Serial.println("Readings:");
|
//Serial.println("Readings:");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -53,10 +53,11 @@ void loop() {
|
|||||||
//Serial.print(scale.get_units(), 1);
|
//Serial.print(scale.get_units(), 1);
|
||||||
//Serial.print("\t| average:\t");
|
//Serial.print("\t| average:\t");
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 0) {
|
||||||
Serial.println(scale.get_units(10), 1);
|
Serial.read();
|
||||||
|
Serial.println(scale.get_units(), 1);
|
||||||
|
|
||||||
scale.power_down(); // put the ADC in sleep mode
|
//scale.power_down(); // put the ADC in sleep mode
|
||||||
delay(100);
|
//delay(100);
|
||||||
scale.power_up();
|
//scale.power_up();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 273 KiB After Width: | Height: | Size: 44 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 281 KiB After Width: | Height: | Size: 30 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 273 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 281 KiB |
+90
-33
@@ -1,10 +1,12 @@
|
|||||||
import cv2
|
import cv2
|
||||||
import time
|
import time
|
||||||
|
import serial
|
||||||
from xmlrpc.server import SimpleXMLRPCServer
|
from xmlrpc.server import SimpleXMLRPCServer
|
||||||
from xmlrpc.server import SimpleXMLRPCRequestHandler
|
from xmlrpc.server import SimpleXMLRPCRequestHandler
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
cap = cv2.VideoCapture(0)
|
cap = cv2.VideoCapture(-1)
|
||||||
font = cv2.FONT_HERSHEY_SIMPLEX
|
font = cv2.FONT_HERSHEY_SIMPLEX
|
||||||
list_img = cv2.imread('list.jpg')
|
list_img = cv2.imread('list.jpg')
|
||||||
list_img = cv2.resize(list_img,None,fx=0.8, fy=0.8, interpolation = cv2.INTER_CUBIC)
|
list_img = cv2.resize(list_img,None,fx=0.8, fy=0.8, interpolation = cv2.INTER_CUBIC)
|
||||||
@@ -28,30 +30,41 @@ IMG_H = 720
|
|||||||
rect_w = 220
|
rect_w = 220
|
||||||
rect_h = 52
|
rect_h = 52
|
||||||
|
|
||||||
test_candy_stat = []
|
weights_list = [37.0, 4.8, 8.8, 2.5]
|
||||||
s = {}
|
|
||||||
s['img_idx'] = 0
|
ARDUPORT = 'COM12'
|
||||||
s['loaded'] = 0
|
serial = serial.Serial(ARDUPORT, 115200, timeout=1)
|
||||||
s['required'] = 4
|
|
||||||
test_candy_stat.append(s)
|
candy_stat = []
|
||||||
s = {}
|
# s = {}
|
||||||
s['img_idx'] = 1
|
# s['img_idx'] = 0
|
||||||
s['loaded'] = 2
|
# s['loaded'] = 0
|
||||||
s['required'] = 2
|
# s['required'] = 4
|
||||||
test_candy_stat.append(s)
|
# candy_stat.append(s)
|
||||||
s = {}
|
# s = {}
|
||||||
s['img_idx'] = 2
|
# s['img_idx'] = 1
|
||||||
s['loaded'] = 1
|
# s['loaded'] = 0
|
||||||
s['required'] = 6
|
# s['required'] = 2
|
||||||
test_candy_stat.append(s)
|
# candy_stat.append(s)
|
||||||
s = {}
|
# s = {}
|
||||||
s['img_idx'] = 3
|
# s['img_idx'] = 2
|
||||||
s['loaded'] = 6
|
# s['loaded'] = 0
|
||||||
s['required'] = 9
|
# s['required'] = 6
|
||||||
test_candy_stat.append(s)
|
# candy_stat.append(s)
|
||||||
|
# s = {}
|
||||||
|
# s['img_idx'] = 3
|
||||||
|
# s['loaded'] = 0
|
||||||
|
# s['required'] = 9
|
||||||
|
# candy_stat.append(s)
|
||||||
|
|
||||||
|
previous_weight = 0
|
||||||
|
|
||||||
def new_order(params):
|
def new_order(params):
|
||||||
pass
|
global candy_stat
|
||||||
|
print ('Got order ')
|
||||||
|
print(params)
|
||||||
|
candy_stat = params
|
||||||
|
return True
|
||||||
|
|
||||||
def async_server_megahack(server):
|
def async_server_megahack(server):
|
||||||
server.serve_forever()
|
server.serve_forever()
|
||||||
@@ -60,6 +73,33 @@ def async_server_megahack(server):
|
|||||||
class RequestHandler(SimpleXMLRPCRequestHandler):
|
class RequestHandler(SimpleXMLRPCRequestHandler):
|
||||||
rpc_paths = ('/RPC2',)
|
rpc_paths = ('/RPC2',)
|
||||||
|
|
||||||
|
def check_endgame(params):
|
||||||
|
for s in candy_stat:
|
||||||
|
if s['required'] != s['loaded']:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
def is_equal_with_tolerance(v1, v2, t):
|
||||||
|
return (v2 * (1-t) < v1) and (v2 * (1+t) > v1)
|
||||||
|
|
||||||
|
did_change = False
|
||||||
|
def check_weights(params, new_weight):
|
||||||
|
global previous_weight, did_change
|
||||||
|
weight_diff = new_weight - previous_weight
|
||||||
|
if weight_diff < 0.3:
|
||||||
|
return
|
||||||
|
elif not did_change:
|
||||||
|
did_change = True
|
||||||
|
else:
|
||||||
|
for i in range(4):
|
||||||
|
if is_equal_with_tolerance(weight_diff, weights_list[i], 0.1):
|
||||||
|
params[i]['loaded'] += 1
|
||||||
|
previous_weight = new_weight
|
||||||
|
did_change = False
|
||||||
|
break
|
||||||
|
if did_change:
|
||||||
|
did_change = False
|
||||||
|
previous_weight = new_weight
|
||||||
|
|
||||||
def draw_rectangles(img, n):
|
def draw_rectangles(img, n):
|
||||||
for i in range(n):
|
for i in range(n):
|
||||||
cv2.rectangle(img, (IMG_W - 5 - rect_w,5 + (rect_h + 5)*i), (IMG_W - 5, 5 + (rect_h + 5)*i + rect_h), (255, 255, 255), -1)
|
cv2.rectangle(img, (IMG_W - 5 - rect_w,5 + (rect_h + 5)*i), (IMG_W - 5, 5 + (rect_h + 5)*i + rect_h), (255, 255, 255), -1)
|
||||||
@@ -68,9 +108,9 @@ def print_stats(img, stats):
|
|||||||
# draw_rectangles(img, len(stats))
|
# draw_rectangles(img, len(stats))
|
||||||
img[0:list_img.shape[0], IMG_W-list_img.shape[1]:IMG_W, :] = list_img[:]
|
img[0:list_img.shape[0], IMG_W-list_img.shape[1]:IMG_W, :] = list_img[:]
|
||||||
for i in range(len(stats)):
|
for i in range(len(stats)):
|
||||||
cv2.putText(frame,str(stats[i]['loaded']),(IMG_W - 130,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
cv2.putText(img,str(stats[i]['loaded']),(IMG_W - 130,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
||||||
cv2.putText(frame,"/",(IMG_W - 90,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
cv2.putText(img,"/",(IMG_W - 90,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
||||||
cv2.putText(frame,str(stats[i]['required']),(IMG_W - 50,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
cv2.putText(img,str(stats[i]['required']),(IMG_W - 50,188 + i * (rect_h + 5)), font, 1.3,(0, 0, 0),2,cv2.LINE_AA)
|
||||||
img[150+(rect_h + 5)*i:150+(rect_h + 5)*i + target_w, IMG_W-130-target_w-20:IMG_W-130-20, :] = img_list[stats[i]['img_idx']][:]
|
img[150+(rect_h + 5)*i:150+(rect_h + 5)*i + target_w, IMG_W-130-target_w-20:IMG_W-130-20, :] = img_list[stats[i]['img_idx']][:]
|
||||||
|
|
||||||
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
|
cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
|
||||||
@@ -79,19 +119,36 @@ with SimpleXMLRPCServer(('localhost', 8000),
|
|||||||
requestHandler=RequestHandler) as server:
|
requestHandler=RequestHandler) as server:
|
||||||
server.register_introspection_functions()
|
server.register_introspection_functions()
|
||||||
|
|
||||||
# Register pow() function; this will use the value of
|
|
||||||
# pow.__name__ as the name, which is just 'pow'.
|
|
||||||
server.register_function(new_order)
|
server.register_function(new_order)
|
||||||
|
|
||||||
# Run the server's main loop
|
|
||||||
t = Thread(target=async_server_megahack, args=(server,))
|
t = Thread(target=async_server_megahack, args=(server,))
|
||||||
t.start()
|
t.start()
|
||||||
|
# serial.write(b'e')
|
||||||
|
# line = serial.readline()[:-2]
|
||||||
|
# print (line)
|
||||||
|
# weight = -float(line)
|
||||||
|
# previous_weight = weight
|
||||||
|
frame_counter = 0
|
||||||
|
weight = 0
|
||||||
|
canvas = np.zeros((720, 1280, 3)).astype(np.uint8)
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
frame_counter += 1
|
||||||
|
if frame_counter == 75:
|
||||||
|
serial.write(b'e')
|
||||||
|
weight = -float(serial.readline()[:-2])
|
||||||
|
frame_counter = 0
|
||||||
|
print(weight)
|
||||||
|
check_weights(candy_stat, weight)
|
||||||
|
if check_endgame(candy_stat):
|
||||||
|
candy_stat = []
|
||||||
|
# TODO: do funny gif
|
||||||
ret, frame = cap.read()
|
ret, frame = cap.read()
|
||||||
frame = cv2.resize(frame,None,fx=2, fy=1.5, interpolation = cv2.INTER_CUBIC)
|
frame = cv2.resize(frame,None,fx=1.5, fy=1.5, interpolation = cv2.INTER_CUBIC)
|
||||||
print_stats(frame, test_candy_stat)
|
canvas[0:720, 0:960, :] = frame[:]
|
||||||
print(frame.shape)
|
if (len(candy_stat) > 0):
|
||||||
cv2.imshow("window", frame)
|
print_stats(canvas, candy_stat)
|
||||||
|
cv2.imshow("window", canvas)
|
||||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user