Merge branch 'dev'
commit
05651f6ee3
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from inkplate10 import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from inkplate5 import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from inkplate6 import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from inkplate6COLOR import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from inkplate6PLUS import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from soldered_inkplate10 import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from soldered_inkplate6 import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,38 @@
|
|||
# This example will show you how to use the onboard RTC to preserve time across reboots
|
||||
|
||||
# Include all the required libraries
|
||||
from soldered_inkplate6PLUS import Inkplate
|
||||
import time
|
||||
|
||||
# Create Inkplate object in 1-bit mode, black and white colors only
|
||||
# For 2-bit grayscale, see basicGrayscale.py
|
||||
display = Inkplate(Inkplate.INKPLATE_1BIT)
|
||||
|
||||
# Main function
|
||||
if __name__ == "__main__":
|
||||
|
||||
# Initialize the display, needs to be called only once
|
||||
display.begin()
|
||||
|
||||
# Clear the frame buffer
|
||||
display.clearDisplay()
|
||||
|
||||
# This has to be called every time you want to update the screen
|
||||
# Drawing or printing text will have no effect on the display itself before you call this function
|
||||
display.display()
|
||||
|
||||
# This is how to set the RTC's time
|
||||
# Arguments are hour, minute, seconds
|
||||
display.rtcSetTime(9,39,10)
|
||||
# And this is the date
|
||||
# Arguments are weekday, day in month, month and year
|
||||
display.rtcSetDate(5,9,2,2024)
|
||||
|
||||
# Show the set time
|
||||
print(display.rtcGetData())
|
||||
|
||||
# Let's wait 10 seconds
|
||||
time.sleep(10)
|
||||
|
||||
# Let's see if the time has updated
|
||||
print(display.rtcGetData())
|
|
@ -0,0 +1,18 @@
|
|||
# Scanner i2c en MicroPython | MicroPython i2c scanner
|
||||
# Renvoi l'adresse en decimal et hexa de chaque device connecte sur le bus i2c
|
||||
# Return decimal and hexa adress of each i2c device
|
||||
# https://projetsdiy.fr - https://diyprojects.io (dec. 2017)
|
||||
|
||||
import machine
|
||||
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
|
||||
|
||||
print('Scan i2c bus...')
|
||||
devices = i2c.scan()
|
||||
|
||||
if len(devices) == 0:
|
||||
print("No i2c device !")
|
||||
else:
|
||||
print('i2c devices found:',len(devices))
|
||||
|
||||
for device in devices:
|
||||
print("Decimal address: ",device," | Hexa address: ",hex(device))
|
|
@ -59,6 +59,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -177,6 +181,70 @@ class _Inkplate:
|
|||
def _tps65186_read(cls, reg):
|
||||
cls._i2c.readfrom_mem(TPS65186_addr, reg, 1)[0]
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
# power_on turns the voltage regulator on and wakes up the display (GMODE and OE)
|
||||
@classmethod
|
||||
def power_on(cls):
|
||||
|
@ -1085,3 +1153,12 @@ class Inkplate:
|
|||
val >>= 1
|
||||
|
||||
self.drawPixel(x + i, y + h - j, val)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
93
inkplate5.py
93
inkplate5.py
|
@ -58,6 +58,14 @@ EPD_LE = const(0x00000004) # in W1Tx0
|
|||
EPD_CKV = const(0x00000001) # in W1Tx1
|
||||
EPD_SPH = const(0x00000002) # in W1Tx1
|
||||
|
||||
# Some constants for the RTC
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
|
||||
|
||||
# Inkplate provides access to the pins of the Inkplate 5 as well as to low-level display
|
||||
# functions.
|
||||
|
||||
|
@ -186,6 +194,70 @@ class _Inkplate:
|
|||
cls.power_off()
|
||||
return cls.temperatureInt
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
# _tps65186_write writes an 8-bit value to a register
|
||||
@classmethod
|
||||
def _tps65186_write(cls, reg, v):
|
||||
|
@ -398,10 +470,10 @@ class InkplateMono(framebuf.FrameBuffer):
|
|||
data = int(fb[ix])
|
||||
ix -= 1
|
||||
w1ts0[0] = lut[data >> 4]
|
||||
#w1tc0[0] = EPD_CL
|
||||
# w1tc0[0] = EPD_CL
|
||||
w1tc0[0] = off
|
||||
w1ts0[0] = lut[data & 0xF]
|
||||
#w1tc0[0] = EPD_CL
|
||||
# w1tc0[0] = EPD_CL
|
||||
w1tc0[0] = off
|
||||
|
||||
# display_mono sends the monochrome buffer to the display, clearing it first
|
||||
|
@ -420,8 +492,8 @@ class InkplateMono(framebuf.FrameBuffer):
|
|||
ip.clean(2, 1)
|
||||
ip.clean(0, 11)
|
||||
|
||||
#w1ts0 = ptr32(int(ESP32_GPIO + 4 * W1TS0))
|
||||
#w1tc0 = ptr32(int(ESP32_GPIO + 4 * W1TC0))
|
||||
# w1ts0 = ptr32(int(ESP32_GPIO + 4 * W1TS0))
|
||||
# w1tc0 = ptr32(int(ESP32_GPIO + 4 * W1TC0))
|
||||
|
||||
# the display gets written N times
|
||||
t1 = time.ticks_ms()
|
||||
|
@ -772,7 +844,7 @@ class Inkplate:
|
|||
None,
|
||||
None,
|
||||
)
|
||||
|
||||
|
||||
def initSDCard(self):
|
||||
_Inkplate.SD_ENABLE.digitalWrite(0)
|
||||
try:
|
||||
|
@ -791,7 +863,7 @@ class Inkplate:
|
|||
def SDCardSleep(self):
|
||||
_Inkplate.SD_ENABLE.digitalWrite(1)
|
||||
time.sleep_ms(5)
|
||||
|
||||
|
||||
def SDCardWake(self):
|
||||
_Inkplate.SD_ENABLE.digitalWrite(0)
|
||||
time.sleep_ms(5)
|
||||
|
@ -835,6 +907,15 @@ class Inkplate:
|
|||
def einkOff(self):
|
||||
_Inkplate.power_off()
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
||||
def readBattery(self):
|
||||
return _Inkplate.read_battery()
|
||||
|
||||
|
|
77
inkplate6.py
77
inkplate6.py
|
@ -61,6 +61,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -179,6 +183,70 @@ class _Inkplate:
|
|||
def _tps65186_read(cls, reg):
|
||||
cls._i2c.readfrom_mem(TPS65186_addr, reg, 1)[0]
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
# power_on turns the voltage regulator on and wakes up the display (GMODE and OE)
|
||||
@classmethod
|
||||
def power_on(cls):
|
||||
|
@ -1048,3 +1116,12 @@ class Inkplate:
|
|||
val >>= 1
|
||||
|
||||
self.drawPixel(x + i, y + h - j, val)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
|
@ -72,6 +72,10 @@ IO_PIN_B5 = const(13)
|
|||
IO_PIN_B6 = const(14)
|
||||
IO_PIN_B7 = const(15)
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class Inkplate:
|
||||
BLACK = const(0b00000000) # 0
|
||||
|
@ -275,6 +279,70 @@ class Inkplate:
|
|||
def gpioExpanderPin(self, pin, mode):
|
||||
return gpioPin(self._PCAL6416A, pin, mode)
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def clean(self):
|
||||
if not self._panelState:
|
||||
|
@ -510,3 +578,12 @@ class Inkplate:
|
|||
self.writePixel(x1 + x, y1 + y, pixel_value1)
|
||||
if x2 < width and y2 < height:
|
||||
self.writePixel(x2 + x, y2 + y, pixel_value2)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
|
@ -67,6 +67,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 6 PLUS as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -180,6 +184,71 @@ class _Inkplate:
|
|||
cls._i2c.writeto(FRONTLIGHT_ADDRESS, bytes((0,)))
|
||||
cls._i2c.writeto(FRONTLIGHT_ADDRESS, bytes((value,)))
|
||||
|
||||
# RTC
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
# Touchscreen
|
||||
|
||||
@classmethod
|
||||
|
@ -1273,3 +1342,12 @@ class Inkplate:
|
|||
|
||||
def tsShutdown(self):
|
||||
_Inkplate.tsShutdown()
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
|
@ -56,6 +56,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 10 as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -324,6 +328,70 @@ class _Inkplate:
|
|||
cls.vscan_start()
|
||||
cls.fill_screen(data)
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
|
||||
class InkplateMono(framebuf.FrameBuffer):
|
||||
def __init__(self):
|
||||
|
@ -1112,3 +1180,12 @@ class Inkplate:
|
|||
val >>= 1
|
||||
|
||||
self.drawPixel(x + i, y + h - j, val)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
|
@ -61,6 +61,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 6 as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -325,6 +329,70 @@ class _Inkplate:
|
|||
cls.vscan_start()
|
||||
cls.fill_screen(data)
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
|
||||
class InkplateMono(framebuf.FrameBuffer):
|
||||
def __init__(self):
|
||||
|
@ -1074,3 +1142,12 @@ class Inkplate:
|
|||
val >>= 1
|
||||
|
||||
self.drawPixel(x + i, y + h - j, val)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
||||
|
|
|
@ -67,6 +67,10 @@ EPD_SPH = const(0x00000002) # in W1Tx1
|
|||
# Inkplate provides access to the pins of the Inkplate 6 PLUS as well as to low-level display
|
||||
# functions.
|
||||
|
||||
RTC_I2C_ADDR = 0x51
|
||||
RTC_RAM_by = 0x03
|
||||
RTC_DAY_ADDR = 0x07
|
||||
RTC_SECOND_ADDR = 0x04
|
||||
|
||||
class _Inkplate:
|
||||
@classmethod
|
||||
|
@ -197,6 +201,70 @@ class _Inkplate:
|
|||
data_to_send = bytearray([0, value])
|
||||
cls._i2c.writeto(FRONTLIGHT_ADDRESS, data_to_send)
|
||||
|
||||
@classmethod
|
||||
def rtc_dec_to_bcd(cls, val):
|
||||
return (val // 10 * 16) + (val % 10)
|
||||
|
||||
@classmethod
|
||||
def rtc_bcd_to_dec(cls, val):
|
||||
return (val // 16 * 10) + (val % 16)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_time(cls, rtc_hour, rtc_minute, rtc_second):
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
cls.rtc_dec_to_bcd(rtc_second),
|
||||
cls.rtc_dec_to_bcd(rtc_minute),
|
||||
cls.rtc_dec_to_bcd(rtc_hour)
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_set_date(cls, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
rtcYear = rtc_yr - 2000
|
||||
|
||||
data = bytearray([
|
||||
RTC_RAM_by,
|
||||
170, # Write in RAM 170 to know that RTC is set
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
data = bytearray([
|
||||
RTC_DAY_ADDR,
|
||||
cls.rtc_dec_to_bcd(rtc_day),
|
||||
cls.rtc_dec_to_bcd(rtc_weekday),
|
||||
cls.rtc_dec_to_bcd(rtc_month),
|
||||
cls.rtc_dec_to_bcd(rtcYear),
|
||||
])
|
||||
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, data)
|
||||
|
||||
@classmethod
|
||||
def rtc_get_rtc_data(cls):
|
||||
cls._i2c.writeto(RTC_I2C_ADDR, bytearray([RTC_SECOND_ADDR]))
|
||||
data = cls._i2c.readfrom(RTC_I2C_ADDR, 7)
|
||||
|
||||
rtc_second = cls.rtc_bcd_to_dec(data[0] & 0x7F) # Ignore bit 7
|
||||
rtc_minute = cls.rtc_bcd_to_dec(data[1] & 0x7F)
|
||||
rtc_hour = cls.rtc_bcd_to_dec(data[2] & 0x3F) # Ignore bits 7 & 6
|
||||
rtc_day = cls.rtc_bcd_to_dec(data[3] & 0x3F)
|
||||
rtc_weekday = cls.rtc_bcd_to_dec(data[4] & 0x07) # Ignore bits 7,6,5,4 & 3
|
||||
rtc_month = cls.rtc_bcd_to_dec(data[5] & 0x1F) # Ignore bits 7,6 & 5
|
||||
rtc_year = cls.rtc_bcd_to_dec(data[6]) + 2000
|
||||
|
||||
return {
|
||||
'second': rtc_second,
|
||||
'minute': rtc_minute,
|
||||
'hour': rtc_hour,
|
||||
'day': rtc_day,
|
||||
'weekday': rtc_weekday,
|
||||
'month': rtc_month,
|
||||
'year': rtc_year
|
||||
}
|
||||
|
||||
# Touchscreen
|
||||
@classmethod
|
||||
def touchInArea(cls, x, y, width, height):
|
||||
|
@ -1325,4 +1393,13 @@ class Inkplate:
|
|||
_Inkplate.frontlight(value)
|
||||
|
||||
def setFrontlight(self, value):
|
||||
_Inkplate.setFrontlight(value)
|
||||
_Inkplate.setFrontlight(value)
|
||||
|
||||
def rtcSetTime(self, rtc_hour, rtc_minute, rtc_second):
|
||||
return _Inkplate.rtc_set_time(rtc_hour, rtc_minute, rtc_second)
|
||||
|
||||
def rtcSetDate(self, rtc_weekday, rtc_day, rtc_month, rtc_yr):
|
||||
return _Inkplate.rtc_set_date(rtc_weekday, rtc_day, rtc_month, rtc_yr)
|
||||
|
||||
def rtcGetData(self):
|
||||
return _Inkplate.rtc_get_rtc_data()
|
Loading…
Reference in New Issue