Netduino home hardware projects downloads community

Jump to content

The Netduino forums have been replaced by new forums at This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Suggestions for program structure - "modes" - threads etc

c# enums mode code structure visual studio threading threads

  • Please log in to reply
No replies to this topic

#1 gismo


    Advanced Member

  • Members
  • PipPipPip
  • 110 posts

Posted 23 December 2013 - 06:00 PM

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.

Also tagged with one or more of these keywords: c#, enums, mode, code structure, visual studio, threading, threads

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.