ADAM'S WEB PRESENCE

10 August 2009

Parallel port control in Python

Filed under: Nerd Notes — adam @ 11:11 am

Controlling the parallel port has always been a pain in Windows 2000, XP and later. In DOS or older versions of Windows you could just write a byte directly to port 0×378 and that was it.

Now you can get the same level of simplicity using inpout32.dll and Python. Go here to download the DLL and you can access it from Python just as easily as it used to be under DOS. The following example writes the number 5 to the parallel port:

import ctypes

ctypes.windll.inpout32.Out32(0x378, 5)


UPDATE: I have made a simple demo app using this technique. You can download it from my commercial website at http://siliconsparrow.com/parallel-port-tester-in-python/.


29 July 2009

Australian Income Tax Spreadsheet Formula

Filed under: Nerd Notes — adam @ 10:47 pm

Just a quick note for my future reference. I’m setting up my budget spreadsheet for the new financial year and I have converted the Australian 2010 income tax rates into a spreadsheet formula. I use OpenOffice, it should work fine in Excel too.

=if(A1<=6000;0;if(a1<=35000;.15*(a1-6000);if(a1<=80000;4350+(.3*(a1-35000));if(a1<=180000;17850+(.38*(a1-80000));55850+(.45*(a1-180000))))))

4 May 2009

TV addiction

Filed under: General — adam @ 4:42 pm

One of the little rules in our house is that kids are not allowed to watch TV before school in the morning.

But these two are so addicted to the glow of a screen, they watch my screen saver and pretend it is a movie!

Sometimes they are quite amusing to watch, they come up with things like “Oooh, watch out little blob, that big blob is going to get you” or “That’s two cows dancing!”.

My screen saver is Electric Sheep by the way.


13 April 2009

Toshiba vs Dell – Cashback deals and Customer Service

Filed under: General — adam @ 10:10 am

I’ve never done a good ‘ol consumer rant on this site so here we go. I’ll put my grumpy old man hat on…

A couple of months ago, it so happened that I bought a Toshiba laptop and a Dell screen in the same week. Both products offered a $100 cash-back deal. What happened next showed very dramatically the difference in attitude towards customers of these two companies.

How the Toshiba cash-back works

The cash-back cannot be claimed in the store, you need to go to Toshiba’s web site and fill in a form.

But there is no form on Toshiba’s web site. So I phoned Toshiba and after the usual phone menu maze and having to hold for quarter of an hour, the Toshiba representative told me I need to go to a different web site.

Next were several screens of web forms to fill in including all my personal details, the model number and serial number of the laptop, when I bought it, where I bought it, the address of the shop, the ABN number of the owner of the shop and more and more and more. So then could I submit my claim ? No. They require you to print out the forms and then photocopy the purchase receipt and write a note, put it in a paper envelope and go to the post office and post it!!  This all took me about two hours.

So Toshiba eliminate people who are not web-savvy, do not have a printer and a photocopier, cannot be bothered spending an hour filling out forms or cannot be bothered going to the post office.

I received my cash-back about 6 weeks later in the form of a postal money order. I had to physically go to the bank and deposit it over the counter so you can add an extra hour to the total time spent by me to claim this money.

You can also add to that, another half an hour I spent writing a letter of complaint about all this to Toshiba. Did I receive so much as an acknowledgement that they received my letter ?  Nope.

From a business point of view I can understand why they do all this. They figure if they make claiming the cash back difficult they can save money because I bet that less than 30% of customers actually go through all that bother. If they sell 1000 laptops, they’ve just saved $70,000.

Of course, this comes at the expense of aggrivating their own customers who like me, will probably never buy another Toshiba product again. Can you put a dollar value on that kind of customer resentment ?

How the Dell cash-back works

Dell credited my VISA card with $100 the next day. No forms to fill in, I didn’t have to do anything. Dell want to keep their customers.

Summary

I know who I will choose next time I buy a laptop.

Company Time I spent applying for the cashback Time before I received the cashback
Toshiba 3 hours 6 weeks
Dell 0 1 day

UPDATE: This Dilbert cartoon says it all…


19 March 2009

Creating a Debian Kernel Package for v2.6.26

Filed under: Nerd Notes — adam @ 10:47 am

There are so many guides out there on how to make a Linux kernel and so many of them are out of date, I thought I should write down a simple step-by-step of the current way to do it as of early 2009.

My goal here was to compile a new kernel for a Debian 4.0 (Etch) system. You can download pre-built kernels but I wanted to modify some drivers before building it.

Anyway, you will firstly need the source code. Go to the Debian Backports Repository and grab the latest linux-source package. Before installing it, you will need to install some tools:

sudo apt-get install kernel-package fakeroot libncurses5-dev

Now we can install the source:

sudo dpkg -i linux-image-2.6.26_dvc.1.2_i386.deb

cd /usr/src

tar jxvf linux-source-2.6.26.tar.bz2

ln -s linux-source-2.6.26 linux

cd linux

Next you need to configure the kernel. A good way is to simply copy the current kernel configuration:

cp /boot/config-2.6.18-6-686 ./.config

Finally, launch the make-kpkg utility. This will configure, compile and package the kernel in a DEB package.

fakeroot make-kpkg --revision=mycustomkernel-1.0 --config menuconfig --initrd kernel_image

This will launch the kernel configuration menu first. You can make any configuration changes here but usually the defaults are fine. When it is all done you will have the completed package file in /usr/src.


2 February 2009

Reading a single keystroke with C++ on Linux

Filed under: Nerd Notes — adam @ 9:03 am

Just say you want to input a single key from your user such as asking “Would you like to continue [y/n] ?” without requiring the user to press ENTER. You’d think you could do it like this:

char c;
cin >> c;
cout << "You pressed " << c << endl;

But it doesn't work! The user has to press ENTER before the cin function will complete.

I read all sorts of crazy solutions on the web to fix this, most of which involve using NCURSES but I think that is total overkill. I have found a simpler way.

Now it's not the fault of std::cin or even C++. It's the operating system which buffers the keyboard input, only releasing it to your app when the user whacks ENTER. So what you need to do is tell the OS not to buffer keystrokes. You can do this with the termios functions in Linux. Here is an example:

// Example for inputting a single keystroke in C++ on Linux
// by Adam Pierce <adam@doctort.org>
// This code is freeware. You are free to copy and modify it any way you like.

#include <iostream>
#include <termios.h>

using namespace std;
main()
{
// Black magic to prevent Linux from buffering keystrokes.
    struct termios t;
    tcgetattr(STDIN_FILENO, &t);
    t.c_lflag &= ~ICANON;
    tcsetattr(STDIN_FILENO, TCSANOW, &t);

// Once the buffering is turned off, the rest is simple.
    cout << "Enter a character: ";
    char c = cin.get();
    cout << "Your character was " << c << endl;

    return 0;
}

17 December 2008

Simple Slide Show is now open source

Filed under: General — adam @ 10:00 pm

I’ve taken that old Simple Slide Show program I wrote years ago and given it a bit of a brush-up. I also changed the licensing so it is open source.

As a bonus, I have added a new feature to allow you to customise the colour and font used in the image captions.

You could use the source code from this to make your own more fully-featured slide show application, or just use it as example code for writing whatever. I hope you find it useful.

CLICK HERE to go to the download page. It’s free!


9 December 2008

Linux is amazingly useful

Filed under: General — adam @ 4:04 pm

It’s incredible the things you can do in Linux. Here’s two amazing things I’ve done today:

Amazing thing #1

I had a corrupted disk and I wanted to run some recovery tools on it but to be safe, I wanted work with a copy of the corrupted disk. So I created a raw copy of the entire disk and piped it to a different machine which had enough storage:

cat /dev/hda1 | netcat -q 1 192.168.0.15 9998

That created a file of 1128GB in size – probably the single biggest file I’ve ever created. It took more than 12 hours to copy to the other machine!

Then I created a loopback device so the system could pretend the file was a real disk:

losetup /dev/loop0 /home/adam/recovery.raw

Then I ran xfs_repair on it and recovered all the files. In the old days I would have to physically install a second hard drive in the corrupted box – did I mention that I did all this remotely from off-site through an ssh session.

Amazing thing #2

I needed to find all the Makefiles for an older version of my projects and update them. This command searches through a bunch of folders for files which contain the string “1.6″ and loads them all up in a text editor for me. It sure beats manually going through dozens of folders and eyeballing every file.

find /usr/src -name Makefile | xargs grep -l "1.6" | xargs kate

7 December 2008

Networked Warcraft II under DOSBox

Filed under: Nerd Notes — adam @ 8:36 pm

This is a guest post contributed by Richard Geoffrion. Thanks for sending this Richard, I hope others will find it useful!


First off, thank you so much, Adam, for the primer on getting Warcraft II working under DOSBOX. The “-t cdrom” option was the piece I was missing to get my game to recognize the CD and work.

After I installed my game, I wound up copying my entire Warcraft II CD to my C:\DOSGAMES\WAR2 directory, then I added “mount d c:\dosgames\war2 -t cdrom” to the [autoexec] section. By copying the CD to the same path as the installed game, I don’t have to duplicate the space to hold the files from the CDROM.

As for playing multiplayer Warcraft II in DOSBOX, it could not be made any easier. There is NOTHING that the user has to configure in Microsoft Windows (or Linux…or OSX) to get IPX gaming working under DOSBOX. The DOSBOX team has built an IPX wrapper right into DOSBOX. Once the Warcraft II game is operational on two or more computers on your network you are ready to setup networking in DOSBOX.

Instructions:
1) Identify the IP addresses or names of each computer that will be participating in the gaming session. (Windows users: To display the computer’s IP address click START, click RUN, type in “cmd” and click the OK button. At the prompt, type in the command ipconfig and press enter. Write down or remember the number on the IP ADDRESS line. If you want to know the name of the computer, you can type in the command ”hostname” and press enter to see the name.) (Linux/OSX users: run ifconfig from a terminal (you may have to sudo the command or su to root)

2) Once you have identified all of the IP addresses (or names) of the computers on your network that will be playing the game, pick one to designate as your IPX SERVER.

3) *OPTIONAL STEP* Sometimes the Microsoft Windows firewall is turned on and it could interfere with proper communications between the client and the server. If you want to run a test to make sure that everyone can connect to your server, then go to each computer that will be connecting to your designated server and start a windows command prompt. Once the prompt is open, use the ping command along with the IP address of the server -OR- the server computer’s name to make sure that the server can respond to the clients. [Example: " ping 192.168.1.100 " -or- " ping HP-PAV6330 " ]

4) Start DOSBOX on your designated server. Run the DOSBOX command:

ipxnet startserver

That is IT!! That is ALL YOU NEED TO DO on the server! It is THAT SIMPLE!

–we’re almost done!–

5) Now start DOSBOX on each client computer that will be joining in the multiplayer fun. Once DOSBOX is running we will be using the DOSBOX command ‘IPXNET CONNECT’ but we’ll be adding something to it. We will either add the IP address of the server or the name. If we were to use the IP address or name from the examples in the optional step 3, our DOSBOX command might look something like this:

C:\> IPXNET CONNECT 192.168.1.100

-OR-

C:\> IPXNET CONNECT HP-PAV6330

At this point, DOSBOX will handle wrapping the IPX packets in TCP/IP.

6) Start WAR2 on the server, Select Multiplayer, select the IPX Network connection method and
click CONNECT then CREATE GAME.

7) Start War2 on each client, Select Multiplayer, select the IPX Network connection method and click CONNECT then JOIN GAME.

8) Begin your game and race your peons out to the unclaimed gold mines to put walls around them to protect them from any players..especially computer players. Oh..wait….that doesn’t belong in this set of instructions! Now who let that slip by quality control?!!?

NOTE 1: It *IS* possible to play WARCRAFT II with a friend across the internet. The variety of the additional steps needed are a bit beyond anyone’s ability to document in a single document but I can briefly outline the requirements below.

A) The gamer who will be the server ( the server user) will have to know their real-world public IP address. If you don’t know your public IP address, you can visit a site that displays your public IP address. A google search on finding your public IP will reveal many. http://www.whatismyip.com is one. [#]

B) If the server user is behind a router/firewall, then the server user will also need to..

*) know their private IP address. This is the IP address that was discovered in the ‘ipconfig’ command from step 1 above.

*) configure their router/firewall to forward the UDP port 213 –DOSBOX IPX WRAPPER traffic– from their external interface to UDP port 213 on the private IP Address of the computer that is the DOSBOX IPX server.

Note 2: The DOSBOX command ” IPXNET help ” will display a list of available networking commands and a small bit of documentation — like the fact that the DEFAULT port for the IPX wrapper in DOSBOX is UDP port 213

Note 3: These same networking steps should work for any IPX DOS game that runs in DOSBOX. These steps have been successfully tested with “One Must Fall”. [Google omf21cd.zip to download this free game.]

[#] Please avoid http://moanmyip.com if you are ..oh I don’t know… at work setting up for a Christmas LAN party! Of course using that link as a secondary browser-start-up-home-page can be fun.

Happy Retro-Gaming!


15 November 2008

Update on TwinHan remote for Mythbuntu 8.10

Filed under: General — adam @ 11:08 pm

twinhan remoteI’ve just upgraded my HTPC to the new Mythbuntu 8.10. I must say that setup is a helluva lot easier than previous versions of Myth although I found my ATI card did not work at all and I had to exhume an ancient nVidia card from my parts box. And I had to hack the xorg.conf file to make the TV output work so the setup is not 100% seamless.

Anyway, onto the odd device, my TwinHan remote control. Setting this up is much easier under Mythbuntu 8.10. Here’s the step-by-step:


Step 1 – Configure LIRC

Plug the IR receiver into a USB port. Wait a moment for it to register and then type the following command:

ls /dev/input/by-id

It should produce output like this. This step is just to verify the correct device name for the remote.

usb-Twinhan_Tech_Remote_Control_1111111-event-kbd
usb-Twinhan_Tech_Remote_Control_1111111-event-mouse
usb-Twinhan_Tech_Remote_Control_1111111-mouse

Now edit the file /etc/lirc/hardware.conf and enter values for REMOTE_DRIVER and REMOTE_DEVICE:

REMOTE_DRIVER="devinput"
REMOTE_DEVICE="/dev/input/by-id/usb-Twinhan_Tech_Remote_Control_1111111-event-kbd"

Due to a bug in this version of Ubuntu, you will also need to run the following command:

lshal | grep input.product

It will spit out a few lines of text. Verify that it produces a line like this:

  input.product = 'Twinhan Tech Remote Control'  (string)

Then edit the file /usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi and make it read like so:

<?xml version="1.0" encoding="UTF-8"?>

<deviceinfo version="0.2">
  <device>
     <match key="info.product" contains_ncase="Twinhan Tech Remote Control">
        <merge key="info.ignore" type="bool">true</merge>
     </match>
  </device>
</deviceinfo>

Finally, download this file:

lircd.conf

and put it in /etc/lirc/

At this stage, I had to reboot so that everything loaded properly. Once you have rebooted, you can test the remote control by typing:

irw

Now every time you press a key, you should see it printed on the screen. Press Ctrl-C when you are done.

STEP 2 – Configure MythTV commands

We are getting closer now. The next step is to set up a file called ~/.lirc/mythtv which contains the mappings between the keys on the remote and the functions in MythTV. Once again, I have already prepared this file which you can download here:

lircrc-mythtv

Rename this file to mythtv and move it to ~/.lirc/ Once that is done, restart MythTV. Here are the key mappings you will end up with:

Key Function
REC Record
TELETEXT OSD
RECALL MENU
PREVIEW INFO
REW/FFWD Forward/backward in MythMusic
CAPTURE Previous playlist item in MythMusic
RECORDLIST Next playlist item in MythMusic

STEP 3 – Configure MPlayer

The final step is to configure the mapping between the remote and the commands in MPlayer. Since MPlayer is a separate program, it needs to be configured separately to MythTV. To configure it, we need another lircrc file but this time is has to be called ~/.lirc/mplayer. Download it from here:

lircrc-mplayer

Rename it to mplayer and put it in ~/.lirc/ and that should be that! Here are the key mappings for MPlayer:

Key Function
MUTE Mute
VOL+/- Adjust volume
CH+/- Skip fwd/back 60 seconds
REW/FFWD Skip fwd/back 10 seconds
PREVIEW Show/hide subtitles
TELETEXT Show/hide OSD
TAB Cycle through audio tracks

If you do not like the key mappings I have chosen, you may edit the files in ~/.lirc. The format should be fairly easy to follow.


« Previous PageNext Page »

Powered by WordPress