-
Notifications
You must be signed in to change notification settings - Fork 0
/
wemos.py
85 lines (73 loc) · 2.98 KB
/
wemos.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
from typing import Tuple
from machine import *
from tkinter import *
from tkinter.tix import *
class Visu_led:
def __init__(self, canvas: Canvas, x: int, y: int, largeur: int, hauteur: int):
self.canvas = canvas
self.x = x
self.y = y
self.largeur = largeur
self.hauteur = hauteur
self.led = None
self.states_color = ['green', 'lawn green', 'gray']
self.add_canavas()
def add_canavas(self):
self.led = self.canvas.create_rectangle(self.x, self.y, self.x + self.largeur, self.y + self.hauteur,
fill='gray')
def set_Color(self, couleur: Tuple[str, str, str]):
self.states_color = list(couleur)
def out(self, niveau: int):
self.canvas.itemconfig(self.led, fill=self.states_color[niveau])
class BoardLed(Visu_led):
def __init__(self, canvas: Canvas, x: int, y: int, largeur: int, hauteur: int):
super().__init__(canvas, x, y, largeur, hauteur)
self.set_Color(('gray', '#068FFB', 'gray'))
class Wemos:
pins = [16, 5, 4, 0, 2, 14, 12, 13, 15, 13, 12, 14, 4, 5, 14]
def __init__(self, canevas: Canvas):
self.canevas = canevas
self.leds: List[Visu_led] = [Visu_led(canevas, 324 - i * 14, 7, 10, 10) for i in range(6)]
self.leds += [Visu_led(canevas, 314 - i * 14, 7, 10, 10) for i in range(6, 16) if i not in [12, 13]]
self.leds += [BoardLed(canevas, 183, 179, 10, 5)]
self.leds_board = [BoardLed(canevas, 183, 145, 10, 5), BoardLed(canevas, 343, 201, 5, 10)]
self.tip = Balloon(self.canevas)
self.tip.bind(self.leds[0].led, balloonmsg='bonjour')
# for i,t in enumerate(self.tips):
# t.bindtags(self.leds[i].led, balloonmsg='boujour')
def add_canevas(self):
for l in self.leds:
l.add_canavas()
def d_to_pin(pin: str):
if pin[0].upper() == "D":
try:
return Wemos.pins[int(pin[1:])]
except:
raise ValueError
def refresh(self):
for i, p in enumerate(self.pins):
valeur = Board.value_By_pin(p)
if valeur == 2 or not Board.run:
self.leds[i].out(2)
else:
self.leds[i].out(valeur)
if Board.run:
self.leds_board[0].out(1)
else:
self.leds_board[0].out(0)
if Board.wifi:
self.leds_board[1].out(1)
else:
self.leds_board[1].out(0)
for pwm in Board.pwm_chanel:
if pwm.maxi > self.canevas.master.pwm.pwm_counter:
pwm.pin.on()
else:
pwm.pin.off()
if len(Board.pwm_chanel) > 0 and self.canevas.master.servo is not None:
self.canevas.master.servo.inspect(True)
def toggle_entry(self, id_pin: int):
index = Board.search_pin(Board.gpio, id_pin)
if index != -1:
if Board.gpio[index].mode() == Pin.IN:
Board.gpio[index].toggle()