-
Notifications
You must be signed in to change notification settings - Fork 2
/
button.py
executable file
·106 lines (80 loc) · 3.26 KB
/
button.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
import argparse
import configparser
import board
import digitalio
import adafruit_character_lcd.character_lcd as characterlcd
from pyunifi.controller import Controller
from gpiozero import Button
from signal import pause
lcd_rs = digitalio.DigitalInOut(board.D26)
lcd_en = digitalio.DigitalInOut(board.D19)
lcd_d7 = digitalio.DigitalInOut(board.D27)
lcd_d6 = digitalio.DigitalInOut(board.D22)
lcd_d5 = digitalio.DigitalInOut(board.D24)
lcd_d4 = digitalio.DigitalInOut(board.D25)
lcd_columns = 16
lcd_rows = 2
lcd = characterlcd.Character_LCD_Mono(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns, lcd_rows)
button2 = Button(2)
button3 = Button(3)
button4 = Button(4)
config = configparser.ConfigParser()
config.read('config.ini')
controller = config.get('config', 'controller')
username = config.get('config', 'username')
password = config.get('config', 'password')
port = config.get('config', 'port')
version = config.get('config', 'version')
siteid = config.get('config', 'siteid')
nosslverify = config.get('config', 'nosslverify')
certificate = config.get('config', 'certificate')
parser = argparse.ArgumentParser()
parser.add_argument('-c', '--controller', default=controller)
parser.add_argument('-u', '--username', default=username)
parser.add_argument('-p', '--password', default=password)
parser.add_argument('-b', '--port', default=port)
parser.add_argument('-v', '--version', default=version)
parser.add_argument('-s', '--siteid', default=siteid)
parser.add_argument('-V', '--no-ssl-verify', default=nosslverify, action='store_true')
parser.add_argument('-C', '--certificate', default=certificate)
args = parser.parse_args()
ssl_verify = (not args.no_ssl_verify)
if ssl_verify and len(args.certificate) > 0:
ssl_verify = args.certificate
c = Controller(args.controller, args.username, args.password, args.port, args.version, args.siteid, ssl_verify=ssl_verify)
lcd.message = 'Press button to\ngenerate voucher'
def generate_guest():
voucher = c.create_voucher(1, 1, 480, note="unipi guest")
code = voucher[0].get('code')
def format_code(string):
length_string = len(string)
first_length = round(length_string / 2)
first_half = string[0:first_length].lower()
second_half = string[first_length:].upper()
return first_half + '-' + second_half
voucher_code = format_code(code)
print(voucher_code)
lcd.clear()
lcd.message = 'Guest voucher\n{}'.format(voucher_code)
def generate_customer():
voucher = c.create_voucher(1, 1, 5, up_bandwidth=512, down_bandwidth=512, byte_quota=1024, note="unipi customer")
code = voucher[0].get('code')
def format_code(string):
length_string = len(string)
first_length = round(length_string / 2)
first_half = string[0:first_length].lower()
second_half = string[first_length:].upper()
return first_half + '-' + second_half
voucher_code = format_code(code)
print(voucher_code)
lcd.clear()
lcd.message = 'Customer voucher\n{}'.format(voucher_code)
def generate_clear():
if button4.is_pressed:
lcd.clear()
lcd.message = 'Press button to\ngenerate voucher'
button2.when_pressed = generate_guest
button3.when_pressed = generate_customer
button4.when_pressed = generate_clear
pause()