Hey Guys,
I'm looking for a little feedback and discussion on how to structure the code for my project. Basically, my device reads a few sensors and displays the information on some LEDs. I want the user to have some control what's being displayed so I have an interrupt driven rotary encoder for the user to control it.
For discussion purposes I want the user to be able to change the "mode". Mode 1, Mode 2 Mode 3, Settings Mode.
In efforts to keep the code simple, scalable, and legible.. What are some of your ideas on how to accomplish this. I started with an enum type for the modes but I think there's a more elegant way. or mixing the enum with something else. I haven't addressed threading yet, but would like to see how it can be best implemented
Here's some starting point/pseudo code:
Void Main()initialize settings/pull settings from memoryinitialize LED driverinitialize rotary encoder//subscribe to rotation eventsRotaryEncoder.RotationEvent += rotationEventHandler;While(true){ReadSensors();if Mode==Mode1{DisplayMode1(sensordata);}else if Mode==Mode2{DisplayMode1(sensordata);}......else if Mode==Settings{//is this where I should use threading?StartSettingsMode()//<-what should this be? This is its own package and needs to unsubscribe the main program from the rotary encoder events and subscribe to new events/control methods for the settings.}}Void MainRotaryEventHandler(rotation value){//enums can't easily be decremented/incremented in netMF. Any other suggestions?if rotation==clockwiseincrement mode++elsedecrement mode--}SettingsModeThis will let users control display parameters, brightness, colors schemes, etc. All driven by same rotary encoder and momentary push button.
Thanks for taking some time and look forward to having a discussion about this.
Update: Investigating State Pattern and State Machine Code to accomplish this. Will post an update when progress is made.
Edited by gismo, 26 March 2014 - 02:33 PM.