So I started writing the MPF interface for the OPP hardware. Brian offered to write the interface, but I know a lot more about the OPP hardware so I think that it is just as easy for me to write it and get it correct and optimize it properly. I didn’t want to get into a situation where Brian spent a bunch of his time, I looked at the code and wasn’t happy with it, and rewrote it myself. That would waste both of our time.
Installing MPF did not go as smoothly as possible. MPF assumes that it is the first time that Python, Pygame, and PySerial are installed on a machine. I had older versions of all three of these programs, so when I tried to start the demo machine in MPF it failed. “DLL load failed: %1 is not a valid Win32 application.” I’m was thinking to myself, oh great, I’ve just set myself on a couple day hunt and peck to try and figure out what went wrong. Luckily it simply required uninstalling PyGame and reinstalling it again over the the new version of Python. (I blame this issue on upgrading from Python 2.7.6 to 2.7.10). I then had trouble running TK. (import TKinter was giving the same issue as above.) I uninstalled Python 2.7.10 and reinstalled it again, and now I was able to import TKinter. MPF does not use TKinter, but my pinball framework uses it for running the debugging window. I was happy to see that I could now run both frameworks successfully. Last configuration change I had to make was to allow Python connections through my computer’s firewall. MPF BCP connect sockets using a local loopback connection. These were actively rejected on my laptop (Win 7 Enterprise Edition), so I had to Control Panel->System & Security->Windows Firewall->Allow Program Through Firewall, and browse to c:\Python27\python.exe.
Woo, hoo. Up and running with the demo machine executing. That was actually relatively painless. (A couple more error checks could be used in the install script, but it does clearly state that the script assumes that no previous version of Python, PySerial and PyGame are installed.)
The thing in MPF that is used to support actual hardware is called a platform. There isn’t currently any information on writing your own platform file, so you basically look at previous examples of platform files, and reverse engineer what they return to the rest of the framework. There are already platform files for the FAST and the PROC and P3-ROC platforms. They support some of the same functions that I support in the OPP hardware. I based the OPP platform file off the FAST platform file. I don’t think it would have changed things significantly to base the file on the P3, but I happen to choose the FAST file. It is going well, but the new platform file isn’t done being written yet.
One thing that I do miss using C, C++, C#, etc is that it is very easy to define an interface. Python does not really have any concept of what an interface is. It also has the added benefit that if somebody calls your object, expecting a certain function and it doesn’t exist, it just crashes. (Yeah, no type checking because that would restrict how things could be used) Do you get a compiler error, oh no. That wouldn’t be the Pythonic way to have to know what type of object you are talking to. Instead it simply gives a back trace dump. Hopefully all the functions are called frequently enough that I can easily find all the interface errors.
So, first thing I have to say about the MPF is that the documentation is really great, especially for a beginner. Within a couple of hours, I was easily able to get a simple machine working that would do an attract light show, flip through my attract slides, and start a three ball game. Most of that is built right into the framework which is really nice. If you are following the tutorials, everything works really well. In the tutorials, some of the background processing is explained which makes extending the example and modifying it to your liking easy.
When you get to the end of the tutorials, things become a little rougher around the edges. I was not willing to dig into the core MPF code, but had some difficulties doing some very simple things. There are currently no tutorials on playing sounds. From programming my pinball framework, I knew this functionality should be very simple to get at using Pygame. My main problem was that I didn’t know how to do it in MPF. I immediately went to the forums but had difficulty finding information. It was great that MPF has forums, but they aren’t very useful at this moment because they aren’t searchable. After a day or two of mucking around, I finally figured out how to get it to work, so I could play a sound at the start of a mode.
I am planning on moving all of the SS3 rules over to MPF and posting the final files. Hopefully this will give others a working example of running a full featured pinball machine using MPF. This little exercise should force me to examine the differences between the two pinball platforms.
One major thing that needs to happen is that the MPF forums need to be made searchable. I remember seeing a post that was related to something that I was putting off implementing, and even after going back and searching for a few hours, I could never find it.
Here are two quick pictures of comparisons between running the OPP framework and MPF. I will describe more of the differences in a later post.
One quick thing to note is the jaggedness of the score font. Both of the frameworks are using the exact same true type font file. I might have to look into how MPF is generating its text. This is one area that the OPP framework was optimized for printing text because it is assumed that it is going to be used for scoring. The MPF framework puts much more emphasis on DMDs, and I think the code to display text is less mature.
When the OPP framework prints text, it is always right justified so it looks old style pinball displays. I haven’t found an easy way to get this to happen in the MPF framework. In MPF, the text anchor is always on the top left corner, so I will have to pre-process all scores to add extra spaces to get the text to not move as the score goes up. MPF also post-processes numbers and adds the commas automatically. That would be great, but in some cases, I don’t want to add commas to the numbers.