Fincher's Follies

Yeah… just let someone else host it

Setting up my Pertelian LCD on my linux box showing recent tweets

If you didn’t pick up on it from the title, this is going to be a pretty geeky post ūüôā I had a little time over Christmas break to finally play around with setting up my Pertelian X2040 LCD screen that Julie gave me LAST Christmas! How slow am I? ¬†I ran into a couple snags and had to code up some things for it to display as I would like so I figured I would post it in case any fellow geeks started looking to do something similar.

First, I had to get my screen talking to my linux box at work.  While it seems like a geeky little gift, Pertelian only lists it as being compatible with Windows (LAME!!) so I had to go looking around for an alternative means of connecting.  I came across lcd4linux that listed my screen as one they were working on supporting. I had to use the pre-release build for version 0.11 because the upcoming release is the first one to include the Pertelian drivers.  Getting it basically up and running was fairly simple (just a few edits to the included lcd4linux.config file to add my display.

 

Display pert-lcd {
   Driver 'Pertelian'
   Port '/dev/ttyUSB0'
   Size '20x4'
   Backlight 1
   Icons 1
}

 

Anyhow, I got it so I could do some basic display things through the program so it was on to configure it for my exact application, displaying recent tweets! ¬†I don’t check Twitter that often, so I thought it would be cool if I could set up my little screen to constantly display recent tweets. ¬†Twitter no longer provides an RSS feed for your timeline (all the tweets from people you follow), but with some searching I discovered this post describing using Roomatic to generate an RSS feed for you. ¬†Once I got that, I put together a little bash script to parse out the 4 most recent tweets. Then I tried to use the Text layout from lcd4linux along with a readline to read each tweet in. ¬†After much digging and frustration, I discovered that readline only reads the first 80 characters. ¬†Not too handy for tweets that can be 140 characters! ¬†So I resigned to just show the 2 most recent tweets each split across lines and was almost done with that when I remembered a brief example that I saw that concatenated strings. So I revamped my script to split each tweet into two 80 character lines, then concatenated them within my config file. ¬†Here’s an example:

 

Widget Twitter1 {
   class 'Text'
   expression file::readline('timeline.txt', 1).file::readline('timeline.txt', 2)
   width 20
   align 'M'
   speed 200 
   update tick
}

 

So everything that is displayed on the screen is done through widgets.  Then you have a Layout that tells the screen where to put each widget. In the above widget, I want to display the first tweet in my timeline. Since I parsed it to have half on line one and the other half on line 2, I use the . to concatenate these two strings.  I still find it odd that lcd4linux has no issue dealing with strings longer than 80 characters, yet readline has that limit. Anyhoo, I combine the widgets for each tweet into a layout for my screen.

 

Layout Twitter {
   Row01.Col1 'Twitter1'
   Row02.Col1 'Twitter2'
   Row03.Col1 'Twitter3'
   Row04.col1 'Twitter4'
}

 

In the widget, you see that the align parameter is set to ‘M’ which means marquee. ¬†This is what we want since a tweet can have over 140 characters, yet my screen is only 20 characters wide. ¬†So the result is 4 lines, each slowly scrolling through the most recent 4 tweets in my timeline! Luckily, lcd4linux constantly performs the readline operations so I just tossed my timeline parsing script in my crontab to run every 15 minutes and as soon as it is updated the display updates with the current timeline. Success!



The only thing I’d really like to tweak now is how exactly it runs. ¬†If I try to run the basic lcd4linux command, it just starts and closes without doing anything. ¬†To make it actually use my designated layout, I have to run it with the -F option that prevents it from forking and runs it in the foreground. ¬†The odd thing is that if I run ‘lcd4linux -F &’ then it puts it in the background and it runs fine. ¬†No idea what they are doing when they fork off, but apparently my machine doesn’t like it. Yay for geeky projects!

Creating a WordPress gallery of images from posts in category

So to start, I will describe exactly what I was trying to do and give a little background.  I did a lot of googling, and it seems that no one really had put together a tool to do what I wanted so I had to piece it together a bit myself.  Perhaps, when I have more free time, I can convert it into a plugin so it will be even easier for someone to use.

In my blog, I have a category called “Mobile” that is used whenever I post items from my phone. ¬†This virtually always consists of me posting a picture that I took on my phone, so I wanted to try to set it up similar to Twitpic or any other Twitter photo hosting site. ¬†I wanted it to work identically, but use my own web space instead of having some third party host, and do what they like with, my pics. ¬†One of the only means I found to do this involved having an Android app that allows the user to use a custom photo hosting site (most only give choices of several popular ones). ¬†The only app I found that allows this wouldn’t talk to the code I had set up on my site so I abandoned that idea and decided to just stick with having “Mobile” posts with a single pic as part of my blog.

While a user can view all posts in a category, it seemed a little cumbersome to scroll through pages of posts that just included a single pic and a few words so I decided I wanted to just put together a gallery of pictures posted. ¬†I found many photo gallery plugins, but, surprisingly, none had enough customization to automatically populate the gallery from my posts. ¬†After a little searching, I discovered this post on the WordPress support pages. It has some php code for getting the first image from WordPress posts, and, since all my “Mobile” posts have a single image, that is exactly what I needed (though it would be pretty simple to modify to grab all images if someone wanted a gallery of all images posted to their blog). ¬†It used another utility called TimThumb, which creates thumbnails of the images.

This worked pretty well, but the result was ONLY a gallery of thumbnails. ¬†My preference was to have the ability to click each pic and it would take you to the associated post, but, at the very least, I wanted to have each thumbnail link to the full resolution pic. ¬†So I created a new page template in my wordpress theme and included the php code. I didn’t worry with formatting because the thumbnails just tile to fill the space. I had to modify the code a bit so that it would grab only from the “Mobile” category and to make each thumbnail link to the full resolution picture. I was pretty happy with the result. ¬†So now, every time I post from my phone it creates a new blog post, and there is a gallery of all the pictures from the posts from my phone that can be viewed all together. ¬†Kinda snazzy!

I still have a couple of tweaks that I would like to do, though.

  1. As mentioned earlier, I would like the link to take the user to the post associated with the pic, not just the full resolution. ¬†I would like this because I always have a title and sometimes have additional text associated with the picture. ¬†I am also entertaining the idea of combining the title and post text and having them be the ALT text for the thumbnail in the gallery. ¬†Then a user could hover their mouse over a pic and see the text associated with it but wouldn’t have an additional step to get to the full resolution version.
  2. I would also like to get comments working so people could comment on the entire gallery. This would probably be only useful if I haven’t implemented #1 yet because, as it is, there is no way to comment on a single pic without just searching through the posts. I have tried to put the code to add commenting to the bottom of the page, but for some reason it never shows up. I am too unfamiliar with wordpress and it has been too long since I really used PHP to figure it out at a glance.
  3. The last thing that would be nice to do is to package this up as a plugin.  Then make it easy to customize where the pics you want displayed will come from and add some formatting options. What would be IDEAL is if I could also create a (or tweak an existing) plugin like WP to Twitter that automatically tweets when I make a post so that the resulting tweet would be the title followed by a link directly to the photo. This should allow most Twitter clients that have previews to see the photo and people could get a glimpse instead of just having a link they would have to click on (i.e. it would work exactly like Twitpic).
None of these will likely happen until I have finished with my dissertation, but it never hurts to have plans in mind.  Hopefully, people that want something similar in their blogs will benefit from this post!