Skip to content

Commit

Permalink
smart mode done
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine3000 committed Jun 12, 2023
1 parent b083714 commit c1a0b48
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 42 deletions.
21 changes: 13 additions & 8 deletions software/modes.py
Original file line number Diff line number Diff line change
@@ -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]
],
]
30 changes: 17 additions & 13 deletions software/modules/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?"
Expand All @@ -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(
Expand All @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions software/modules/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions software/modules/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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!")
Expand Down
25 changes: 15 additions & 10 deletions software/modules/heating_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion software/modules/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions software/settings.toml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c1a0b48

Please sign in to comment.