Skip to content

Commit

Permalink
Add 2- and 4-line variants of SSD1306 Display Functions and extra Opt…
Browse files Browse the repository at this point in the history
…ions (#1030)
  • Loading branch information
kizniche committed Jun 23, 2021
1 parent 8eb3a42 commit 1524fd4
Show file tree
Hide file tree
Showing 12 changed files with 1,724 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- Add Input: ADS1256 with Analog pH/EC sensors
- Add Output: MCP23017 16-Channel I/O Expander (On/Off)
- Add return status to Conditional Controllers
- Add SSD1306 128x64 Display with 4 Lines ([#1030](https://github.com/kizniche/mycodo/issues/1030))
- Add 2- and 4-line variants of SSD1306 Display Functions and extra Options ([#1030](https://github.com/kizniche/mycodo/issues/1030))

### Miscellaneous

Expand Down
21 changes: 12 additions & 9 deletions mycodo/devices/lcd_pioled_circuitpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ def lcd_init(self):
"Error: {err}".format(err=err))

def lcd_write_lines(self,
message_line_1,
message_line_2,
message_line_3,
message_line_4,
message_line_1=None,
message_line_2=None,
message_line_3=None,
message_line_4=None,
message_line_5=None,
message_line_6=None,
message_line_7=None,
Expand All @@ -123,11 +123,14 @@ def lcd_write_lines(self,
outline=0,
fill=0)

draw.text((x, top + self.line_y_dimensions[0]), message_line_1, font=font, fill=255)
draw.text((x, top + self.line_y_dimensions[1]), message_line_2, font=font, fill=255)
draw.text((x, top + self.line_y_dimensions[2]), message_line_3, font=font, fill=255)
draw.text((x, top + self.line_y_dimensions[3]), message_line_4, font=font, fill=255)

if message_line_1 is not None:
draw.text((x, top + self.line_y_dimensions[0]), message_line_1, font=font, fill=255)
if message_line_2 is not None:
draw.text((x, top + self.line_y_dimensions[1]), message_line_2, font=font, fill=255)
if message_line_3 is not None:
draw.text((x, top + self.line_y_dimensions[2]), message_line_3, font=font, fill=255)
if message_line_4 is not None:
draw.text((x, top + self.line_y_dimensions[3]), message_line_4, font=font, fill=255)
if message_line_5 is not None:
draw.text((x, top + self.line_y_dimensions[4]), message_line_5, font=font, fill=255)
if message_line_6 is not None:
Expand Down
28 changes: 23 additions & 5 deletions mycodo/functions/display_ssd1306_oled_128x32_i2c.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

# Set to how many lines the LCD has
lcd_lines = 4
lcd_x_characters = 21


def execute_at_creation(error, new_func, dict_functions=None):
Expand Down Expand Up @@ -171,7 +170,7 @@ def execute_at_modification(
'execute_at_creation': execute_at_creation,
'execute_at_modification': execute_at_modification,

'message': 'This Function outputs to a 128x32 SSD1306 OLED display via I2C. Since this display can show 8 lines at a time, channels are added in sets of 8 when Number of Line Sets is modified. Every Period, the LCD will refresh and display the next 8 lines. Therefore, the first 8 lines that are displayed are channels 0 - 7, then 8 - 15, and so on. After all channels have been displayed, it will cycle back to the beginning.',
'message': 'This Function outputs to a 128x32 SSD1306 OLED display via I2C. This display Function will show 4 lines at a time, so channels are added in sets of 4 when Number of Line Sets is modified. Every Period, the LCD will refresh and display the next set of lines. Therefore, the first set of lines that are displayed are channels 0 - 3, then 4 - 7, and so on. After all channels have been displayed, it will cycle back to the beginning.',

'options_disabled': [
'measurements_select',
Expand Down Expand Up @@ -232,6 +231,14 @@ def execute_at_modification(
'name': 'Reset Pin',
'phrase': 'The pin (BCM numbering) connected to RST of the display'
},
{
'id': 'characters_x',
'type': 'integer',
'default_value': 21,
'required': True,
'name': 'Characters Per Line',
'phrase': 'The maximum number of characters to display per line'
},
{
'id': 'use_non_default_font',
'type': 'bool',
Expand Down Expand Up @@ -315,6 +322,14 @@ def execute_at_modification(
'name': TRANSLATIONS['text']['title'],
'phrase': "Text to display"
},
{
'id': 'display_unit',
'type': 'bool',
'default_value': True,
'required': True,
'name': 'Display Unit',
'phrase': "Display the measurement unit (if available)"
}
]
}

Expand All @@ -340,6 +355,7 @@ def __init__(self, function, testing=False):
self.i2c_bus = None
self.number_line_sets = None
self.pin_reset = None
self.characters_x = None
self.use_non_default_font = None
self.non_default_font = None
self.font_size = None
Expand Down Expand Up @@ -374,9 +390,9 @@ def initialize_variables(self):
"interface": "I2C",
"i2c_address": self.i2c_address,
"i2c_bus": self.i2c_bus,
"x_characters": lcd_x_characters,
"x_characters": self.characters_x,
"line_y_dimensions": self.line_y_dimensions,
"lcd_type": "128x64_pioled_circuit_python",
"lcd_type": "128x32_pioled_circuit_python",
"font_size": self.font_size
}

Expand Down Expand Up @@ -441,7 +457,9 @@ def loop(self):
lines_display[current_line] = format_measurement_line(
self.options_channels['select_measurement'][current_channel]['device_id'],
self.options_channels['select_measurement'][current_channel]['measurement_id'],
val_rounded, lcd_x_characters)
val_rounded,
self.characters_x,
display_unit=self.options_channels['select_measurement'][current_channel]['display_unit'])

elif self.options_channels['line_display_type'][current_channel] == 'measurement_ts':
if measure_ts:
Expand Down
Loading

0 comments on commit 1524fd4

Please sign in to comment.