Emulator for BrainPad?

@ taylorza - Based on your suggestion, I quickly found an example here:[url]audio - Play dynamically-created simple sounds in C# without external libraries - Stack Overflow

Still a bit glitchy, but already works much better that Console.Beep! With some tuning, should work just fine. Thanks.

Buzzer — check 8)

Now, the only thing that is left is the touch pads. I would really, really, [em]really [/em]like to see them abstracted somehow. This is the only thing that is not compatible with vanilla-NETMF. Such compatibiity would be really great.

Can you model them as simple buttons? I know they have an analog threshold component, but most folks will use them as simple pushbuttons - either pressed or not-pressed.

@ Simon from Vilnius - maybe fake as analog inputs or buttons.

I cannot fake it, because it requires PulseFeedback class, which sits in GHI.Hardware.dll, which cannot be loaded into emulator (at least I’m not aware of how that could be done).

It has to be compiled away. Either removed completely, or with #if directives. Gus will veto the first option, and I’m not sure the second option can be done silently in the background…

What happens if you load PulseFeedback and the supporting assembly into the project, but never call it? If no constructors are called and there is no static initialization that relies on firmware, then it should sit there inert and you can use your same isInEmulator trick to call an alternate implementation.

[Edit: Just looked at the BrainPad source and it does initialize a static PulseFeedback. That would need to be made a lazy initialization. Move the initialization into a EnsureInitialized() method and call that method in every static member function. That function can do the correct initialization depending on whether you are in the emulator or not.]

@ mcalsyn - No luck:


    #### Exception System.NotSupportedException - CLR_E_NOT_SUPPORTED (2) ####
    #### Message: 
    #### GHI.Processor.Display::.cctor [IP: 0032] ####
An unhandled exception of type 'System.NotSupportedException' occurred in GHI.Hardware.dll

So much for that bright idea then.

The only solution that comes to mind is fairly complex : remove references to PulseFeedback in the BrainPad.cs file and move them into an interface-defined wrapper class. Create two assemblies with separate implementations of the wrapper definition - one that uses PulseFeedback and one that uses a non-PulseFeedback emulator class. At runtime, use the BrainPad class and isInEmulator to dynamically load the correct class. Use dynamic loading to avoid the static class constructors being called when in the emulator. GHI.Hardware won’t be initialized until it is dynamically loaded, which will never happen in the emulator.

[Edit: GHI.Hardware needs to be in the deployment manifest, but not referenced in the main program. It’s not immediately clear to me if that’s possible without stepping outside of the normal VS workflow - it may complicate things for the end user in an unacceptable way. Mechanically, this approach will work, but it may not be practical]

@ mcalsyn - Yeah, sounds pretty complicated. But it seems nobody knows am easier way… :think:

@ Simon
I would like to have your Emulator for my pupils home studies.
Do you have a download - link. I could not find it at GHI.
Thanks in advance!

@ mflume - I’ve stopped working on it because I was unable to find any easy solution for touch pads, which can’t really be emulated. Without them, emulator is not complete and I thus have no hope GHI would include it somehow in their SDK or teaching materials. Also, I’m not good at legal stuff, and so I did not release it publicly because I did not know how to decorate the driver code that I borrowed from GHI. But I could probably send you the whole project privately…

@ Simon from Vilnius - touch pads were removed from the new brainpads. More details on why this happened this in few days. Everything else is near identical. Your emulator is most welcome. We would love to add it to the brain pad support page if you are willing to share.

@ Gus - Alright then this changes things. Combined with the vsix project somebody uploaded a few days ago, we could make quite a solid BrainPad support package…

EDIT: I’ll just wait for those few days before doing anything, then.