I’ve been getting started learning the Rust language, and thought I’d share some my initial take-aways.
I’m an embedded developer, and most of the code I write for work is in C. As I’ve mentioned before, I’m particularly interested in Rust as it’s a systems language that might one day be a suitable replacement for C/C++ in my everyday work. Read more on Trying out Rust – Packages, Upgrades, & Security…
On a recent project I needed to fairly accurately measure current and power consumption of a handful of parts in real time. We needed to measure current in the range of micro amps, so this was actually somewhat tricky.
I could have just used a bunch of super expensive current meters, but I managed to find a much more convenient and cheap solution using a Raspberry Pi. We were already using a Pi to allow for remote debugging, so I went looking for something I could hook up to that.
I found these ADCs:
They plug right into the GPIO headers on the Pi and even come with some python libraries for reading them.
Read more on Using the Raspberry Pi as a Simple Current and Power Meter…
I recently wanted to get the Haskell SDK bindings running on windows. It was a bit trickier than I thought it would be — mostly due to a terrible macro SDL used to redefine the
main() function. I used the SDL 1.2 bindings as they’re a little more mature than the SDL 2 bindings, which are pretty much brand new. Here is how I got things working:
1. Install the Haskell Platform
Download and run the installer from the Haskell website.
2. Get the msys Base Environment
mingw-get-setup.exe from the MinGW website and run it. You should only have to select the msys-base meta-package (which will install several other packages). Then from the menu, select “Installation” -> “Apply Changes” and press the “Apply” button to download and install. Once the changes are applied, you can close the installer. Read more on Haskell SDL Bindings on Windows…
While writing some ruby scripts to handle asynchronous messages to and from some external hardware I ran into a problem. I wanted to wait on a queue of responses until I either got a response, or a timeout expired. Unfortunately this turned out to be a bit harder than I expected. The two most common answers when I search for “ruby queue pop with timeout” or “ruby queue timeout” are to either use some variant of “run it in a separate thread and toss in an exception when you want to stop” (such as ruby’s Timeout), or to use the non-blocking pop, with something like:
Read more on Ruby Queue Pop with Timeout…
In many languages, when you are unsure of a particular detail of the language, you can often “just run it” and see what happens. This might work in another language, but in C this will almost certainly bite you. It’s too easy to to accidentally invoke “undefined behavior”, where your code might do one thing in one case, but something totally different in another, without even getting a warning from the compiler.
Here are a few undefined behaviors you might not know about, along with the relevant section from the C99 spec. These aren’t just pedantic ramblings; they’re all cases that I’ve encountered on real projects out in the wild. Read more on Undefined Behaviors in C that You’ve Probably Run into without Knowing It…
I recently wanted an ethernet JTAG adapter for a project I was working on. Unfortunately ethernet JTAG adapters can cost upwards of $300, and even then they can be specific to particular chipset and toolchains.
However, were already using OpenOCD with ST-LINK/V2 programmers to communicate with out hardware, and it turns out that it’s very easy to set up OpenOCD on the Raspberry Pi. You can then plug the programmer into the Pi, connect a debugger (gdb in our case) to the OpenOCD instance, and debug your firmware remotely! Read more on Inexpensive Ethernet JTAG Adapter with Raspberry Pi and OpenOCD…
Setting up high-quality font rendering in a memory-constrained embedded system sounds like it would be hard. However, like many other problems in embedded systems, this one has pretty much already been solved by game developers. It turns out that getting proper font rendering, with kerning and all, can easily be done in a day’s work.
The game development communities are actually a great place to look for a lot of algorithms. Anything with graphics (even simple things like fonts), geometry/spatial algorithms (collision detection/prediction), or physical simulations have all gotten a lot of attention from the game developers. And their solutions are often mindful of memory and realtime constrains, which are of particular interest in embedded systems.
My particular use case is rendering text to a tiny black and white display (smaller than 150×50) in a resource-constrained environment (32k of RAM total) written in C. Read more on High-Quality Font Rendering for Embedded Systems…
I’ve made several toy games with friends, but whenever it came around to adding some simple multiplayer support, getting the networking running was always a royal pain. It seemed like each game had so many special cases for how game-state needed to be synchronized between players that it was impossible to decouple the netcode from the game logic. I wished for a network library that could handle all the state synchronization for me, but I could never find one.
The trouble is that most existing “game networking libraries” are actually mostly data transport protocols (built over UDP). These help ship the data to its destination more responsively than TCP and more reliably than UDP, but usually don’t help much with the coordination/synchronization of game-state between players. So I decided to make one myself! And I did! (It only took me 3 years; turns out it’s kinda tricky.)
I have a simple, working, and hopefully actually useful implementation at github. Read more on Game Networking Made Easy…
So you’ve been studiously committing your changes early and often only to discover that, for whatever reason, you really wished you’d been committing your changes to a different branch. Now what do you do? Is there a way we can just move unpushed changes onto a new branch? Actually, Yes!
1. Make a Backup
First of all, in order to do this we’re going to need to use the mercurial rebase extension to essentially re-write (unpushed) commit history. Rebasing is one of the few mercurial commands that can irreversibly destroy changes. Fortunately, we can easily create a convenient backup by just creating a local clone of the repository.
Make sure you don’t have any uncommitted local changes, and then do:
hg clone path/to/original path/to/backup/
Now that we have a good backup, lets get started. Read more on Moving Unpushed Changes to a New Branch with Mercurial…
I was recently working on a project where I needed to be able to tell (in an automated way) if the versions of two builds matched. The project provided version info that consisted of a manually hardcoded version number and timestamp of when the source was built. This was problematic. The manual version number was incremented rarely and so was useless for day-to-day development. And the timestamp would only tell you when that particular build was generated but not what source was used to generate it. This made it difficult to trace down bugs as it was nearly impossible to know for sure what source a build was generated from.
So I set about to come up with a good replacement.
What Makes Version Information Useful?
Here are the things we wanted from version information:
- Determine if two builds come from the same source (even if built on different machines, at different times).
- Easily find the code associated with a particular build.
- Easily determine approximately how old a build is; compare age of versions.
- Provide an easy mechanism for the user to tell different versions of builds apart.
Read more on Creating Automated Build Versions During Development…