Skip to content

Commit ba6a131

Browse files
authored
Merge pull request #6 from mitag/NoAbstracts
Removal of all abstract classes for microcontrollers
2 parents 4abacdb + acd4caf commit ba6a131

File tree

2 files changed

+107
-25
lines changed

2 files changed

+107
-25
lines changed

sparkfun_serlcd.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@
6060
__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"
6161

6262
# imports
63-
from abc import ABC, abstractmethod
63+
// from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3
6464
from time import sleep
6565
from micropython import const
6666

6767
# public constants
68-
DEFAULT_I2C_ADDR = const(0x72)
68+
# DEFAULT_I2C_ADDR = const(0x72)
6969
"""Default I2C address for SerLCD"""
7070

7171

@@ -139,8 +139,8 @@ def _map_range(value, in_min, in_max, out_min, out_max):
139139

140140
return int(result)
141141

142-
# abstract base class
143-
class Sparkfun_SerLCD(ABC):
142+
# base class
143+
class Sparkfun_SerLCD:
144144
"""Abstract base class for Sparkfun AVR-Based Serial LCD display.
145145
Use the appropriate driver communcation subclass Sprarkfun_SerLCD_I2C()
146146
for I2C, Sparkfun_SerLCD_SPI() for SPI or Sparkfun_SerLCD_UART for UART.
@@ -382,27 +382,6 @@ def set_contrast(self, value):
382382
self._write_bytes(data)
383383
sleep(0.010)
384384

385-
def set_i2c_address(self, new_address):
386-
"""Change the I2C Address. 0x72 is the default.
387-
Note that this change is persistent. If anything goes wrong
388-
you may need to do a hardware reset to unbrick the display.
389-
390-
byte new_addr - new i2c address"""
391-
# Mask new address to byte
392-
new_address &= 0x00FF
393-
# Transmit to device on old address
394-
data = bytearray()
395-
# Send contrast command
396-
data.append(_SETTING_COMMAND)
397-
data.append(_ADDRESS_COMMAND) # 0x19
398-
data.append(new_address)
399-
self._write_bytes(data)
400-
# Update our own address so we can still talk to the display
401-
self._change_i2c_address(new_address)
402-
403-
# This may take awhile
404-
sleep(0.050)
405-
406385
def scroll_display_left(self, count=1):
407386
"""Scroll the display to the left"""
408387
self._special_command(_LCD_CURSORSHIFT | _LCD_DISPLAYMOVE | _LCD_MOVELEFT, count)

sparkfun_serlcd_i2c.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019 Gaston Williams
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
"""
23+
`sparkfun_serlcd`
24+
================================================================================
25+
26+
CircuitPython driver library for the Sparkfun Serial LCD displays
27+
28+
29+
* Author(s): Gaston Williams
30+
31+
* Based on the Arduino library for the Sparkfun SerLCD displays
32+
Written by Gaston Williams, August 22, 2018
33+
* Based on sample code provided with the SparkFun Serial OpenLCD display.
34+
The original LiquidCrystal library was written by David A. Mellis and
35+
modified by Limor Fried @ Adafruit and the OpenLCD code was written by
36+
Nathan Seidle @ SparkFun.
37+
38+
39+
Implementation Notes
40+
--------------------
41+
42+
**Hardware:**
43+
44+
* This is library is for the SparkFun Serial LCD displays
45+
* SparkFun sells these at its website: www.sparkfun.com
46+
* Do you like this library? Help support SparkFun. Buy a board!
47+
* 16x2 SerLCD Black on RGB https://www.sparkfun.com/products/14072
48+
* 16x2 SerLCD RGB on Black https://www.sparkfun.com/products/14073
49+
* 20x4 SerLCD Black on RGB https://www.sparkfun.com/products/14074
50+
51+
**Software and Dependencies:**
52+
53+
* Adafruit CircuitPython firmware for the supported boards:
54+
https://github.com/adafruit/circuitpython/releases
55+
56+
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
57+
"""
58+
59+
__version__ = "0.0.0-auto.0"
60+
__repo__ = "https://github.com/fourstix/Sparkfun_CircuitPython_SerLCD.git"
61+
62+
# imports
63+
// from abc import ABC, abstractmethod // Please no abstractmethods, CircuitPython is not Python 3
64+
from time import sleep
65+
from micropython import const
66+
from sparkfun_serlcd.py import Sparkfun_SerLCD:
67+
68+
69+
# public constants
70+
DEFAULT_I2C_ADDR = const(0x72)
71+
"""Default I2C address for SerLCD"""
72+
73+
# sparkfun_serlcd_i2c.py
74+
class Sparkfun_SerLCD_i2c(Sparkfun_SerLCD):
75+
"""Sparkfun SerLCD connected to I2C
76+
This is a subclass of 'Sparkfun_SerLCD' and implements
77+
all of the same functions.
78+
79+
"""
80+
81+
def __init__(self, i2c, columns, lines, address=None):
82+
83+
84+
def set_i2c_address(self, new_address):
85+
"""Change the I2C Address. 0x72 is the default.
86+
Note that this change is persistent. If anything goes wrong
87+
you may need to do a hardware reset to unbrick the display.
88+
89+
byte new_addr - new i2c address"""
90+
# Mask new address to byte
91+
new_address &= 0x00FF
92+
# Transmit to device on old address
93+
data = bytearray()
94+
# Send contrast command
95+
data.append(_SETTING_COMMAND)
96+
data.append(_ADDRESS_COMMAND) # 0x19
97+
data.append(new_address)
98+
self._write_bytes(data)
99+
# Update our own address so we can still talk to the display
100+
self._change_i2c_address(new_address)
101+
102+
# This may take awhile
103+
sleep(0.050)

0 commit comments

Comments
 (0)