Ethan McTague

A Messy Project

For my 12th grade Computer Engineering final project, I decided to build a 3-D scanner. It didn't quite turn out as I had hoped due to time and hardware constraints, unfortunately, but it does work!

Here's the source code in all its messy glory.

Python and Decorators

The python script, meant to run on a Raspberry Pi, operates a stepper motor and ultrasonic sensor to measure the distance to objects surrounding it. Not the most impressive thing ever, but I was proud of this bit, one of the few times I've actually used decorators:

indlevel = 0

def task(name, resname):
    def func_decorator(func):
        def func_wrapper(*args, **kwargs):
            global indlevel
            print("%s[Begin %s]" % (("\t" * indlevel), name), file=sys.stderr)
            indlevel += 1
            result = func(*args, **kwargs)
            indlevel -= 1
            print("%s[End %s=%s]" % (("\t" * indlevel), resname, result), file=sys.stderr)
            return result
        return func_wrapper
return func_decorator

This decorator can wrap a function to assist in logging. It logs the beginning and end of a function's execution, as well as its result, in a perfectly indented tree.

Here's an example:

@task("Doing A Thing", "result")
def doThing():
    return 10.5

@task("Doing An Outer Thing", "result")
def doOuterThing():
        doThing()
        doThing()
        return 20.0

doOuterThing()
[Begin Doing An Outer Thing]
    [Begin Doing A Thing]
        [End result=10.5]
        [Begin Doing A Thing]
        [End result=10.5]
[End result=20.0]

This little decorator made debugging much, much simpler, because a single line above a function definition would allow me to see exactly when it's called and what it returns.

'HERE' strings in C++?

It turns out that C++11 adds a new type of string literal, and that I didn't even realize until I set out to work on this project! Wrapping a string in R"<delim>( and )<delim>" allows you to write raw, multi-line string literals, similar to here/EOS strings in other languages!

I used this to avoid implementing file loading for some shader files, instead embedding them at compile-time. To accomplish this, simply put the beginning and ending of the new string literal syntax at the start and ends of the file you want to embed, and then #include it:

embeddable.txt

R"HERE(
This is the text to be embedded!
Look, it's multiple lines!
Works like a charm!
)HERE";

main.cpp

std::string embeddedText =
#include "embeddable.txt"

Non-blocking stdin? Sorta...

I needed a game loop to run in parallel with reading from standard input. Unfortunately, there's no reasonable, reliable way to check for new input in a non-blocking manner.

It seems the best workaround is to spawn a thread that reads from standard input and notifies the main thread of new input. It works, as shown here, but the fact that it's just sorta killed mid-execution when the main thread needs to terminate is a little sketchy to me. If anyone has any idea how to cleanly kill off the input thread, please get in touch - ethan@tague.me.

inputThread = std::thread([&]
{
        float value;

        while (std::cin >> value) {
                lockNewData.lock();
                newData.push_back(value);
                notifyNewData = true;
                lockNewData.unlock();
        }
});
if (notifyNewData) {
    lockNewData.lock();
    // Handle new data from newData here!
    notifyNewData = false;
    lockNewData.unlock();
}
Monday, June 17, 2019 at 05:12 PM

The SX-64 Keyboard Cable

On EBay, replacement keyboard cables for the Commodore SX-64 can run around $20-30 before shipping costs are added in. Understandable for such an old and obscure item, right?

Wrong!

The SX-64 Keyboard cable is actually an ever-so-slightly modified version of a common connector: A D-Sub DB25 connector, used for older serial and parallel ports. In particular, it uses a male-male DB25 cable with an angled connection on one end, and (according to some sources) the metal sheathing of the connector removed on the other end. Some of the pins are also missing on both ends, but apparently, these don't need to be removed for replica cables to work correctly.

The total cost of parts needed to recreate this cable is approximately $3 - A regular DB25 male-female cable (because male-male cables are way rarer) and a small male-male adapter. Simply trim the sheathing off one half of the adapter piece, connect it into the female end of the cable, and you should be good to go.

An Update

It seems I misunderstood the steps needed for this - the plastic sheathing around one end of the connector need to be trimmed down, not the metal around the connector part. This is to permit it to fit. However, this is a tricky procedure - I couldn't trim it down properly.

Wednesday, May 01, 2019 at 03:13 PM

I've been working on this new site for about two days now. My goal was to develop a simple, yet usable blog entirely from scratch. It's made with one thing in mind: images. Text is secondary - the image content I post should be visible front and center without much obstruction.

Because of this goal, plenty of emphasis was placed on media management. The image management system for the blog was developed prior to the actual posting system, and allows images to be easily embedded into posts. Image information, such as accessible alternate text, is stored alongside the image and automatically inserted into the page when the image is embedded in markdown. This makes it possible to adjust the description for images that are used across multiple posts, if necessary, without editing each post. It also lets me implement new image viewing features (perhaps a zoomed-in view) without editing each individual post.

The entire system is implemented on the Google App Engine for simplicity. The Cloud Datastore is used for post and image data. The Google Cloud User System is used for authentication, allowing me to log in with a single click when I'm already signed into my Google account. You could log in, too, if you'd like! You couldn't actually do anything, though, only my account has administrator rights!

Wednesday, April 24, 2019 at 01:24 PM
Older Posts
Log In