#Ecran ili9341 Touch IRQ simulé
#
# Pilotage motoconvecteur
# si T° du motoconvecteur < T° pièce arrêter la turbine
# le relai turbine est simulé par la diode blue
# la diode verte allumée la turbine tourne
# la diode rouge clignote si le programme tourne
# simulé sur WorWI sur un esp32-devkit-v1
# la simu ne marche pas pour l'ecran tactile
# d'ou les 3 poussoirs
import gc
print("Mémoire libre :", gc.mem_free(), "octets")
import machine, onewire, ds18x20, time, binascii
from machine import Pin, SPI, Timer
timer_0 = Timer(0)
from ili9341new import ILI9341
from xpt2046 import Touch
import ESP32
from ESP32 import *
import ZonesTactiles
from ZonesTactiles import *
import random
#fontes____________________________
import glcdfont
import tt14
import tt24
import tt32
fonts = [glcdfont, tt14, tt24, tt32]
from couleursdebase import *
def afficher_bouton (x, y, wb, hb, color1, color2, texte, dxt , dyt, font):
ecran.set_font(font)
ecran.fill_rectangle(x, y, wb, hb, color=color2)
ecran.set_color(color1,color2)
ecran.set_pos(x+dxt,y+dyt)
ecran.print(texte)
def afficherB1_ON():
global etatB1
afficher_bouton (xB1, yB1, wB1, hB1, noir, pourpre, "", 0 , 0, tt24)
etatB1=True
def afficherB2_OFF():
global etatB2
afficher_bouton (xB2, yB2, wB2, hB2, grisF, grisC, "", 0 , 0, tt24)
etatB2=False
temp_pièce=20.1
temp_motoconvecteur=26.7
# INIT ECRAN ili9341
power = Pin(ILI_LED_PIN, Pin.OUT)
power.value(1) # obligatoire sur certains modele
#---------------------------------------------
cs_pin=Pin(ILI_CS_PIN,Pin.OUT)
cs_pin.on()
cs_pinTouch=Pin(ILI_CS_PINTouch,Pin.OUT)
irq_pinTouch=Pin(ILI_IRQ_PINTouch,Pin.IN)
cs_pinTouch.on()
spi = SPI(2,
baudrate=40000000,
miso=Pin(ILI_MISO_PIN),
mosi=Pin(ILI_MOSI_PIN),
sck=Pin(ILI_CLK_PIN)
)
ecran = ILI9341(
spi,
cs=Pin(ILI_CS_PIN),
dc=Pin(ILI_DC_PIN),
rst=Pin(ILI_RST_PIN),
w=ILI_largeur,
h=ILI_hauteur,
r=ILI_rotation
)
# capteur tactile
interruption_a_traiter = False
# Fonction de rappel (Callback) pour l'interruption
#print("___FIN DES DEFINITIONS des routines--debut boucle____")
#ecran.set_color(blanc,cyan)
#ecran.erase()
def afficher_libelleles ():
ecran.set_color(blanc,blue)
ecran.erase() #init ecran blanc/bleu
afficher_bouton (5, 100, 190, 43, noir, vert, "" , 0,0, tt24)
afficher_bouton (5, 148, 190, 43, noir, vert, "", 0,0, tt24)
def creer_sprite(sprite_txt, sprite_nom ,spritecolor_txt ,spritecolor_fond):
w_E = len(sprite_txt*8)
h_E = 8
buf_Entree = bytearray(w_E * h_E * 2)
fb_buf_Entree = framebuf.FrameBuffer(buf_Entree, w_E, h_E, framebuf.RGB565)
fb_buf_Entree.fill(spritecolor_fond) # FOND gris clair
fb_buf_Entree.text(sprite_txt, 0, 0, spritecolor_txt) # CARACTERES
#continuer = input("enter 3 pour continuer")
buf_X2 = bytearray(w_E*2 * h_E*2 * 2)
fb_buf_X2 = framebuf.FrameBuffer(buf_X2, w_E*2, h_E*2, framebuf.RGB565)
ligne_O = bytearray(w_E*2) # ligne O à traiter
ligne_D = bytearray(w_E*2*2) #w_E*4 ligne D à creer
index_D = 0
for ih in range(h_E): #pour la ligne ih
ligne_O[:] = buf_Entree[ih*2*w_E:ih*2*w_E + 2*w_E] # extraction ligne ih
index_LD = 0
for iw in range(0,2*w_E,2): # parcourir les w_E*2 codcol
ligne_D[index_LD:index_LD+2] = ligne_O[iw:iw+2]
ligne_D[index_LD+2:index_LD+4] = ligne_O[iw:iw+2]
index_LD += 4
buf_X2[index_D:index_D+2*w_E*2] = ligne_D[:]
buf_X2[index_D+2*w_E*2:index_D+4*w_E*2] = ligne_D[:]
index_D += 4*w_E*2
long_sprite = len(buf_X2)
nom_sprite = "sprite_" + sprite_nom
w_sprite = "w_sprite_" + sprite_nom
fb_sprite = "fb_sprite_" + sprite_nom
globals()[nom_sprite] = buf_X2
globals()[w_sprite] = w_E*2
globals()[fb_sprite] = framebuf.FrameBuffer(globals()[nom_sprite], globals()[w_sprite], h_sprite, framebuf.RGB565)
afficher_libelleles ()
afficherB1_ON()
afficherB2_OFF()
afficher_bouton (xB3, yB3, wB3, hB3, noir, grisC, "", 10 , 12, tt24)
import framebuf
# (0x001F) # FOND BLEU
# (0x1FF8) # MAGENTA
# (0xE007) # VERT
# (0x20FD) # ORANGE ROSE
# (0xEFBD) # FOND gris clair
h_sprite = 16
# Affiche la mémoire libre en octets
print("Mémoire libre :", gc.mem_free(), "octets")
#creer bouton OFF
sprite_txt = sprite_nom ="OFF"
spritecolor_fond=0xEFBD
spritecolor_txt=0xFFFF
creer_sprite(sprite_txt, sprite_nom ,spritecolor_txt ,spritecolor_fond )
#creer bouton Ecran Noir
sprite_txt ="ETEINDRE L'ECRAN"
sprite_nom ="E_N"
spritecolor_fond=0xEFBD
spritecolor_txt=0xFFFF
creer_sprite(sprite_txt, sprite_nom ,spritecolor_txt ,spritecolor_fond )
#creer bouton ON
sprite_txt = sprite_nom ="ON"
spritecolor_fond=0x1FF8
spritecolor_txt=0x0000
creer_sprite(sprite_txt, sprite_nom ,spritecolor_txt ,spritecolor_fond )
#creer bouton MA
sprite_txt="LED M/A"
sprite_nom = "MA"
spritecolor_fond=0xE007
spritecolor_txt=0x0000
creer_sprite(sprite_txt, sprite_nom, spritecolor_txt ,spritecolor_fond )
#creer bouton Ventilo
sprite_txt="LED Ventil."
sprite_nom = "Ventilo"
spritecolor_fond=0xE007
spritecolor_txt=0x0000
creer_sprite(sprite_txt, sprite_nom, spritecolor_txt ,spritecolor_fond )
print("Mémoire libre :", gc.mem_free(), "octets")
#afficher sprite
ecran.afficher_sprite(fb_sprite_Ventilo , 15, 113, w_sprite_Ventilo , h_sprite)
ecran.afficher_sprite(fb_sprite_MA , 15, 161, w_sprite_MA , h_sprite)
ecran.afficher_sprite(fb_sprite_OFF , xB2+20, yB2+13, w_sprite_OFF , h_sprite)
ecran.afficher_sprite(fb_sprite_ON, xB1+28, yB1+13, w_sprite_ON, h_sprite)
ecran.afficher_sprite(fb_sprite_E_N, xB3+20, yB3+13, w_sprite_E_N, h_sprite)
"""
print ("DEBUT buf_X2 ___________________________________________________")
for i in range(0, 2*w_E*2*h_E*2, 2): # Affiche les premiers pixels (2 octets chacun)
pixel = buf_X2[i:i+2]
print ("iX2 ",i," ",pixel)
print ("FIN buf_X2 ___________________________________________________")
"""