Main Site Documentation

Request for inspiration: NETMF design pattern for device access


#1

Hi again

I have been thinking about refactoring some of my projects in the context of porting it to 4.3 anyway.

But the same challenge pops up again and again.

Access to devices.

For the example, lets take a “Character Display” -module that we need to print to from different classes. Its instantiated somewhere and you can send a reference to it in a constructor, and then print as you like. But the display messes up because of multi-threading, so you need to wrap it in a lock or something.

I have had a look at some codeshare projects, but no-one really has a brilliant solution to enabling global access to a device, and i controlled manner.

Any golden nuggets that I need to look at?


#2

I have a small framework for char display (+ optionally rotary switch)
By this I can created “pages”, which are basically a list of strings (to support more than two lines).
I can create multiple pages, and activate one or another.
Changes to the pages uses a lock, to prevent multi thread confusion.
The active page writes it’s contents to the display if it’s changed or gets active.
I even have “self updating pages” for current date time.
Another type of page is a menu entry, which accepts an up, down or select event.
By this it switches to the next/previous menu page, or enters a sub menu.
There are also pages for networking info like IP address, gateway, …

The pages could also be used to switch between different subsystems by a timer.
Each sub-System (or internal thread) could have it’s own page.


#3

I usually just create a static object with a static method that can be accessed globally. In the method I put a lock around the thing I want controlled. That way any thread from anywhere can call this static method to update the display. In the constructor I put the code required to start the display so that the first call to the method will invoke the startup if needed.


#4

For this kind of thing, I sometimes create a thread that the display would run on. It reads from a queue and displays each item on the queue. The display handles enqueue and dequeue methods. Adding to the queue can be done from any thread in the system by making the enqueue method of the display thread safe.


#5

@ all posters - Great stuff, thanks! : ;D


#6

check out Skewworks code Pixy and the likes you will get a very good implementations from there…

cheers,
Jay.,