module:micropython:esp32displaykey:esp32displaykey
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
module:micropython:esp32displaykey:esp32displaykey [2021/12/25 14:10] – [Main-Program: Esp32CheckUart.py] omdevelop | module:micropython:esp32displaykey:esp32displaykey [2022/09/13 11:58] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 18: | Line 18: | ||
* minimale Zeit zur Erkennung von Tastenwiederholungen: | * minimale Zeit zur Erkennung von Tastenwiederholungen: | ||
* Eigener Thread mit permanenter Tastatur-Abfrage | * Eigener Thread mit permanenter Tastatur-Abfrage | ||
+ | * Entprellung über TIME_KEYPRESSES | ||
+ | * Tasten-Wiederholung über TIME_KEYREPETITION | ||
* MainLoop: periodische Abfrage GetKeyCode() | * MainLoop: periodische Abfrage GetKeyCode() | ||
* Keys beim IT01: | * Keys beim IT01: | ||
Line 42: | Line 44: | ||
===== Version ===== | ===== Version ===== | ||
- | {{: | + | {{: |
===== Beschreibung ===== | ===== Beschreibung ===== | ||
+ | {{: | ||
==== Ausgabe MicroPython-Terminal: | ==== Ausgabe MicroPython-Terminal: | ||
* Ausgabe der KeyCodes (mit Wiederholungen) | * Ausgabe der KeyCodes (mit Wiederholungen) | ||
Line 378: | Line 381: | ||
</ | </ | ||
- | ==== Library-Module: | + | ==== Library-Module: |
<code python> | <code python> | ||
+ | # | ||
+ | import time | ||
+ | # | ||
+ | class CLCDisplay: | ||
+ | # HD44780 LCD controller command set | ||
+ | LCD_CLR = 0x01 # DB0: clear display | ||
+ | LCD_HOME = 0x02 # DB1: return to home position | ||
+ | # | ||
+ | LCD_ENTRY_MODE = 0x04 # DB2: set entry mode | ||
+ | LCD_ENTRY_INC = 0x02 # --DB1: increment | ||
+ | LCD_ENTRY_SHIFT = 0x01 # --DB0: shift | ||
+ | # | ||
+ | LCD_ON_CTRL = 0x08 # DB3: turn lcd/cursor on | ||
+ | LCD_ON_DISPLAY = 0x04 # --DB2: turn display on | ||
+ | LCD_ON_CURSOR = 0x02 # --DB1: turn cursor on | ||
+ | LCD_ON_BLINK = 0x01 # --DB0: blinking cursor | ||
+ | # | ||
+ | LCD_MOVE = 0x10 # DB4: move cursor/ | ||
+ | LCD_MOVE_DISP = 0x08 # --DB3: move display (0-> move cursor) | ||
+ | LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left) | ||
+ | # | ||
+ | LCD_FUNCTION = 0x20 # DB5: function set | ||
+ | LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode) | ||
+ | LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line) | ||
+ | LCD_FUNCTION_10DOTS = 0x04 # --DB2: 5x10 font (0->5x7 font) | ||
+ | LCD_FUNCTION_RESET = 0x30 # See " | ||
+ | # | ||
+ | LCD_CGRAM = 0x40 # DB6: set CG RAM address | ||
+ | LCD_DDRAM = 0x80 # DB7: set DD RAM address | ||
+ | # | ||
+ | LCD_RS_CMD = 0 | ||
+ | LCD_RS_DATA = 1 | ||
+ | # | ||
+ | LCD_RW_WRITE = 0 | ||
+ | LCD_RW_READ = 1 | ||
+ | # | ||
+ | def __init__(self, | ||
+ | self.num_lines = num_lines | ||
+ | if self.num_lines > 4: | ||
+ | self.num_lines = 4 | ||
+ | self.num_columns = num_columns | ||
+ | if self.num_columns > 40: | ||
+ | self.num_columns = 40 | ||
+ | self.CursorY = 0 | ||
+ | self.CursorX = 0 | ||
+ | self.ImpliedNewline = False | ||
+ | self.Backlight = True | ||
+ | self.DisplayOff() | ||
+ | self.BacklightOn() | ||
+ | self.Clear() | ||
+ | self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC) | ||
+ | self.HideCursor() | ||
+ | self.DisplayOn() | ||
+ | # | ||
+ | def Clear(self): | ||
+ | self.hal_write_command(self.LCD_CLR) | ||
+ | self.hal_write_command(self.LCD_HOME) | ||
+ | self.CursorY = 0 | ||
+ | self.CursorX = 0 | ||
+ | # | ||
+ | def ShowCursor(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | | ||
+ | | ||
+ | # | ||
+ | def HideCursor(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) | ||
+ | # | ||
+ | def BlinkCursorOn(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | | ||
+ | | ||
+ | # | ||
+ | def BlinkCursorOff(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | | ||
+ | | ||
+ | # | ||
+ | def DisplayOn(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) | ||
+ | # | ||
+ | def DisplayOff(self): | ||
+ | self.hal_write_command(self.LCD_ON_CTRL) | ||
+ | # | ||
+ | def BacklightOn(self): | ||
+ | self.backlight = True | ||
+ | self.hal_backlight_on() | ||
+ | # | ||
+ | def BacklightOff(self): | ||
+ | self.backlight = False | ||
+ | self.hal_backlight_off() | ||
+ | # | ||
+ | def MoveTo(self, | ||
+ | self.CursorY = cursory | ||
+ | self.CursorX = cursorx | ||
+ | Address = cursorx & 0x3f | ||
+ | if cursory & 1: | ||
+ | Address += 0x40 # Lines 1 & 3 add 0x40 | ||
+ | if cursory & 2: # Lines 2 & 3 add number of columns | ||
+ | Address += self.num_columns | ||
+ | self.hal_write_command(self.LCD_DDRAM | Address) | ||
+ | # | ||
+ | def PutCharacter(self, | ||
+ | if character == ' | ||
+ | if self.implied_newline: | ||
+ | self.implied_newline = False | ||
+ | else: | ||
+ | self.CursorX = self.num_columns | ||
+ | else: | ||
+ | self.hal_write_data(ord(character)) | ||
+ | self.CursorX += 1 | ||
+ | if self.CursorX >= self.num_columns: | ||
+ | self.CursorX = 0 | ||
+ | self.CursorY += 1 | ||
+ | self.implied_newline = (character != ' | ||
+ | if self.CursorY >= self.num_lines: | ||
+ | self.CursorY = 0 | ||
+ | self.MoveTo(self.CursorY, | ||
+ | # | ||
+ | def PutText(self, | ||
+ | for C in text: | ||
+ | self.PutCharacter(C) | ||
+ | # | ||
+ | def custom_char(self, | ||
+ | location &= 0x7 | ||
+ | self.hal_write_command(self.LCD_CGRAM | (location << 3)) | ||
+ | self.hal_sleep_us(40) | ||
+ | for i in range(8): | ||
+ | self.hal_write_data(charmap[i]) | ||
+ | self.hal_sleep_us(40) | ||
+ | self.MoveTo(self.cursor_y, | ||
+ | # | ||
+ | def hal_backlight_on(self): | ||
+ | pass | ||
+ | # | ||
+ | def hal_backlight_off(self): | ||
+ | pass | ||
+ | # | ||
+ | def hal_write_command(self, | ||
+ | raise NotImplementedError | ||
+ | # | ||
+ | def hal_write_data(self, | ||
+ | raise NotImplementedError | ||
+ | # | ||
+ | def hal_sleep_us(self, | ||
+ | time.sleep_us(usecs) | ||
+ | # | ||
+ | # | ||
</ | </ | ||
Line 525: | Line 673: | ||
</ | </ | ||
- | ==== Library-Module: | + | ==== Library-Module: |
- | <code python> | + | |
- | </ | + | |
- | + | ||
- | ==== Library-Module: | + | |
- | <code python> | + | |
- | </ | + | |
- | + | ||
- | ==== Library-Module: | + | |
- | <code python> | + | |
- | </ | + | |
- | + | ||
- | ==== Library-Module: | + | |
<code python> | <code python> | ||
# | # | ||
+ | import machine | ||
import time | import time | ||
# | # | ||
- | class CLCDisplay: | + | import Define as DEF |
- | # HD44780 | + | import Thread as THR |
- | | + | import LCDisplayI2C as LCD |
- | | + | # |
+ | class CCommandDisplay(): | ||
+ | | ||
+ | self.LCDisplay | ||
+ | | ||
# | # | ||
- | | + | |
- | | + | |
- | LCD_ENTRY_SHIFT = 0x01 # --DB0: shift | + | |
# | # | ||
- | LCD_ON_CTRL = 0x08 # DB3: turn lcd/cursor on | + | class CClear(CCommandDisplay): |
- | | + | |
- | | + | |
- | LCD_ON_BLINK = 0x01 # --DB0: blinking cursor | + | |
- | # | + | |
- | LCD_MOVE = 0x10 # DB4: move cursor/ | + | |
- | LCD_MOVE_DISP = 0x08 # --DB3: move display | + | |
- | LCD_MOVE_RIGHT = 0x04 # --DB2: move right (0-> left) | + | # |
- | # | + | class CWrite(CCommandDisplay): |
- | | + | def __init__(self, |
- | LCD_FUNCTION_8BIT = 0x10 # --DB4: set 8BIT mode (0->4BIT mode) | + | |
- | LCD_FUNCTION_2LINES = 0x08 # --DB3: two lines (0->one line) | + | self.Row = row |
- | | + | self.Col = col |
- | | + | self.Text = text |
- | # | + | |
- | | + | def Execute(self): |
- | LCD_DDRAM = 0x80 # DB7: set DD RAM address | + | self.LCDisplay.MoveTo(self.Row, self.Col) |
- | # | + | self.LCDisplay.PutText(self.Text) |
- | LCD_RS_CMD = 0 | + | |
- | LCD_RS_DATA = 1 | + | # |
- | # | + | class CThreadDisplay(THR.CThread): |
- | LCD_RW_WRITE = 0 | + | |
- | LCD_RW_READ = 1 | + | |
- | # | + | |
- | def __init__(self, | + | |
- | self.num_lines = num_lines | + | |
- | | + | |
- | | + | |
- | self.num_columns | + | |
- | | + | |
- | self.num_columns | + | |
- | | + | |
- | self.CursorX = 0 | + | |
- | self.ImpliedNewline = False | + | |
- | self.Backlight = True | + | |
- | self.DisplayOff() | + | |
- | | + | |
- | | + | |
- | self.hal_write_command(self.LCD_ENTRY_MODE | self.LCD_ENTRY_INC) | + | |
- | | + | |
- | self.DisplayOn() | + | |
# | # | ||
+ | def __init__(self, | ||
+ | super(CThreadDisplay, | ||
+ | self.I2CDisplay = i2cdisplay | ||
+ | self.LCDisplay = lcdisplay | ||
+ | self.CommandList = [] | ||
+ | return | ||
+ | # | ||
+ | def OnStart(self, | ||
+ | return | ||
+ | def OnBusy(self, | ||
+ | while (THR.stBusy == thread.State): | ||
+ | self.Clear() | ||
+ | Col = 0 | ||
+ | while (Col <= 19): | ||
+ | self.Write(0, | ||
+ | self.Write(1, | ||
+ | self.Write(2, | ||
+ | self.Write(3, | ||
+ | while (0 < len(self.CommandList)): | ||
+ | Command = self.CommandList.pop(0) | ||
+ | Command.Execute() | ||
+ | time.sleep(0.5) | ||
+ | Col += 1 | ||
+ | if (THR.stBusy != thread.State): | ||
+ | break | ||
+ | return | ||
+ | def OnAbort(self, | ||
+ | return | ||
+ | def OnEnd(self, thread): | ||
+ | return | ||
+ | # | ||
+ | def Open(self): | ||
+ | self.Start() | ||
+ | return | ||
+ | def Close(self): | ||
+ | self.Abort() | ||
+ | return | ||
+ | # | ||
def Clear(self): | def Clear(self): | ||
- | self.hal_write_command(self.LCD_CLR) | + | self.CommandList.append(CClear(self.LCDisplay)) |
- | | + | |
- | self.CursorY = 0 | + | def Write(self, row, col, text): |
- | | + | self.CommandList.append(CWrite(self.LCDisplay, row, col, text)) |
+ | return | ||
# | # | ||
- | def ShowCursor(self): | + | # |
- | | + | # |
- | | + | if (' |
+ | print('*** CheckEsp32DisplayKey: | ||
# | # | ||
- | | + | |
- | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) | + | |
+ | DEF.LCDISPLAY_COUNT_ROWS, | ||
+ | TD = CThreadDisplay(I2CDisplay, | ||
+ | TD.Open() | ||
# | # | ||
- | | + | |
- | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | | + | |
- | | + | |
# | # | ||
- | | + | |
- | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY | | + | |
- | | + | |
# | # | ||
- | | + | |
- | self.hal_write_command(self.LCD_ON_CTRL | self.LCD_ON_DISPLAY) | + | |
- | # | + | |
- | def DisplayOff(self): | + | |
- | self.hal_write_command(self.LCD_ON_CTRL) | + | |
- | # | + | |
- | def BacklightOn(self): | + | |
- | self.backlight = True | + | |
- | self.hal_backlight_on() | + | |
- | # | + | |
- | def BacklightOff(self): | + | |
- | self.backlight = False | + | |
- | self.hal_backlight_off() | + | |
- | # | + | |
- | def MoveTo(self, | + | |
- | self.CursorY = cursory | + | |
- | self.CursorX = cursorx | + | |
- | Address = cursorx & 0x3f | + | |
- | if cursory & 1: | + | |
- | Address += 0x40 # Lines 1 & 3 add 0x40 | + | |
- | if cursory & 2: # Lines 2 & 3 add number of columns | + | |
- | Address += self.num_columns | + | |
- | self.hal_write_command(self.LCD_DDRAM | Address) | + | |
- | # | + | |
- | def PutCharacter(self, | + | |
- | if character == '\n': | + | |
- | if self.implied_newline: | + | |
- | self.implied_newline = False | + | |
- | else: | + | |
- | self.CursorX = self.num_columns | + | |
- | else: | + | |
- | self.hal_write_data(ord(character)) | + | |
- | self.CursorX += 1 | + | |
- | if self.CursorX >= self.num_columns: | + | |
- | self.CursorX = 0 | + | |
- | self.CursorY += 1 | + | |
- | self.implied_newline = (character != '\n') | + | |
- | if self.CursorY >= self.num_lines: | + | |
- | self.CursorY = 0 | + | |
- | self.MoveTo(self.CursorY, | + | |
- | # | + | |
- | def PutText(self, | + | |
- | for C in text: | + | |
- | self.PutCharacter(C) | + | |
- | # | + | |
- | def custom_char(self, | + | |
- | location &= 0x7 | + | |
- | self.hal_write_command(self.LCD_CGRAM | (location << 3)) | + | |
- | self.hal_sleep_us(40) | + | |
- | for i in range(8): | + | |
- | self.hal_write_data(charmap[i]) | + | |
- | self.hal_sleep_us(40) | + | |
- | self.MoveTo(self.cursor_y, | + | |
- | # | + | |
- | def hal_backlight_on(self): | + | |
- | pass | + | |
- | # | + | |
- | def hal_backlight_off(self): | + | |
- | pass | + | |
- | # | + | |
- | def hal_write_command(self, | + | |
- | raise NotImplementedError | + | |
- | # | + | |
- | def hal_write_data(self, | + | |
- | raise NotImplementedError | + | |
- | # | + | |
- | def hal_sleep_us(self, | + | |
- | time.sleep_us(usecs) | + | |
# | # | ||
# | # | ||
Line 690: | Line 782: | ||
+ | |||
+ | ==== 211225 : " | ||
+ | * {{: | ||
==== 211224 : Versuch zur Thread-Entkopplung ==== | ==== 211224 : Versuch zur Thread-Entkopplung ==== |
module/micropython/esp32displaykey/esp32displaykey.1640437814.txt.gz · Last modified: 2021/12/25 15:10 (external edit)