From c1a0b4827c8f195018e02bec3044d0f338d262bd Mon Sep 17 00:00:00 2001 From: Antoine Jaunard Date: Mon, 12 Jun 2023 16:55:39 +0200 Subject: [PATCH] smart mode done --- software/modes.py | 21 +++++++++++++-------- software/modules/display.py | 30 +++++++++++++++++------------- software/modules/globals.py | 6 +++--- software/modules/handlers.py | 13 +++++++++---- software/modules/heating_system.py | 25 +++++++++++++++---------- software/modules/utilities.py | 2 +- software/settings.toml | 6 +++--- 7 files changed, 61 insertions(+), 42 deletions(-) diff --git a/software/modes.py b/software/modes.py index 2168e20..2246fe6 100755 --- a/software/modes.py +++ b/software/modes.py @@ -1,17 +1,22 @@ modes = [ - [ - "Express", - [00, 01, 02], - [32, 29, 27] - ], [ "Tempeh (48h)", [00, 20, 30, 40, 48], - [32, 31, 30, 27, 26] + [32, 31, 29, 27, 26] ], [ "Tempeh (60h)", [00, 20, 30, 48, 60], - [32, 32, 30, 27, 26] - ] + [32, 31, 29, 27, 26] + ], + [ + "Soaking (48h)", + [00, 24, 48], + [30, 28, 26] + ], + [ + "Quick test", + [0, 0.001, 0.002, 0.003, 0.004], + [32, 30, 28, 26, 25] + ], ] diff --git a/software/modules/display.py b/software/modules/display.py index 04de76e..cfdae71 100755 --- a/software/modules/display.py +++ b/software/modules/display.py @@ -34,19 +34,19 @@ # Text areas modules.globals.CONTENT_1_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=5, y=5) + FONT, text="", color=0xFFFFFF, x=5, y=6) modules.globals.CONTENT_2_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=5, y=19) + FONT, text="", color=0xFFFFFF, x=5, y=21) modules.globals.CONTENT_3_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=5, y=34) + FONT, text="", color=0xFFFFFF, x=5, y=36) modules.globals.CONTENT_4_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=5, y=41) + FONT, text="", color=0xFFFFFF, x=5, y=43) modules.globals.CONTENT_5_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=5, y=56) + FONT, text="", color=0xFFFFFF, x=5, y=57) modules.globals.MENU_LEFT_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=114, y=56) + FONT, text="", color=0xFFFFFF, x=114, y=57) modules.globals.MENU_RIGHT_AREA = label.Label( - FONT, text="", color=0xFFFFFF, x=123, y=56) + FONT, text="", color=0xFFFFFF, x=123, y=57) SCREEN.append(modules.globals.CONTENT_1_AREA) SCREEN.append(modules.globals.CONTENT_2_AREA) SCREEN.append(modules.globals.CONTENT_3_AREA) @@ -74,13 +74,14 @@ def display_screen(menu_on, manual_on, screen_index): # Select mode modules.globals.CONTENT_1_AREA.text = "Choose a mode for" modules.globals.CONTENT_2_AREA.text = "your fermentation" - modules.globals.CONTENT_5_AREA.text = modules.globals.modes[modules.globals.modes_index][0] + modules.globals.CONTENT_5_AREA.text = modules.globals.modes[ + modules.globals.modes_index][0] modules.globals.CONTENT_5_AREA.color = 0x000000 modules.globals.CONTENT_5_AREA.background_color = 0xFFFFFF modules.globals.MENU_LEFT_AREA.text = "↓" modules.globals.MENU_RIGHT_AREA.text = "↑" elif screen_index == 2: - temp_target = os.getenv('target_temperature') + modules.globals.temp_target = os.getenv('manual_target_temperature') modules.globals.CONTENT_1_AREA.text = " What's the ideal" modules.globals.CONTENT_2_AREA.text = "temperature for you" modules.globals.CONTENT_3_AREA.text = "fermentation?" @@ -91,7 +92,7 @@ def display_screen(menu_on, manual_on, screen_index): modules.globals.MENU_LEFT_AREA.text = "↓" modules.globals.MENU_RIGHT_AREA.text = "↑" elif screen_index == 3: - timer_hours = os.getenv('timer_hours') + modules.globals.timer_hours = os.getenv('manual_timer_hours') modules.globals.CONTENT_1_AREA.text = " For how long do" modules.globals.CONTENT_2_AREA.text = "you want to ferment?" modules.globals.CONTENT_5_AREA.text = modules.utilities.timer_unit( @@ -117,13 +118,16 @@ def display_screen(menu_on, manual_on, screen_index): modules.heating_system.update_values() elif screen_index == 1: modules.globals.CONTENT_1_AREA.text = " Set: Temperature" - modules.globals.CONTENT_5_AREA.text = "{} C".format(modules.utilities.round_down(modules.globals.temp_target, 1)) + modules.globals.CONTENT_5_AREA.text = "{} C".format( + modules.utilities.round_down(modules.globals.temp_target, 1)) elif screen_index == 2: modules.globals.CONTENT_1_AREA.text = " Set: Timer" - modules.globals.CONTENT_5_AREA.text = modules.utilities.timer_unit(int(modules.globals.timer_hours)) + modules.globals.CONTENT_5_AREA.text = modules.utilities.timer_unit( + int(modules.globals.timer_hours)) elif screen_index == 3: modules.globals.CONTENT_1_AREA.text = "Fermenting in mode" - modules.globals.CONTENT_2_AREA.text = "↳ {}".format(modules.globals.modes[modules.globals.modes_index][0]) + modules.globals.CONTENT_2_AREA.text = "↳ {}".format( + modules.globals.modes[modules.globals.modes_index][0]) modules.globals.CONTENT_3_AREA.text = "Want to change?" modules.globals.CONTENT_5_AREA.text = modules.globals.bool_string elif screen_index == 4: diff --git a/software/modules/globals.py b/software/modules/globals.py index c8eb7c5..a53d74b 100755 --- a/software/modules/globals.py +++ b/software/modules/globals.py @@ -17,10 +17,10 @@ def initialize(): modes_index = 0 global temp - temp = os.getenv('target_temperature') + temp = os.getenv('manual_target_temperature') global temp_target - temp_target = os.getenv('target_temperature') + temp_target = os.getenv('manual_target_temperature') global time_startup time_startup = time.time() @@ -32,7 +32,7 @@ def initialize(): time_sensor = time.time() global timer_hours - timer_hours = os.getenv('timer_hours') + timer_hours = os.getenv('manual_timer_hours') global time_left time_left = timer_hours diff --git a/software/modules/handlers.py b/software/modules/handlers.py index 500d1de..5256320 100755 --- a/software/modules/handlers.py +++ b/software/modules/handlers.py @@ -41,8 +41,7 @@ def edit_handler(increment): modules.globals.CONTENT_5_AREA.text = modules.globals.modes[modules.globals.modes_index][0] elif screen == "change_mode": modules.globals.total_increment += increment * 2 - print(modules.globals.total_increment) - if modules.globals.total_increment % 2 == 0: + if not modules.globals.total_increment % 2 == 0: modules.globals.bool_string = "Yes please" else: modules.globals.bool_string = "No thanks" @@ -125,12 +124,18 @@ def button_actions(): if screen == "define_time": modules.globals.time_startup = time.time() if screen == "change_mode" and modules.globals.bool_string == "Yes please": + # re initialize modules.globals.menu_on = False modules.globals.manual_on = False modules.globals.edit_mode = True modules.globals.modes_index = 0 - modules.globals.temp_target = os.getenv('target_temperature') - modules.globals.timer_hours = os.getenv('timer_hours') + modules.globals.time_startup = time.time() + modules.globals.time_heater = time.time() + modules.globals.time_sensor = time.time() + modules.globals.temp = os.getenv('manual_target_temperature') + modules.globals.temp_target = os.getenv('manual_target_temperature') + modules.globals.timer_hours = os.getenv('manual_timer_hours') + modules.globals.time_left = modules.globals.timer_hours modules.menu.goto("select_mode", "Set!") else: modules.menu.goto("dashboard", "Set!") diff --git a/software/modules/heating_system.py b/software/modules/heating_system.py index 6106eae..8d35270 100755 --- a/software/modules/heating_system.py +++ b/software/modules/heating_system.py @@ -111,7 +111,6 @@ def heating_system(temp, temp_target, temp_margin): time_now = time.time() time_diff = time_now - modules.globals.time_heater - print(modules.globals.fermenter_running) if modules.globals.fermenter_running: if not modules.globals.sensor_error: if temp > temp_target + temp_margin * 2: @@ -147,30 +146,36 @@ def heating_system(temp, temp_target, temp_margin): modules.globals.status_subsentence = "not responding" update_led('purple', 40) - update_status_sentence() - update_values() - else: - print('expired') modules.globals.status_sentence = " Timer expired." modules.globals.status_subsentence = "How did it go?" - update_led('white', 60) + update_led('white', 40) HEAT.duty_cycle = 0 if temp >= modules.globals.TEMP_SAFE: FAN.duty_cycle = modules.utilities.percent_to_duty_cycles(100) else: FAN.duty_cycle = 0 + + update_status_sentence() + update_values() def update_target_temp(time_left, mode): - if not modules.globals.manual_on: + if modules.globals.fermenter_running and not modules.globals.manual_on: time_left_diff = modules.globals.timer_hours * 3600 - time_left index = 0 for i in mode[1]: iindex = index + 1 if index + 1 <= len(mode[1]) else index if (mode[1][index] * 3600) < time_left_diff < (mode[1][iindex] * 3600): # convert time to percentage - time_diff_percent = 100 * float(time_left_diff) / float((mode[1][iindex] * 3600) - (mode[1][index] * 3600)) + percent_part = float(time_left_diff - (mode[1][index] * 3600) ) + percent_whole = float((mode[1][iindex] * 3600) - (mode[1][index] * 3600)) + time_diff_percent = 100 * percent_part / percent_whole + # print("time percent: " + str(time_diff_percent)) # calculate in-between temp according to time percentage - new_tempeh_target = modules.utilities.map_range(time_diff_percent, 0, 100, mode[2][index], mode[2][iindex]) - modules.globals.temp_target = modules.utilities.round_down(new_tempeh_target, 1) + new_temp_target = modules.utilities.map_range(time_diff_percent, 0, 100, mode[2][index], mode[2][iindex]) + # print("temp percent: " + str(new_temp_target)) + modules.globals.temp_target = modules.utilities.round_down(new_temp_target, 2) + # print("TIME: from:" + str(mode[1][index]) + " / to:" + str(mode[1][iindex])) + # print("TEMP: from:" + str(mode[2][index]) + " / to:" + str(mode[2][iindex])) + print("TEMP TARGET: " + str(modules.globals.temp_target)) index += 1 diff --git a/software/modules/utilities.py b/software/modules/utilities.py index 932851f..d05df13 100755 --- a/software/modules/utilities.py +++ b/software/modules/utilities.py @@ -27,4 +27,4 @@ def timer_unit(hour): return time_unit def map_range(x, in_min, in_max, out_min, out_max): - return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min diff --git a/software/settings.toml b/software/settings.toml index 8a44d08..e4e5859 100755 --- a/software/settings.toml +++ b/software/settings.toml @@ -1,8 +1,8 @@ # Settings fermenter_model = "mini" # mini or lab -target_temperature = 30 -timer_hours = 48 -sensor_model = "sht31d" # sht31d or mcp9808 or aht20 +manual_target_temperature = 30 +manual_timer_hours = 48 +sensor_model = "aht20" # sht31d or mcp9808 or aht20 display_orientation = "reversed" # normal or reversed led_model = "external" # external or onboard default_mode = "default" # default or manual