Emulator for BrainPad?

  1. Any plans to build one?
  2. Is full support even possible? I saw GameO emulators, supporting N18 display and buttons. What about buzzer and temperature sensor?

A very good idea

@ Gus - Already exploring possibilities… Looks like there’s no PWM support in emulator. This will make RGB light and buzzer emulation tricky, and traffic lights are problematic, too, since current driver is based on PWM (but at least it could be changed, giving up the possibility to dim. Dimming isn’t very useful on traffic lights anyway, IMO).

Yes and no! You only need to emulate the brain pad interface, the class we provide. It can be whatever in the back.

So when should I except to see it done, Santa is asking.

Emulator does not support neither AnalogIn nor PWM. It does support I2C and SPI though, so (maybe) an option would be to create a virtual I2C device in emulator, that mimics acceleratometer, temperature sensor and buzzer. That would still require some internal modifications of the driver object. Is it sealed already? I see some consistency issue there…

I think you are thinking about this on too low a level. As Gus was suggesting, just reproduce the wrapper classes. Emulation close to the metal (at the I2C level) would be useful for custom apps created without the BrainPad.cs wrapper class, but that’s probably unnecessary given the educational role for this board.

You can create an emulator version of BrainPad.cs and attach the methods and accessors on those classes to GUI elements.

@ mcalsyn - you’re missing the point — you cannot wrap anything inside a NETMF app that actually emits sound on the PC. NETMF app doesn’t have access to such resources, but the [em]emulator does[/em], because it is a stand-alone [em]WPF program [/em]that can interact with [em]NETMF program[/em]. Emulation of the GPIO, I2C and SPI is easy, because they are built in into standard NETMF emulator, while AnalogIn and PWM is not. So there is no easy way to dim a LED, represented as a Rectangle class in the WPF program. Extensions needed.

Maybe I am missing something - I’ve only done two other emulators and that was a while ago and I do recall having to extend the emulator classes, though I don’t recall it being that difficult. Seems to me that the emulator was designed for that type of extensibility. Again, it’s been a while, but later this week I will dredge up my code and look into it again if it still seems to be a blocking issue.

The end user will not use pwm at all, not for the first courses anyways. All you need is your own version of the brain pad class that emulate the features, like dim the lights, without any pwm behind.

Looks like we really do not understand each other of what ā€œBrainPad emulationā€ is.

@ Simon from Vilnius - I understand but I was giving an much easier alternative. Within can still be used for most courses.

@ Gus - Well, I have it cracked… With driver modifications like this one:

    /// <summary>
    /// Controls the Light Sensor on the BrainPad.
    /// </summary>
    public static class LightSensor {
        private static AnalogInput _ain;

        static LightSensor() {
            if (isRunningInEmulator) return;

            _ain = new AnalogInput((Cpu.AnalogChannel)9);
        }

        /// <summary>
        /// Get the level of brightness.
        /// </summary>
        /// <returns>A value respresenting the level of brightness.</returns>
        public static double GetLevel() {
            if (isRunningInEmulator) {
                var readBuffer = new byte[2];
                _emulatorI2c.WriteRead(new byte[] { 1 }, ref readBuffer);
                return readBuffer[0] + readBuffer[1] * 256;
            } else {
                return _ain.Read();
            }

        }
    }

I can make a full-featured NETMF BrainPad emulator. The question is whether you want it or not…

3 Likes

Already said it is a great idea, yes please :slight_smile:

That was exactly what I meant by ā€˜higher level emulation’.

Almost there…

Only Buzzer and LCD remains. Buzzer is surprisingly tricky, since Console.Beep() function is blocking ant there’s no way to kill it. Anybody knows another easy way to emit sound in PC?

5 Likes

LCD support!!!

What’s left is the buzzer and touch pads. While I can make at least a rudimentary support for buzzer, there’s probably no way I could emulate touch pads, since they require GHI.Hardware library. Not sure what to do here. Omitting touch pads will require physical removal of related code, or the driver will not be easily switched between real device and the emulator. Adding conditional compilation might be an option, but I guess that would not be very educational… :think:

5 Likes

This is just fantastic. I am going to need to add a course or two using the emulator. I just need it first :wink:

If I was looking for a real quick and dirty way to solve this, I would try the following…

  1. Create a MemoryStream and write a wav file to it, dynamically generate the PCM data for a one or two cycles of the sound based on the PWM frequency duty cycle etc.
  2. Pass the MemoryStream to System.Media.SoundPlayer and call PlaySoundLooping.

I cannot test this right now, I just prepped my machine for tomorrows Visual Studio 2015 release so no tools installed yet.

I am not sure if you will get a glitch between cycles as the sound loops, so you could improve that by generating a few cycles as PCM data and then if it glitches you would be less often.

I would be interested in hearing how this works out and if you do not come right, I should have VS installed tomorrow and I will happily throw together a sample of what I am thinking here.

@ taylorza - At what time do you expect the final VS2015 files are available for download. I only found a starting time for the Show: 8:30 PDT if I remember correctly.

@ Reinhard Ostermeier - I do not have a specific expectation, I will pull it from MSDN as soon as it is available. Since it is going to be during the week, when I normally spend less time at the computer, I wanted to get my machine prepped beforehand.

I like a new clean machine for these things and due to a recent robbery I decide to take the opportunity to limit the amount of hardware I have scattered around, so now I only have a solitary notebook. Trust me that is a first for me :slight_smile: I typically favor a desktop and I am sure I am going to breakdown and by one again at some point.

1 Like