Adding support for Waveshare V1 displays.
Adding support for full refresh after n partial refreshes (for Waveshare displays).
This commit is contained in:
parent
000e11869f
commit
32b7428595
sdcard/rootfs/root/pwnagotchi
config.yml
scripts/pwnagotchi/ui
@ -93,9 +93,11 @@ ui:
|
||||
enabled: true
|
||||
rotation: 180
|
||||
# Possible options inkyphat/inky or waveshare/ws
|
||||
type: 'waveshare'
|
||||
type: 'waveshare_2'
|
||||
# Possible options red/yellow/black (black used for monocromatic displays)
|
||||
color: 'black'
|
||||
# How often to do a full refresh
|
||||
refresh: 10
|
||||
video:
|
||||
enabled: true
|
||||
address: '10.0.0.2'
|
||||
|
@ -79,6 +79,9 @@ class Display(View):
|
||||
self._video_address = config['ui']['display']['video']['address']
|
||||
self._display_type = config['ui']['display']['type']
|
||||
self._display_color = config['ui']['display']['color']
|
||||
self.full_refresh_count = 0
|
||||
self.full_refresh_trigger = config['ui']['display']['refresh']
|
||||
|
||||
self._render_cb = None
|
||||
self._display = None
|
||||
self._httpd = None
|
||||
@ -104,8 +107,11 @@ class Display(View):
|
||||
def _is_inky(self):
|
||||
return self._display_type in ('inkyphat', 'inky')
|
||||
|
||||
def _is_waveshare(self):
|
||||
return self._display_type in ('waveshare', 'ws')
|
||||
def _is_waveshare1(self):
|
||||
return self._display_type in ('waveshare_1', 'ws_1', 'waveshare1', 'ws1')
|
||||
|
||||
def _is_waveshare2(self):
|
||||
return self._display_type in ('waveshare_2', 'ws_2', 'waveshare2', 'ws2')
|
||||
|
||||
def _init_display(self):
|
||||
if self._is_inky():
|
||||
@ -113,8 +119,16 @@ class Display(View):
|
||||
self._display = InkyPHAT(self._display_color)
|
||||
self._display.set_border(InkyPHAT.BLACK)
|
||||
self._render_cb = self._inky_render
|
||||
elif self._is_waveshare():
|
||||
from pwnagotchi.ui.waveshare import EPD
|
||||
elif self._is_waveshare1():
|
||||
from pwnagotchi.ui.waveshare.v1.epd2in13 import EPD
|
||||
# core.log("display module started")
|
||||
self._display = EPD()
|
||||
self._display.init(self._display.lut_full_update)
|
||||
self._display.Clear(0xFF)
|
||||
self._display.init(self._display.lut_partial_update)
|
||||
self._render_cb = self._waveshare_render
|
||||
elif self._is_waveshare2():
|
||||
from pwnagotchi.ui.v2.waveshare import EPD
|
||||
# core.log("display module started")
|
||||
self._display = EPD()
|
||||
self._display.init(self._display.FULL_UPDATE)
|
||||
@ -165,7 +179,19 @@ class Display(View):
|
||||
|
||||
def _waveshare_render(self):
|
||||
buf = self._display.getbuffer(self.canvas)
|
||||
self._display.displayPartial(buf)
|
||||
if self._is_waveshare1:
|
||||
if self.full_refresh_count == self.full_refresh_trigger:
|
||||
self._display.Clear(0x00)
|
||||
self._display.display(buf)
|
||||
elif self._is_waveshare2:
|
||||
if self.full_refresh_count == self.full_refresh_trigger:
|
||||
self._display.Clear(BLACK)
|
||||
self._display.displayPartial(buf)
|
||||
self._display.sleep()
|
||||
if self.full_refresh_count == self.full_refresh_trigger:
|
||||
self.full_refresh_count = 0
|
||||
else:
|
||||
self.full_refresh_count += 1
|
||||
|
||||
def _on_view_rendered(self, img):
|
||||
# core.log("display::_on_view_rendered")
|
||||
|
@ -31,7 +31,8 @@ def setup_display_specifics(config):
|
||||
face_pos = (0, int(height / 4))
|
||||
name_pos = (int(width / 2) - 15, int(height * .15))
|
||||
status_pos = (int(width / 2) - 15, int(height * .30))
|
||||
elif config['ui']['display']['type'] in ('ws', 'waveshare'):
|
||||
elif config['ui']['display']['type'] in ('ws_1', 'ws1', 'waveshare_1', 'waveshare1',
|
||||
'ws_2', 'ws2', 'waveshare_2', 'waveshare2'):
|
||||
fonts.setup(10, 9, 10, 35)
|
||||
|
||||
width = 250
|
||||
|
@ -0,0 +1,218 @@
|
||||
# //*****************************************************************************
|
||||
# * | File : epd2in13.py
|
||||
# * | Author : Waveshare team
|
||||
# * | Function : Electronic paper driver
|
||||
# * | Info :
|
||||
# *----------------
|
||||
# * | This version: V3.1
|
||||
# * | Date : 2019-03-20
|
||||
# * | Info : python3 demo
|
||||
# * fix: TurnOnDisplay()
|
||||
# ******************************************************************************//
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documnetation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and//or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
|
||||
from . import epdconfig
|
||||
from PIL import Image
|
||||
import RPi.GPIO as GPIO
|
||||
# import numpy as np
|
||||
|
||||
# Display resolution
|
||||
EPD_WIDTH = 122
|
||||
EPD_HEIGHT = 250
|
||||
|
||||
class EPD:
|
||||
def __init__(self):
|
||||
self.reset_pin = epdconfig.RST_PIN
|
||||
self.dc_pin = epdconfig.DC_PIN
|
||||
self.busy_pin = epdconfig.BUSY_PIN
|
||||
self.width = EPD_WIDTH
|
||||
self.height = EPD_HEIGHT
|
||||
lut_full_update = [
|
||||
0x22, 0x55, 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x11,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E, 0x1E,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
]
|
||||
|
||||
lut_partial_update = [
|
||||
0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
]
|
||||
|
||||
# Hardware reset
|
||||
def reset(self):
|
||||
epdconfig.digital_write(self.reset_pin, GPIO.HIGH)
|
||||
epdconfig.delay_ms(200)
|
||||
epdconfig.digital_write(self.reset_pin, GPIO.LOW) # module reset
|
||||
epdconfig.delay_ms(200)
|
||||
epdconfig.digital_write(self.reset_pin, GPIO.HIGH)
|
||||
epdconfig.delay_ms(200)
|
||||
|
||||
def send_command(self, command):
|
||||
epdconfig.digital_write(self.dc_pin, GPIO.LOW)
|
||||
epdconfig.spi_writebyte([command])
|
||||
|
||||
def send_data(self, data):
|
||||
epdconfig.digital_write(self.dc_pin, GPIO.HIGH)
|
||||
epdconfig.spi_writebyte([data])
|
||||
|
||||
def wait_until_idle(self):
|
||||
# print("busy")
|
||||
while(epdconfig.digital_read(self.busy_pin) == 1): # 0: idle, 1: busy
|
||||
epdconfig.delay_ms(100)
|
||||
# print("free busy")
|
||||
|
||||
def TurnOnDisplay(self):
|
||||
self.send_command(0x22) # DISPLAY_UPDATE_CONTROL_2
|
||||
self.send_data(0xC4)
|
||||
self.send_command(0x20) # MASTER_ACTIVATION
|
||||
self.send_command(0xFF) # TERMINATE_FRAME_READ_WRITE
|
||||
self.wait_until_idle()
|
||||
|
||||
def init(self, lut):
|
||||
if (epdconfig.module_init() != 0):
|
||||
return -1
|
||||
# EPD hardware init start
|
||||
self.reset()
|
||||
self.send_command(0x01) # DRIVER_OUTPUT_CONTROL
|
||||
self.send_data((EPD_HEIGHT - 1) & 0xFF)
|
||||
self.send_data(((EPD_HEIGHT - 1) >> 8) & 0xFF)
|
||||
self.send_data(0x00) # GD = 0 SM = 0 TB = 0
|
||||
|
||||
self.send_command(0x0C) # BOOSTER_SOFT_START_CONTROL
|
||||
self.send_data(0xD7)
|
||||
self.send_data(0xD6)
|
||||
self.send_data(0x9D)
|
||||
|
||||
self.send_command(0x2C) # WRITE_VCOM_REGISTER
|
||||
self.send_data(0xA8) # VCOM 7C
|
||||
|
||||
self.send_command(0x3A) # SET_DUMMY_LINE_PERIOD
|
||||
self.send_data(0x1A) # 4 dummy lines per gate
|
||||
|
||||
self.send_command(0x3B) # SET_GATE_TIME
|
||||
self.send_data(0x08) # 2us per line
|
||||
|
||||
self.send_command(0X3C) # BORDER_WAVEFORM_CONTROL
|
||||
self.send_data(0x03)
|
||||
|
||||
self.send_command(0X11) # DATA_ENTRY_MODE_SETTING
|
||||
self.send_data(0x03) # X increment; Y increment
|
||||
|
||||
# WRITE_LUT_REGISTER
|
||||
self.send_command(0x32)
|
||||
for count in range(30):
|
||||
self.send_data(lut[count])
|
||||
|
||||
return 0
|
||||
|
||||
##
|
||||
# @brief: specify the memory area for data R//W
|
||||
##
|
||||
def SetWindows(self, x_start, y_start, x_end, y_end):
|
||||
self.send_command(0x44) # SET_RAM_X_ADDRESS_START_END_POSITION
|
||||
self.send_data((x_start >> 3) & 0xFF)
|
||||
self.send_data((x_end >> 3) & 0xFF)
|
||||
self.send_command(0x45) # SET_RAM_Y_ADDRESS_START_END_POSITION
|
||||
self.send_data(y_start & 0xFF)
|
||||
self.send_data((y_start >> 8) & 0xFF)
|
||||
self.send_data(y_end & 0xFF)
|
||||
self.send_data((y_end >> 8) & 0xFF)
|
||||
|
||||
##
|
||||
# @brief: specify the start point for data R//W
|
||||
##
|
||||
def SetCursor(self, x, y):
|
||||
self.send_command(0x4E) # SET_RAM_X_ADDRESS_COUNTER
|
||||
# x point must be the multiple of 8 or the last 3 bits will be ignored
|
||||
self.send_data((x >> 3) & 0xFF)
|
||||
self.send_command(0x4F) # SET_RAM_Y_ADDRESS_COUNTER
|
||||
self.send_data(y & 0xFF)
|
||||
self.send_data((y >> 8) & 0xFF)
|
||||
self.wait_until_idle()
|
||||
|
||||
def getbuffer(self, image):
|
||||
if self.width%8 == 0:
|
||||
linewidth = self.width//8
|
||||
else:
|
||||
linewidth = self.width//8 + 1
|
||||
|
||||
buf = [0xFF] * (linewidth * self.height)
|
||||
image_monocolor = image.convert('1')
|
||||
imwidth, imheight = image_monocolor.size
|
||||
pixels = image_monocolor.load()
|
||||
|
||||
if(imwidth == self.width and imheight == self.height):
|
||||
# print("Vertical")
|
||||
for y in range(imheight):
|
||||
for x in range(imwidth):
|
||||
if pixels[x, y] == 0:
|
||||
# x = imwidth - x
|
||||
buf[x // 8 + y * linewidth] &= ~(0x80 >> (x % 8))
|
||||
elif(imwidth == self.height and imheight == self.width):
|
||||
# print("Horizontal")
|
||||
for y in range(imheight):
|
||||
for x in range(imwidth):
|
||||
newx = y
|
||||
newy = self.height - x - 1
|
||||
if pixels[x, y] == 0:
|
||||
# newy = imwidth - newy - 1
|
||||
buf[newx // 8 + newy*linewidth] &= ~(0x80 >> (y % 8))
|
||||
return buf
|
||||
|
||||
|
||||
def display(self, image):
|
||||
if self.width%8 == 0:
|
||||
linewidth = self.width//8
|
||||
else:
|
||||
linewidth = self.width//8 + 1
|
||||
|
||||
self.SetWindows(0, 0, EPD_WIDTH, EPD_HEIGHT);
|
||||
for j in range(0, self.height):
|
||||
self.SetCursor(0, j);
|
||||
self.send_command(0x24);
|
||||
for i in range(0, linewidth):
|
||||
self.send_data(image[i + j * linewidth])
|
||||
self.TurnOnDisplay()
|
||||
|
||||
def Clear(self, color):
|
||||
if self.width%8 == 0:
|
||||
linewidth = self.width//8
|
||||
else:
|
||||
linewidth = self.width//8 + 1
|
||||
|
||||
self.SetWindows(0, 0, EPD_WIDTH, EPD_HEIGHT);
|
||||
for j in range(0, self.height):
|
||||
self.SetCursor(0, j);
|
||||
self.send_command(0x24);
|
||||
for i in range(0, linewidth):
|
||||
self.send_data(color)
|
||||
self.TurnOnDisplay()
|
||||
|
||||
def sleep(self):
|
||||
self.send_command(0x10) #enter deep sleep
|
||||
# self.send_data(0x01)
|
||||
epdconfig.delay_ms(100)
|
||||
|
||||
### END OF FILE ###
|
||||
|
@ -0,0 +1 @@
|
||||
epdconfig_old.py
|
Loading…
x
Reference in New Issue
Block a user