#! /usr/bin/env python3
#-*- coding: utf-8 -*-

# python3 /home/scripts_python_tests_capteurs/TFT9341/TFT9341_test_2.py
#----------------------------------------------------------------------
import time
from datetime import datetime
import string
import sys

import BuzzerPoussoir
import TFT9341


enabled_LCD_strings  = [True,True,True,True,True,True,True,True,True,True]

couleurs_AQCM05_TFT   = ["#28ED5D", "#20A649", "#EEEE19", "#FF8000", "#FF0000", "#A000A0", "#E000E0", "#FFFFFF", "#FFFFFF"]
couleurs_AQCM05_TFT   = ["#28ED5D", "#20A649", "#EEEE19", "#FF8000", "#FF0000", "#A000A0", "#E000E0", "#FFFFFF"]
couleurs_AQCM05_TFT   = ["#008000", "#00FF00", "#FFFF00", "#FF7000", "#FF0000", "#FF00FF", "#00B0B0", "#FFFFFF", "#B0B0B0"]

#----------------------------------------------------------------------
try:

	BuzzerPoussoir.init_GPIO_BZP()
	
	if not( TFT9341.TFT9341_init() ) :
		print("TFT9341 : initialisations -> échec !")
		print(" ")
		
	else :
		print("TFT9341 : initialisations -> succès.")
		print(" ")
		
		#----------------------------------------------------------------------
		'''
		TFT9341.TFT9341_display_logo()
		TFT9341.TFT9341_backlight_off()
		'''
		
		#----------------------------------------------------------------------
		'''
		chaine_a = "1234567890123456"
		chaine_b = "abcdefghijklmnop"
		
		TFT9341.TFT9341_update_TFT_12(chaine_a, chaine_b)
		TFT9341.TFT9341_backlight_on()
		time.sleep(3)
		TFT9341.TFT9341_backlight_off()
		time.sleep(1)
		'''

		#----------------------------------------------------------------------
		jours = [ "Dim", "Lun", "Mar", "Mer", "Jeu", "Ven", "Sam" ]
		
		#----------------------------------------------------------------------
		'''
		mac = "e4_5f_01_5c_5d_91"
		ip = "192.168.234.182/24"
		gw = "192.168.1.254"
		dns = "192.168.248.254"
		ssid = "LesGranges5"
		mac = mac.replace("_",":")
		TFT9341.TFT9341_update_TFT_NETWORK(mac, ip, gw, dns, ssid)
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)
		'''
		
		lignes = [ 
			"ligne_1", 
			"ligne_2", 
			"ligne_3", 
			"ligne_4" 
		]
		
		TFT9341.TFT9341_update_TFT_CONFIRMATION(lignes, 0)
		TFT9341.TFT9341_backlight_on()
		time.sleep(4)
		
		TFT9341.TFT9341_update_TFT_SABLIER()
		'''
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 0)
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 1)
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 2)
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 3)
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 4)
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_MENUS(lignes, 5)
		'''

		'''
		#titre:16, lignes:27
		lignes = [ 
			"pagaille_pagaille", 
			"PAGAILLE1_pagaille1_pagaill", 
			"pagaille_2", 
			"pagaille_3", 
			"pagaille_4",
			"pagaille_5"
		]
		
		TFT9341.TFT9341_update_TFT_INFO(lignes)
		TFT9341.TFT9341_backlight_on()
		'''



		'''
		date_heure_maintenant = time.localtime(time.time())
		jour = int(time.strftime('%w', date_heure_maintenant))
		date_TFT_string  = jours[jour] + " " + str(time.strftime('%d/%m/%Y', date_heure_maintenant))
		print(date_TFT_string)
		heure_TFT_string = str(time.strftime('%H:%M', date_heure_maintenant))

		heure_TFT_string = "20:58"
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "75", "3", couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0])
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)
		'''

		'''
		heure_TFT_string = "18:51"
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "75", "3", couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0])
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)

		heure_TFT_string = "18:58"
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "75", "3", couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0])
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)

		heure_TFT_string = "11:11"
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "75", "3", couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0])
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)

		heure_TFT_string = "00:00"
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "75", "3", couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0], couleurs_AQCM05_TFT[0])
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)

		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "105", "123", "1", couleurs_AQCM05_TFT[1], couleurs_AQCM05_TFT[1], couleurs_AQCM05_TFT[1])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "53", "83", "33", couleurs_AQCM05_TFT[2], couleurs_AQCM05_TFT[2], couleurs_AQCM05_TFT[2])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "81", "31", couleurs_AQCM05_TFT[3], couleurs_AQCM05_TFT[3], couleurs_AQCM05_TFT[3])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "53", "121", "333", couleurs_AQCM05_TFT[4], couleurs_AQCM05_TFT[4], couleurs_AQCM05_TFT[4])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "112", "311", couleurs_AQCM05_TFT[5], couleurs_AQCM05_TFT[5], couleurs_AQCM05_TFT[5])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "3333", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "1111", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "33333", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "11111", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "18181", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "51", "111", "41516", couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6], couleurs_AQCM05_TFT[6])
		time.sleep(2)
		'''

		
		'''
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "31", "71", "21", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "17", "18", "12", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "11", "103", "11", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "101", "423", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "118", "421", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "412", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "142", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "411", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "141", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "114", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "111", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "3456", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "3451", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "3416", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "3156", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "1456", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "1123", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "4511", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "4151", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_DBA(date_TFT_string, heure_TFT_string, "37", "111", "1111", couleurs_AQCM05_TFT[8], couleurs_AQCM05_TFT[9], couleurs_AQCM05_TFT[10])
		'''
		
		'''
		TFT9341.TFT9341_update_TFT_DBA("01/11/2023", "11:11:11", "115", "11.1", "41", couleurs_AQCM05_TFT[1], couleurs_AQCM05_TFT[2], couleurs_AQCM05_TFT[3])
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_DBA("01/11/2023", "11:11:11", "115", "7.1", "16", couleurs_AQCM05_TFT[1], couleurs_AQCM05_TFT[2], couleurs_AQCM05_TFT[3])
		time.sleep(2)
		
		TFT9341.TFT9341_update_TFT_DBA("01/11/2023", "11:11:11", "115", "1.1", "31", couleurs_AQCM05_TFT[1], couleurs_AQCM05_TFT[2], couleurs_AQCM05_TFT[3])

		TFT9341.TFT9341_backlight_off()
		time.sleep(1)

		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "745", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "741", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "751", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "715", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "110", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		TFT9341.TFT9341_update_TFT_lite("02/01/2023", "17:54:32", "1115", "18.3", "47", 3, 4, 5)
		time.sleep(2)
		'''

		
		'''
		
		#----------------------------------------------------------------------
		mesures_string = ["mesure 1", "mesure 2", "mesure 3", "mesure 4", "mesure 5", "mesure 6", "mesure 7", "mesure 8", "mesure 9", "mesure 10"]
		color_mesures_string = [0xFF0000, 0x00FF00, 0x0000FF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0xFFFFFF, 0x00FF00, 0x0000FF, 0xFFFFFF]

		TFT9341.TFT9341_display_TFT_mesures(mesures_string, color_mesures_string, enabled_LCD_strings)
		TFT9341.TFT9341_backlight_on()
		time.sleep(2)
		
		TFT9341.TFT9341_backlight_off()
		time.sleep(1)
		
		'''
		


		
			
except Exception as except_str:
	print(("TFT9341_test : exception -> ", except_str))
	print(" ")
		
finally:
	#TFT9341.TFT9341_backlight_off()

	print("TFT9341_test : sortie...")
	print(" ")

