Can you point a noob to some good resources on how to get started building apps on NETMF? Specifically, I am building on Gadgeteer, but the question is less about specific hardware.
I am comming from a server dev background and have some client app building experience (Silverlight, etc). In that world, there are design patterns such as MVVM, MVC, etc. As I start building apps in NETMF, I find myself having a lot of spagetti code in program.cs that I then start trying to “farm” out into various classes and class libraries. But is there some good guidance on best approach?
I am thinking Micro device development is similar to game development needing game design patterns, no? Any advice is welcome. I’d love to see a healthy thread on this, as there are plenty code samples, but not many well structured app examples. I am certain there is a better approach than to start coding, then refactoring, and coding some more.
@ neoscoob - Welcome to the community!
I wish I could point you to a great source of what you’re looking for but there just isn’t a place that I know of that has really documented the patterns well. So, I’ll start this off with a simple pattern that coming from a desktop dev world is probably going to break your heart
Global variables are your friend. Everything on micros is about consuming less memory, avoiding garbage collection, and reducing CPU cycles. You’ll find that using static global variables to hold resources and memory buffers is a very common pattern used to avoid initializing & disposing of variables (& GC…). It’s way past my bedtime. If I need to explain more let me know and I’ll dig into it deeper tomorrow.
ian, this is really great info, thank you. I thought I was “cheating” as I started using more global vars, but I can see wisdom in it.
What are some thoughts on my “game design” patterns suggestion? I mean, most apps are based on a clock/timer, and take action in some sort of loop, no? Though even this I failed at one prototype, causing UI and user input lag when something is happening such as a servo moving (despite my threading efforts).
I’d love to see how other folks assemble apps end to end. And I completely agree, not a lot of resources on this topic, so if we can build out a great thread here, thats a start!
I’ve never really attempted to write any games but we have some folks on this forum that are great at it and have done some truly spectacular work. Hopefully, some of them will chime in with those tips.
One thing you always have to keep in mind is that GC will happen and it will create a ~200ms lag when it does. There’s no way to avoid it. So, if you’re doing something that can’t cope with that then GHI has given us RLP as a way to write code that sits below NETMF that isn’t impacted by GC. Perhaps a good way to learn would be for you to post the code you had problems with and we can tear it apart and make suggestions?
Well… If you’re careful to not allocate/free stuff during critical times and force GC beforehand, it’s not that bad… It’s not “realtime” but it’s not bad.
I did a lot of work around this when making a Spider run my (very fast) 3D printer… Once you hit the “print” button, it dosen’t allow you to do much except abort the print but it behaves quite nicely while the machine’s printing. It’s been months since I’ve looked at this but am tempted to say I could run an hour print without seeing the GC run at all or maybe running a once/twice for a few ms each…
It took some planning and some thinking about things differently than I’m used to (also coming from the server world) but was happy with the way it worked.
@ ddurant - Agreed. It’s quite possible. My point though was that it will happen at some point and his “pattern” of thinking should take that into account depending on his project.
@ Josh - Oooh!!! I love how the posts are back below the reply on the edit page
@ ddurant - Agreed. It’s quite possible. My point though was that it will happen at some point and his “pattern” of thinking should take that into account depending on his project.[/quote]
Then I agree with you after all!
One emerging pattern with NETMF/Gadgeteer is pairing a small dedicated microprocessor to handle realtime tasks while leaving the mainboard CPU to handle event dispatching, UI, and non-time critical tasks. GHI’s newly announced Open Daisy Link will make that easier - the Cortex M0 is capable of doing many things besides running the Daisy Link protocol, and there’s an easily accessible toolchain. It’s lower level code but sometimes it’s less work to write a bit of C than to fight the GC.
One benefit of NETMF is that you can develop using familiar coding conventions, which increases your code’s maintainability. If you do run into perf bottlenecks, then you can employ memory optimizations/GC avoidance, etc.