Renamed variables to be "pylint compatibles" and translated in english

This commit is contained in:
Pierrick C 2018-11-18 16:34:00 +01:00
parent 84c85d11c3
commit 0a30d6ed74
1 changed files with 44 additions and 39 deletions

View File

@ -29,40 +29,40 @@ from encoder import Encoder
#Paramètres
NB_PIX = 8 # Nombre de pixels
MAX_LUM = 100 # Luminosité max (100 max.)
COULEUR = [255, 255, 255] # Couleur de base (à luminosité max)
MAX_BRIGHT = 100 # Luminosité max (100 max.)
COLOR = [255, 255, 255] # Couleur de base (à luminosité max)
#Déclaration des objets et initialisation des variables
board_type = uname()[0]
print("Système :", board_type)
BRD_TYPE = uname()[0]
print("Système :", BRD_TYPE)
if board_type == 'esp8266':
if BRD_TYPE == 'esp8266':
NEOPIX_PIN = 2
# Les deux broches suivantes doivent être capable d'interruption !!!
# sur ESP8266 => : 4, 5, 12, 13 et 14
ENC_PIN_A = 13 # N° de la 1ere broche de l'encodeur
ENC_PIN_B = 12 # N° de la 2e broche de l'encodeur
ENC_BOUTON = 14 # broche du clic central de l'encodeur
ENC_PIN_C = 14 # broche du clic central de l'encodeur
# With ESP8266 (no timing parameter)
pixel_strip = neopixel.NeoPixel(machine.Pin(NEOPIX_PIN), NB_PIX)
NPXL_STRIP = neopixel.NeoPixel(machine.Pin(NEOPIX_PIN), NB_PIX)
elif board_type == 'esp32':
elif BRD_TYPE == 'esp32':
NEOPIX_PIN = 14
# Pins
ENC_PIN_A = 15 # N° de la 1ere broche de l'encodeur
ENC_PIN_B = 33 # N° de la 2e broche de l'encodeur
ENC_BOUTON = 27 # broche du clic central de l'encodeur
ENC_PIN_C = 27 # broche du clic central de l'encodeur
# # Only with ESP32 : add timing param.
# # timing param =0 for "old" 400kHz neopixel (default)
# # =1 for "new" 800kHz neopixel
pixel_strip = neopixel.NeoPixel(machine.Pin(NEOPIX_PIN), NB_PIX, timing=1)
NPXL_STRIP = neopixel.NeoPixel(machine.Pin(NEOPIX_PIN), NB_PIX, timing=1)
else:
# ce code n'est pas prévu pour d'autre carte pour l'instant
print("Carte non-supportée")
print("Carte non-supportée :", BRD_TYPE)
quit()
# # Only with ESP32 : add timing param.
@ -72,63 +72,68 @@ else:
# coul_tmp = [0, 0, 0]
#Eteint tout à l'initialisation
pixel_strip.fill([0, 0, 0])
pixel_strip.write()
NPXL_STRIP.fill([0, 0, 0])
NPXL_STRIP.write()
# Encodeur rotatif
enc = Encoder(ENC_PIN_B, ENC_PIN_A,
min_val=0, max_val=MAX_LUM,
clicks=1)
ENCODER = Encoder(ENC_PIN_B, ENC_PIN_A,
min_val=0, max_val=MAX_BRIGHT,
clicks=1)
#Bouton
bout = machine.Pin(ENC_BOUTON, machine.Pin.IN)
ENC_BUT = machine.Pin(ENC_PIN_C, machine.Pin.IN)
#Variable d'état
LUM = 0 # Luminosité (0 - 100)
PWR = False # Est-ce que l'éclairage est allumé ?
BOUT_PRESS_STATE = 1
#Variables d'état
BRIGHTN = 0 # Luminosité (0 - 100)
PWR = False # Est-ce que l'éclairage est allumé ?
BUTTN_STATE = 1
def update_neopixel(np_strp, coul, lum=50):
def update_neopixel(np_strp, col, bri=50):
"""Update NeoPixel strip with one color
:param np_strp : NeoPixel object
:param coul : color [R, G, B]
:param lum : brightness 0-100 (default: 50)
:param col : color [R, G, B]
:param bri : brightness 0-100 (default: 50)
"""
col_tmp = [0, 0, 0]
for i in range(3):
col_tmp[i] = int(coul[i] * lum / 100)
col_tmp[i] = int(col[i] * bri / 100)
pixel_strip.fill(col_tmp)
pixel_strip.write()
np_strp.fill(col_tmp)
np_strp.write()
#####################
# BOUCLE PRINCIPALE #
#####################
while True:
# Si on a un changement de valeur, on met à jour la luminisité et l'éclairage
# des NeoPixel
if PWR and LUM != enc.value:
print(enc.value)
LUM = enc.value
update_neopixel(pixel_strip, COULEUR, LUM)
if PWR and BRIGHTN != ENCODER.value:
print(ENCODER.value)
BRIGHTN = ENCODER.value
update_neopixel(NPXL_STRIP, COLOR, BRIGHTN)
# Quand le bouton central est appuyé puis relâché, on allume ou on éteint
if bout.value() == 0 and BOUT_PRESS_STATE == 1:
if ENC_BUT.value() == 0 and BUTTN_STATE == 1:
PWR = not PWR
print("Power :", PWR)
if not PWR:
# Extinction des LED
pixel_strip.fill((0, 0, 0))
pixel_strip.write()
NPXL_STRIP.fill((0, 0, 0))
NPXL_STRIP.write()
else:
# Luminité basse si on allume avec une luminisité de 0
if LUM == 0:
LUM = 10
if BRIGHTN == 0:
BRIGHTN = 10
# On remet l'encodeur à la dernière luminosité connue
# pour ignorer les mouvements pendant l'extinction
enc.reset(LUM)
update_neopixel(pixel_strip, COULEUR, LUM)
ENCODER.reset(BRIGHTN)
# Rallume les LED:
update_neopixel(NPXL_STRIP, COLOR, BRIGHTN)
BOUT_PRESS_STATE = bout.value()
BUTTN_STATE = ENC_BUT.value()
time.sleep_ms(20)