acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_example_meter_3.py (2472B)
1 #!//opt/bin/lv_micropython -i 2 import utime as time 3 import lvgl as lv 4 import display_driver 5 from imagetools import get_png_info, open_png 6 7 # Register PNG image decoder 8 decoder = lv.img.decoder_create() 9 decoder.info_cb = get_png_info 10 decoder.open_cb = open_png 11 12 # Create an image from the png file 13 try: 14 with open('../../assets/img_hand_min.png','rb') as f: 15 img_hand_min_data = f.read() 16 except: 17 print("Could not find img_hand_min.png") 18 sys.exit() 19 20 img_hand_min_dsc = lv.img_dsc_t({ 21 'data_size': len(img_hand_min_data), 22 'data': img_hand_min_data 23 }) 24 25 # Create an image from the png file 26 try: 27 with open('../../assets/img_hand_hour.png','rb') as f: 28 img_hand_hour_data = f.read() 29 except: 30 print("Could not find img_hand_hour.png") 31 sys.exit() 32 33 img_hand_hour_dsc = lv.img_dsc_t({ 34 'data_size': len(img_hand_hour_data), 35 'data': img_hand_hour_data 36 }) 37 38 def set_value(indic, v): 39 meter.set_indicator_value(indic, v) 40 # 41 # A clock from a meter 42 # 43 44 meter = lv.meter(lv.scr_act()) 45 meter.set_size(220, 220) 46 meter.center() 47 48 # Create a scale for the minutes 49 # 61 ticks in a 360 degrees range (the last and the first line overlaps) 50 scale_min = meter.add_scale() 51 meter.set_scale_ticks(scale_min, 61, 1, 10, lv.palette_main(lv.PALETTE.GREY)) 52 meter.set_scale_range(scale_min, 0, 60, 360, 270) 53 54 # Create another scale for the hours. It's only visual and contains only major ticks 55 scale_hour = meter.add_scale() 56 meter.set_scale_ticks(scale_hour, 12, 0, 0, lv.palette_main(lv.PALETTE.GREY)) # 12 ticks 57 meter.set_scale_major_ticks(scale_hour, 1, 2, 20, lv.color_black(), 10) # Every tick is major 58 meter.set_scale_range(scale_hour, 1, 12, 330, 300) # [1..12] values in an almost full circle 59 60 # LV_IMG_DECLARE(img_hand) 61 62 # Add the hands from images 63 indic_min = meter.add_needle_img(scale_min, img_hand_min_dsc, 5, 5) 64 indic_hour = meter.add_needle_img(scale_min, img_hand_hour_dsc, 5, 5) 65 66 # Create an animation to set the value 67 a1 = lv.anim_t() 68 a1.init() 69 a1.set_values(0, 60) 70 a1.set_repeat_count(lv.ANIM_REPEAT.INFINITE) 71 a1.set_time(2000) # 2 sec for 1 turn of the minute hand (1 hour) 72 a1.set_var(indic_min) 73 a1.set_custom_exec_cb(lambda a1,val: set_value(indic_min,val)) 74 lv.anim_t.start(a1) 75 76 a2 = lv.anim_t() 77 a2.init() 78 a2.set_var(indic_hour) 79 a2.set_time(24000) # 24 sec for 1 turn of the hour hand 80 a2.set_values(0, 60) 81 a2.set_custom_exec_cb(lambda a2,val: set_value(indic_hour,val)) 82 lv.anim_t.start(a2) 83