Skip to content

Commit

Permalink
Optimized chart drawing to (hopefully) reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dukeduck1984 committed Sep 30, 2020
1 parent f900142 commit 4ed442d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions MAIN/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def __init__(self, profiles_obj, config_dict, pid_obj, sensor_obj):
self.led = self.led_init()
self.line = None
self.dashed_line = None
self.null_chart_point_list = None
self.point_count = None
self.chart_point_list = None
self.profile_detail_init()
self.profile_alloy_selector.move_foreground()
self.show_set_btn_hide_stage()
Expand Down Expand Up @@ -77,9 +78,17 @@ def profile_detail_init(self):
# Update chart settings
temp_range = self.profiles.get_temp_range()
self.chart.set_range(temp_range[0], temp_range[-1] + GUI.CHART_TOP_PADDING) # min, max temp in the chart
point_count = self.profiles.get_chart_point_count()
self.chart.set_point_count(point_count)
self.null_chart_point_list = [lv.CHART_POINT.DEF] * point_count
self.point_count = self.profiles.get_chart_point_count()
self.chart.set_point_count(self.point_count)
self.chart_point_list = self.null_chart_list

@property
def null_chart_list(self):
"""
Generate a null list for the chart
:return: List
"""
return [lv.CHART_POINT.DEF] * self.point_count

def chart_init(self):
"""
Expand All @@ -99,17 +108,17 @@ def chart_clear(self):
"""
Clear the chart with null points
"""
self.chart.set_points(self.chart_series, self.null_chart_point_list)
self.chart_point_list = self.null_chart_list
self.chart.set_points(self.chart_series, self.chart_point_list)

def chart_update(self, temp_list):
"""
Update chart data, should be called every 1s
:param temp_list: list of actual temp with increasing length - new point appended to the tail
"""
list_length = len(temp_list)
data_points = self.null_chart_point_list.copy()
data_points[:list_length] = temp_list
self.chart.set_points(self.chart_series, data_points)
self.chart_point_list[:list_length] = temp_list
self.chart.set_points(self.chart_series, self.chart_point_list)

def draw_profile_line(self, points):
"""
Expand Down
2 changes: 1 addition & 1 deletion MAIN/oven_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _reflow_temp_control(self):
self.set_oven_state("cool")
if self.oven_state == "cool":
self.oven_enable(False)
if self.oven_state == 'cool' and len(self.temp_points) >= len(self.gui.null_chart_point_list):
if self.oven_state == 'cool' and len(self.temp_points) >= len(self.gui.chart_point_list):
self.beep.activate('Stop')
self.has_started = False

Expand Down

0 comments on commit 4ed442d

Please sign in to comment.