cancel
Showing results for 
Search instead for 
Did you mean: 

How to detect period of user inactivity and lock screen?

M-Schiller
Associate III

Hello,

I am working on a Cortex M4 and I'd like to add some power-saving features to my program and figured I'd need to detect user activity. For this reason, I'd like to

  • detect if a user hasn't tapped the touchscreen for x [e.g. 5] seconds, and if so:
    • dim the screen's backlight as much as possible or, better yet, manually set the display to standby and disable touch sensing.
    • clock-down the MCU.
  • if a HW button is pressed, I'd like to wake the display back up again, and increase the clock again.

Furthermore, I created a dedicated "charging screen" (basically only an animated battery filling up some bars in a loop) from which I want to go to power-saving mode even when a user touches the screen in order to charge faster.

So, my questions are:

  • Where is the `TouchController::sampleTouch(...)` method even called? I haven't found it anywhere in the code...
  • Would the `TouchController` be the best place to put the logic for detecting inactivity?
  • If not, where should I best put this kind of code?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Michael K
Senior III

sampleTouch() is called from the pre-compiled TouchGFX library code, see attached stack trace. You could try adding a flag to TouchController that sets itself on a touch event and clears when read. Read that flag from the Model::tick() function and if too many ticks pass without the flag being set, send whatever signals you need to send to the backend to start the powerdown process, e.g. through an RTOS queue. I don't have experience with low power modes so I can't speak any further on it, good luck.

Embedded UI/UX Consulting: cadenza.design

View solution in original post

4 REPLIES 4
MM..1
Chief III

Simply timing you need place to model tick

and reset on any UI place .

Dim is based on your type of design.

When in sleep you do nothing then simply after timeout suspend rtos and stop mcu. (after LCD off)

Wakeup is more complicated , but basic method is make wathdog reset after wakeup and start sw as on power on...

M-Schiller
Associate III

> Simply timing you need place to model tick

How does the model know whether or not a valid touch was sampled? As far as I could see, the model doesn't know about the TouchController. Could you point me to where it could get sampled touches?

> and reset on any UI place .

Do you mean on any ...Presenter::activate()? If so, I have controls (e.g. sliders) that do not necessarily change screens when controlled. So, I think if a user uses these controls, the presenter couldn't reset the timer. Besides, I would like to have "aimless screen tapping" (not controlling any buttons or sliders) as a means to keep the display awake.

> Dim is based on your type of design.

Dimming in general isn't an issue, I use PWM to control the screen's brightness.

> When in sleep you do nothing then simply after timeout suspend rtos and stop mcu. (after LCD off)

>Wakeup is more complicated , but basic method is make wathdog reset after wakeup and start sw as on power on...

As "clean reset" seems difficult, I wanted to try and just reduce the clock for this, not necessarily suspend the OS. The clock is currently running at 168MHz, and I thought that waiting for an interrupt of a single HW button and not displaying anything on screen should be possible with quite a bit less.

Michael K
Senior III

sampleTouch() is called from the pre-compiled TouchGFX library code, see attached stack trace. You could try adding a flag to TouchController that sets itself on a touch event and clears when read. Read that flag from the Model::tick() function and if too many ticks pass without the flag being set, send whatever signals you need to send to the backend to start the powerdown process, e.g. through an RTOS queue. I don't have experience with low power modes so I can't speak any further on it, good luck.

Embedded UI/UX Consulting: cadenza.design
MM..1
Chief III

model tick only increment global timeout and when is bigger as limit suspend all as you need, model dont need info about touch, here only timo++ and if

when you use only touch as source of UI events then in I2C driver for touch receive place timo=0 8)