Вопрос

I'm looking for some ideas as I'm trying to wrap my head around the best way to code menu navigation with one interrupt driven device. In particular a rotary encoder knob with a push button. The question is how to manage how the interrupt routines will change depending on the context of the menu/dislay. Also, what data types should I used to keep track of the menu etc.

I'm programming an embedded device with the NetMF framework in C#. The rotary encoder know will fire an interrupt/event when it's rotated and return the direction and timestamp. Also, the push button will fire another interrupt/event and return the timestamp.

A simple outline. Device will boot up and start in some default state. Then the user can rotate the knob to change the "mode". This is simple, to me. Now, when it comes to the user controlling the settings, It would be something like press and hold the momentary for 3 seconds. After 3 seconds it will switch into settings mode. Now, the rotary encoder will rotate through different settings. Scroll/rotate to the setting you want. Forwards or backwards. Then, press the button to enable editing the setting...again, change what the rotary encoder and button do. Maybe press and hold button for exit and save all settings. Menus may be nested.

Thinking aloud: Hardware Functions are Change-Setting-To-Edit(rotate), Enter specific Setting/forward/deeper into menu(button), Change Setting Value(rotate), Save Setting(button), Go-Back(button), Save-All and exit to Main Mode. Each Setting "Page" or display could have a forward and back indicator that can be selected with the Rotary encoder.

Anyway it flows, I'm looking for a way to keep track of the menus and the controls of the rotary encoder and so that it's easy to extend and read.

How do I manage all of the different functions of the Interrupt Event Handlers as I change menu contexts? Is there some way to have have a set of functions for each context? How Do I keep track of them?

Thanks!

REVISED BETTER QUESTION: How to pass native event handler for interrupt in state pattern code

Это было полезно?

Решение

What you are describing is a classic example of an event-driven state machine -- the events are handled differently depending on the current context (i.e. state). Check out QP for a framework that could suit you well. Or if that requires too much of an investment then Google for more traditional ways of implementing a state machine.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top