#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 machine, onewire, ds18x20, time, binascii
from machine import Pin, SPI, Timer
timer_0 = Timer(0)
from ili9341new import ILI9341, color565
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]
blanc=color565(255,255,255)
noir=color565(0,0,0)
rouge=color565(255,0,0)
blue=color565(0,0,255)
vert=color565(0,255,0)
cyan = color565(0, 255, 255)
pourpre = color565(255, 0, 255)
grisF=color565(64,64,64)
grisM=color565(128,128,128)
grisC=color565(192,192,192)
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, cyan, "", 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, "LED Ventilateur" , 9 , 12, tt24)
afficher_bouton (5, 148, 190, 43, noir, vert, "LED M/A", 9 , 12, tt24)
afficher_libelleles ()
afficherB1_ON()
#continuer = input("enter -1 pour continuer")
afficherB2_OFF()
#continuer = input("enter 0 pour continuer")
import framebuf
# (0x001F) # FOND BLEU
# (0x1FF8) # MAGENTA
# (0xFF07) # VERT
# (0x20FD) # ORANGE ROSE
# (0xEFBD) # FOND gris clair
fbcolor_fond=0xEFBD
fbcolor_txt=0xFFFF
fb_txt="OFF"
sprite_OFF = bytearray(1)
w_sprite_OFF = len(fb_txt*8)
w_E = len(fb_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(fbcolor_fond) # FOND gris clair
fb_buf_Entree.text(fb_txt, 0, 0, fbcolor_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)
print("long =", long_sprite)
sprite_OFF = bytearray(long_sprite)
fb_sprite_OFF = framebuf.FrameBuffer(sprite_OFF, w_E*2, h_E*2, framebuf.RGB565)
sprite_OFF[:] = buf_X2
"""
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 ___________________________________________________")
"""
ecran.ds_sprite(fb_sprite_OFF, xB2+20, yB2+13, w_E*2, h_E*2)