Ordered a Raspberry Pi

If you haven’t heard of it, Raspberry Pi is a very interesting project to create an incredibly cheap but powerful computer. It was released on February 29th, and on that same day, I purchased a Model B ($35) through element14′s site. Due to overwhelming demand, I probably won’t actually get it for a while, but when I do, I’ll post an update on my blog about it. Because of the unbelievable value of the device, and not-too-shabby specifications, there are many potential applications for it. I plan on playing with it and potentially coding some really neat stuff in my free time. I’ll post further updates about the Raspberry Pi on my blog.

Significant LibreScribe Progress Made

As you may have noticed, I took a break from working on LibreScribe for a while, and the project looked as though it was abandoned. Well, it isn’t, and I’ve got tons of good news! Since the last time I wrote an update about LibreScribe, in late May, I made several incredibly significant changes. Some of these may not seem that exciting, but they are absolutely crucial in order to further develop the program. Some of these new features (such as retrieving and changing the name of the device) didn’t exist in libSmartpen at all, so implementing them required me to capture packets sent over USB and do a bit of reverse engineering. At first, I used the trial version of USBTrace, but I quickly realized that it wasn’t the tool for the job when I got notifications that I used more than my 256K data limit just by opening LiveScribe Desktop. To make it even less appealing, it costs $195 USD for a single license! That’s ridiculous! So of course, I did a bit of searching, and I found busdog, which does the same job (although using unsigned filter drivers that require modifying windows settings and rebooting several times) for free! Although getting it setup was significantly more frustrating than getting USBTrace working, it was well worth not paying $195, and it does everything I need it to, albeit without as nice of an interface. Anyways, here’s a list of significant changes I made:

  • LibreScribe no longer crashes when retrieving the list of applications installed on the device. This was incredibly frustrating when I was trying to develop it. It also filters out the LiveScribe Connect and System files, so that they are not listed if they are present on the device.
  • Instead of displaying a hard-coded list of notebooks, LibreScribe now retrieves the names of all of the notebooks actually in use on the device.
  • When a device is not present on the system, or LibreScribe can’t find it, the page tree now shows a “No Smartpen Detected” item, along with an brand new icon that indicates that no device is connected instead of the regular pen icon.
  • I added context menu event handlers to the page tree, so now when you right click or press the menu button, LibreScribe can display a menu of options relevant to the item you clicked. More work on this still needs to be done, but if you click the root element (the smartpen itself, or the placeholder when one isn’t connected), you will now see a new menu allowing you to rename the device, refresh the connection, or display information about the device.
  • When the device is unplugged or plugged in, the page tree and the applications/audio lists will now automatically refresh themselves.
  • LibreScribe now retrieves the name of the smartpen from the device, rather than defaulting to “My LiveScribe Smartpen”. It can also set the name of the pen, but this feature is still a little bit buggy (it won’t brick your device, so it’s safe to test). Interesting discovery: In the LiveScribe desktop software, you can set the name of the pen to anything up to 50 characters. This does not mean that the device doesn’t allow more than that, it’s just a ‘soft’ limit in the LiveScribe desktop software. There probably is an actual limit, but I was able to set the device name to almost a paragraph of text, including every symbol you can type on a standard US keyboard, and retrieving it from the pen worked perfectly. The pen stored the entire thing, and returned it when I checked the name, although it did not display the entire string when I turned the device on, just the first part of it. The string of text I tested was “~`!@#$%^&*()-_+={}[]:;”‘<>?/,.\ Testing the maximum name length for a LiveScribe Smartpen… I wonder if I could fit a paragraph in here…? You have got to be kidding me… I typed this much and it STILL works? That’s incredible. There’s virtually no limit to how long the smartpen’s name is. I can’t believe I can set and receive values this long! I’m speechless…“. Needless to say, you can store almost anything in the name of the Smartpen. I wonder how the LiveScribe desktop software would react if it tried to retrieve this string.
  • I added a dialog box to rename the device, as well as another dialog box to confirm the new name.
  • LiveScribe no longer crashes when removing or connecting a smartpen while the program is running.
  • I merged in the inline functions written by Luis Pedro Coelho on his fork of LibreScribe, which are a better implementation of device type checking than I had
  • Tons of new debugging output was added. You can see this output on the console. This makes figuring out what went wrong in a crash so much easier.

Remember, LibreScribe is still alpha quality and should not be used in a production environment. If you have any issues or suggestions, feel free to file a bug report. Or, if you’re skilled enough, I’d appreciate it if you fixed the bug yourself, and submitted a patch. Ah, the benefits of open source coding! This is only just the beginning. Expect tons of new enhancements and bug fixes over the next several months.

How To Make a Beeping Timer Using Bash Script and Ubuntu Linux

I had my wisdom teeth removed this morning, and I’ve more or less been bedridden with my laptop, so I decided to kill time and keep my mind off of the pain by writing a script to beep whenever I have to alternate between having ice on my face and vice versa. I’m supposed to switch between the two every 20 minutes, which is a pain to remember and keep track of, so why not have the computer do that for me? Most of the work is already done for me in readily available tools, like Linux‘s “date” command, and the MOC console audio player. The only “real” work I had to do was write a few simple conditional statements, look into command line arguments for the programs used (using man pages), and creating a beeping sound using Audacity. This took me less than 30 minutes total, and I figured someone somewhere might find it useful or interesting, so I decided to write a tutorial about it and describe how I did it. A lot of this is geared towards those without much programming experience, so it might be useful in teaching the basics of programming and turning logic into code. Note: I realize there is a “beep” command available, but my laptop does not have a built-in speaker that works with that, so this is a very easy alternative, and it’s more compatible, too.

Because the easiest step is creating the audio file, I’ll start with that. If you’re just looking for a short beeping sound, and you don’t feel like opening up Audacity, the file I used can be downloaded below.

Audio File Used: 440Hz Beep for 3 Seconds

This is actually incredibly easy. If you don’t already have Audacity, download and install it. Now open it up, and choose “Tone” under the “Generate” menu. For me, the settings I used were Waveform: Sine, Frequency: 440Hz, Amplitude: 1, Duration: 3 Seconds. This will quickly generate the beeping sound. Now you need to export this in a format playable by MOC. To do this, go to File > Export… and set the file type to “Ogg Vorbis Files“. Now save the file as something.ogg in the same directory you want the script to be in. For my script, the file name I used is “beep-440-3s.ogg”, but the name really doesn’t matter. I don’t recommend using spaces as you probably have to escape them in your script, which is a pain that can easily be avoided.

Now, if you don’t already have MOC console audio player installed, you need to install it (or another tool of your choosing) in order to play the audio file from the command line. To get MOC audio player in Ubuntu or Debian Linux, you can type the following command in a terminal, assuming the debian package “moc” is available in your configured software repositories:

sudo apt-get install moc

This method requires super-user (administrative) permissions, unfortunately, but that probably won’t be a problem for you. For more information on the sudo command, see Ubuntu Linux, Day 18: What Is This ‘sudo’ You Speak Of? (pcworld.com). Excuse me for a second, my timer just went off… now that we got that over with, let’s get started on coding the script!

Now, In my case, because I have to switch between ice and no ice every 20 minutes, there are three times that I switch between the two as 60 divided by 20 is 3. Because this is an odd number, the range minutes that I will or will not have a bag of ice on my face alternates every hour. To determine whether or not I should have a bag of ice on my face in a given 20 minutes, we can use the modulus operator, which is used to determine the remainder of a division operation. If the modulus operator returns a zero, then there is no remainder (obviously). By getting the remainder of dividing the number of the hour by 2, we can tell if the current hour is even if the remainder is zero. The way I wrote this script isn’t the most efficient way of doing this, but I wanted to create something that worked quickly without spending too much time on it. Also, yes, I realize I could’ve done something incredibly simple, like using the watch command to tell me when to alternate between ice and no ice, but this was more fun to code, mostly for practice, and it works for me. An example of how I would use the watch command instead is to have it wait 20 minutes (the argument ‘n’, which is the time to wait, is in seconds, so there are 1200 seconds in 20 minutes), and play the sound after that amount of time. This can be done with the following command from within the folder where the beep audio file is stored, substituting the duration and the file name with the ones you used/need:

watch -n 1200 mocp -l beep-440-3s.ogg

This will wait 20 minutes from the time of starting the command and then beep, repeating every 20 minutes. However, the title of this guide is “How To Make a Beeping Timer Using Bash Script and Ubuntu”, so I’m going to show you how to do that.

First, we’ll start with the obligatory shebang line:

#!/bin/bash

Because the entire script will be repeated indefinitely, until closed (such as using Ctrl + C), we want the main contents of our script to be in a while loop. The bash equivalent of a “while (true)” loop is “while [ 1 ]“, so the entire body of the script will be enclosed in that loop. Instead of brackets, while loops in bash are terminated with “do” at the beginning, and “done” at the end. The most obvious challenge we need to focus on is getting the current hour and minute in a format that’s incredibly easy to parse and work with. Linux’s “date” command works wonderfully for this. It does nearly all of the work for you, all you have to do is tell it how to format the date. If you look through the man pages for the date command, you can see that you’re able to specify how to format the date. All we’re interested in is the current hour (%k) and minutes (%M). To retrieve the hour from the date command, you simply type “date +%k”, where the formatting we want is after the plus sign. Go ahead and try that. The command to retrieve the current time in minutes is the same thing, substituting “k” for “M”. The letters are case-sensitive. When initializing a variable using bash script, it’s possible to set the variable to the return value (output) of a command using back-ticks. So, to get the current hour and minute, our code looks like this:

HOUR=`date +%k`

MIN=`date +%M`

Now that we have the hour and the minutes, we need to check to see if we should play the beep audio file or not. If the remainder of dividing the current minutes by 20 is zero, then we should be playing the file. The code for this is as follows:

let REM=”$MIN % 20″

if [ $REM = 0 ];

then

mocp -l beep-440-3s.ogg

fi

The “-l” argument of the mocp command tells MOC to just play the audio files specified in the command line arguments without messing with playlists, etc. Now that we have the beep working, we could consider the script done, as it goes off every at :00, :20, and :40 after the hour, but other that the fact that it’s obvious if you should put on ice or take it off, it’s a coding challenge to determine which one, so I decided to make the program say whether you should put ice on or vice versa. The first thing I did is realized that there are three times in an hour where I alternate between ice or not. Two of the times are the same except for the middle time at 20 minutes. Because 20 / 20 is one, we can check if the current minutes divided by 20 is 1 and display whether or not to put ice on depending on if the hour is an even number or not. In my code, I refer to the current minute divided by 20 with a truncated remainder as the current “set” number. The code for this is easy to write:

let SET=”($MIN-$REM)/20″

For debugging information, I list the current hour, minute, set, and whether  I should have ice on or not on the screen. This is also easy to code:

echo -n “Hour: $HOUR Min: $MIN Set: $SET “

In the string echoed to the console and the mathematical expressions, a variable name preceded by a dollar sign ($) is replaced with the value of that variable and evaluated as such. The -n argument of the “echo” command just tells echo not to append a new line character to the end of the string it prints to the output stream (in this case the console). The reason for this is because later in this script I echo whether or not I need to have ice on or off, and it looks neater to have it all on the same line. To determine whether the hour is an even number or not, we get the remainder of dividing the hour by two. If the remainder is zero, the hour is even. We can then use that to help determine whether we alternate cycles this hour. The code for this is incredibly simple:

let hrem=”$HOUR % 2″

As stated earlier, if the set is the middle set (set ’1′, at 20 minutes after the hour), whether or not I need to use ice is different than the other two sets. Using that logic as well as the fact that the fact that the cycles alternate each hour, we can piece together the logic using very basic conditional statements:

if [ $SET -ne 1 ]; then

if [ $hrem -ne 0 ]; then

echo “Ice On”

else

echo “Ice Off”

fi

else

if [ $hrem -ne 0 ]; then

echo “Ice Off”

else

echo “Ice On”

fi

fi

If you aren’t familiar with bash syntax, “-ne” is short for “is not equal to”, which is usually expressed in other languages using “!=”, or “not” before a condition. Finally, to prevent a lot of redundant output, we will use the sleep command to wait a minute (60 seconds in the command) before the next iteration (repetition) of the while loop:

sleep 60s #wait 1 minute

And we’re finally done coding the script! Now, we just need to save the script in the same directory as the beep audio file, with the “.sh” file extension and set it as executable. To do that, you can use the Properties dialog, or just do it with the command prompt using the following command:

chmod +x ice-timer-script.sh

Now you can run the script using the command “sh ice-timer-script.sh“. I hope that somebody finds this tutorial useful. Writing this certainly helped keep me busy, since I’ve been in bed for the majority of the day. If you have any questions or feel that anything needs clarification, feel free to leave a comment! The final script used in this tutorial can be found at http://code.dylanmtaylor.com/bash/ice-timer-script.sh.

FiOS WEP Key Calculator Website Updated

It’s been a very long time since I last worked on my Verizon FiOS WEP key calculator website. Over the last few days, I decided that it looked dated, and I decided to make it look a lot cleaner, using the magic of CSS3. I removed several images from the site, such as the header image, and the background gradient image, and I replaced them with a pure CSS-based approach, reducing the total page size from just above 12Kb to only 6.5Kb, and significantly reducing the already low amount of time taken to load the page, as well as making it feel more modern. The page loads, literally, almost instantly now, even on a dial-up connection, which is rather impressive if you ask me.  I think visitors will like the new look of my FiOS WEP key calculator site, and if you have any feedback about it, feel free to leave a comment on this post.

LibreScribe Progress Update

Since my last post, I have made a lot of progress with LibreScribe. Just a few commits ago, LibreScribe gained the ability to retrieve a list of installed applications on the device, and add them to the list in the applications tab. I also fixed several other significant issues, including:

  • When the smartpen is connected/disconnected, the application no longer crashes, and the status is automatically refreshed
  • Device storage usage is now displayed in MiB instead of in bytes. This makes it a lot less confusing how much space is remaining on your smartpen.
  • A bug, where the Echo Smartpen was detected as an “unknown LiveScribe Smartpen” in certain cases was fixed.
  • All absolute paths have been removed from the project. All resources are now referenced using relative paths.
  • wxFormBuilder has been replaced with wxSmith. The entire user interface has been recreated from scratch (although it’s very similar to the old interface, intentionally)
  • Many C++ source and header files are no longer necessary, so they have been removed, and merged into other files. This makes the codebase a lot more maintainable.
  • Duplicate udev events (such as multiple add events of the same device) are ignored now. Previously, we ended up refreshing the device information up to four times in a row because of duplicate events. This significantly reduces the delay between plugging in a device and seeing a response on the screen.

There are still tons of issues that still need to be fixed before LibreScribe becomes usable in a production environment, but I’ve been steadily making progress, and I hope to have something useful out soon.

Major Bug Fix in LibreScribe

A lot of work on the LibreScribe project has been accomplished since I first wrote about it. Just today, I fixed a major regression which was preventing the device information dialog from being displayed. In addition to that, I now have more work done on the interface, so that when the windows is resized, most of the elements will scale properly to fit the new size. Another major change I made was setting up the layout of the “Audio” and “Applications” tabs, so that there are now lists, with data split into columns. These changes mark a significant improvement in the look and feel of LibreScribe, but it’s only the beginning. Expect a large number of major changes in the not-too-distant future.

A Reply From Lexmark

After discovering a bug in Lexmark‘s Debian installer, as described in my previous post, and reporting it to Lexmark’s support team, I found a response from Lexmark in my inbox, which was sent on the 18th, and I decided to share it on my blog to show that Lexmark is aware of the issue, and they are actively working on resolving it. Here is the message I received from Lexmark Support:

Dear Dylan, 

Here is your Service Request # 1-5145156021

We recently received your feedback.

Thank you for sharing this information. We really appreciate your time and effort in bringing this one to us. I will definitely forward this one to our software engineers so that we can make the necessary changes to our software. We really appreciate your feedback. It’s through customers like you that we’re able to make improvements in our current and future products.

If you have any more questions or concerns, please contact me at your convenience and I will be happy to assist you. (If I am not available, another representative may reply to your request.)

To respond, please select “Reply” in your e-mail software, and be sure that the past e-mail is included in this reply.

[AOL Users: In order to include the previous e-mail, you must highlight it with your mouse when you are replying.]

If your e-mail client automatically deletes prior e-mail thread information, it will cause a delay while we look up your support history. If this is the case you may want to save the old e-mails as attachments and attach them to the current e-mail.

Sincerely,
Efren
Lexmark eSupport Team
http://support.lexmark.com

The driver installation failed because there was a typo in the Lua source code for the Linux Lexmark printer driver. To be specific, the variable “ownership” was misspelled as “ownhership” in one of the lines of the source code. While this is a very easy to fix bug, it prevents the Linux installer from working at all, and I am happy to hear that Lexmark knows about the issue now, and it’s likely that a quick fix will be released. Hopefully this will eliminate the need for my workaround, and simplify Linux printer driver installation.

Fixing Lexmark Printer Driver Installation in Ubuntu 11.04

Recently I just installed the Lexmark printer driver in my 64-bit Ubuntu 11.04 installation. As you may or may not notice, the installer is broken by default in Ubuntu 11.04, and it just exits with an error message, saying

Lua error detected: While parsing install.lua: config/run.lua:1374: attempt to index global ‘ownhership’ (a nil value)

After playing with the installer, I finally got it to work perfectly, so I emailed the Lexmark support team to let them know how to fix this, but for now, I’m going to share what you need to do on my blog.

First, you need to extract the files for the installer. To do this, you need to run

./lexmark-inkjet-legacy-wJRE-1.0-1.amd64.deb.sh –noexec –keep

It’s worth noting that there are two hyphens before noexec and keep. Once you run that command, the files for the installer will be extracted to the tmp folder in the current working directory. For now, just type cd tmp and press enter. Now, open up a text editor, such as gedit and navigate to the config folder in the tmp folder we just extracted. Open up the file “run.lua”. The problem is that Lexmark misspelled ownership as ownhership, which broke the installer. Around line 1484, you will find a line that says

if tonumber(ownhership[1]) == 0 then

delete the errant h in the word ownership and save the file. Now, go back to your terminal and run sudo sh startupinstaller.sh in the tmp folder. The installer will work as expected now.

Update: Special thanks to Mathieu Triclot for your $5 donation! Glad I could help! :)

LibreScribe, My Latest (and Most Challenging) Project

Image representing Livescribe  as depicted in ...
Image via CrunchBase

Over the past few days, I’ve been working on attempting to code an open source Smartpen Manager for Livescribe devices, based off of the work done in Steven Walter’s libsmartpen project, which hasn’t been updated for months. The project is called “LibreScribe”, and the source code is already on github right now. The code will be written primarily in C++, with limited functionality (such as threads) from the upcoming C++0x standard, and it will use wxWidgets for the graphical user interface, which will be built using wxFormBuilder, attempting to follow the Tango guidelines as close as possible. So far, I have only scratched the surface of all the coding that will be necessary, so it would be great if some of the coders reading this would step up to the plate and help out. Even small things, such as documenting functions, adding comments, ensuring source code style consistency, and making it easier to maintain the source code are incredibly important. Right now, there’s still tons of work to do. So much, in fact, that it’s actually easier to list what’s done than what’s left to do. Right now, I’m focusing on fixing bugs and writing functions to check the status of the connected Smartpen. To be more specific, some of the most important bugs at the moment include:

  • When the user plugs in or unplugs the device, the background thread updates the status of the device behind the scenes, but nothing is reflected in the user interface.
  • Clicking the “Device Information” button twice without closing the program results in a segmentation fault.
  • Currently, only LiveScribe Pulse devices are detected. LiveScribe Echo devices should work, but I can’t check the USB product ID property of them without physical access to one.
  • The program is not currently capable of retrieving the name of the Smartpen. More OBEX analysis is necessary to determine how the official desktop client retrieves the name of the Smartpen.

Once I have all of these bugs fixed, I will begin working on adding more of the code from libsmartpen into the project, fixing up existing code, and writing new code. This is probably one of the toughest coding projects I’ve started, but I enjoy the challenge, and I hope to create something genuinely useful to the open source community, improve my own coding ability, and learn new things. I frequently push changes to github, as long as I don’t notice any significant regressions, so you can track my progress in almost real-time. At the moment, the user interface is far from being finished (link is a screenshot), but it’s not too bad. Also, feel free to fork the code base, and make improvements.

A Simple JavaScript Dice Rolling Site

Portable Network Graphics

Image via Wikipedia

I haven’t been blogging very much about my recent projects lately, and I’ve been putting off writing about this one for a while, but I finally decided to share this. I recently created a JavaScript + SVG dice rolling demo site, roughly based on the work done by Taylor Copeland on his JavaScript dice implementation, as well as a lot of new code written by me, and part of an HTML5 test suite written by Niels Leenheer that detects whether the user’s browser supports inline SVG or not. This code should run just fine on all modern browsers, and if it fails to detect support for SVG images, it should fall back gracefully on pre-rasterized PNG images. The project is open-source, and can be downloaded in it’s entirety as a 7z archive. The source code of the page is dynamically generated using PHP, and it accepts GET parameters that affect the page returned. Also, if you look through the source code, you might just find a secret GET parameter or two… ;)

EDIT: Somehow I managed to forget to link to the actual site, even though I linked to the 7z download. Click here to visit the site. Sorry about that!