Idea is to replace interrupt handler for each setup screen, which seems to work fine, but initial interrupt handler:
Code: Select all
self.xpt.int_handler = self.first_press
Code: Select all
def first_press(self, x, y):
""" If touchscreen is pressed, change status """
gc.collect()
# self.display.clear()
self.touchscreen_pressed = True
Code: Select all
async def run_display_loop(self):
# TODO: Initial welcome screen?
# await self.show_welcome_screen()
# NOTE: Loop is started in the main()
while True:
if self.touchscreen_pressed is True:
if self.setup_screen_active is False:
# First setup screen
self.draw_setup_screen()
else:
# Draw setup screen just once
# TODO: screen timeout
pass
elif self.touchscreen_pressed is False:
rows, rowcolours = await self.show_time_co2_temp_screen()
await self.show_screen(rows, rowcolours)
rows, rowcolours = await self.show_particle_screen()
await self.show_screen(rows, rowcolours)
rows, rowcolours = await self.show_status_monitor_screen()
await self.show_screen(rows, rowcolours)
await asyncio.sleep_ms(1)
I tried to change screen update so that instead of using await asyncio.sleep I had a counter for each millisecond, which checked is touchscreen pressed (= interrupt handler), but behavior was same.
Documentation https://docs.micropython.org/en/latest/ ... rules.html explains "As mentioned above, ISR’s should be designed to be as simple as possible. They should always return in a short, predictable period of time. This is important because when the ISR is running, the main loop is not: inevitably the main loop experiences pauses in its execution at random points in the code." and this is true, because if I long press touch screen digitizer, screen update slows down, but the interrupt handler function is not activated.
Is there better ways to implement interrupt handlers or is my logic wrong?