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

# clear && python3 /home/scripts_python/TFT9341_test_B.py
#----------------------------------------------------------------------
import time
import string
import sys

import BuzzerPoussoir
import TFT9341

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

	BuzzerPoussoir.init_GPIO_BZP()
	
	TFT9341.TFT9341_backlight_on()
	
	if not( TFT9341.TFT9341_init() ) :
		print("TFT9341 : initialisations -> échec !")
		print(" ")
		
	else :
		print("TFT9341 : initialisations -> succès.")
		print(" ")
		

		chaine_a = "1234567890123456"
		chaine_b = "abcdefghijklmnop"
		
		TFT9341.TFT9341_update_TFT_12(chaine_a, chaine_b)
		
		time.sleep(2)
		
		mesures_string       = ["mesure 1", "mesure 2", "mesure 3", "mesure 4", "mesure 5", "mesure 6", "mesure 7", "mesure 8"]
		color_mesures_string = ["#FF0000", "#00FF00", "#0000FF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"]

		TFT9341.TFT9341_display_TFT_mesures(mesures_string, color_mesures_string, 8)
		
		time.sleep(2)
		
		while True:
			try:
				print("TFT9341 : boucle sans fin...")
				print(" ")
				
				while True:


					time.sleep(2)


			except KeyboardInterrupt:				
				print("TFT9341 : exception 1 (clavier) !!!")
				print(" ")
				sys.exit(3)
				
			except:
				print("TFT9341 : exception 2 !!!")
				print(" ")
			
			
except Exception as except_str:
	print(("TFT9341 : exception 3 -> ", except_str))
	print(" ")
		
finally:
	TFT9341.TFT9341_backlight_off()

	print("TFT9341 : sortie...")
	print(" ")

