Progress Indicator in Windows 7 Taskbar

Illustration

One of little things that mean a lot in Windows 7 is (at least for me) ability to show progress in taskbar. There is no longer need to Alt-Tab every minute or so into long running task (most often file copy). Progress of any long-running operation can (and should) be visible in taskbar button itself.

It is surprisingly easy to use this feature in our programs. Everything that we need is contained withing two functions: SetProgressState and SetProgressValue. Setting percentage is as easy as

var res = _taskbarList.SetProgressValue(owner.Handle, (ulong)newProgressPercentage, 100);

Although that minimal code will do it’s work, there is need for some additional preparation around it. We need to initialize feature itself, we need to check whether function is even available (XP is pretty much alive) and some error checking would be nice touch.

Because of this I made sample class in C# that should enable your program to have all those goodies. And, as always, sample is available for download.

Sending Hex Byte on PIC

Illustration

Sometime I have a need to convert byte to it’s hexadecimal representation. I did that plenty of times - you just call ToString or whichever function your favorite language has and byte ranging from 0 to 255 gets converted to two ASCII characters spanning familiar ‘0’ to ‘F’ range. If this code needs to be implemented in assembler for micro controller, things start to get more interesting.

This version of code is implemented on both PIC16F628 and PIC16F690 (although code should work on almost any 8-bit PIC). Function is called TXD_HEX and source code is here:

TXD_HEX
    MOVWF       var_hex_in
    SWAPF       var_hex_in, W
    CALL        TXD_HEX_NIBBLE
    MOVFW       var_hex_in
TXD_HEX_NIBBLE
    ANDLW       0x0F
    ADDLW       '0'
    MOVWF       var_hex_out
    SUBLW       '9'
    BTFSC       STATUS, C
    GOTO        TXD_HEX_NIBBLE_DONE
    MOVFW       var_hex_out
    ADDLW       .7
    MOVWF       var_hex_out
TXD_HEX_NIBBLE_DONE
    MOVFW       var_hex_out
    CALL        TXD_BYTE
    RETURN

TXD_HEX

Upon entrance first thing we do is storing actual character that we need to transmit into var_hex_in. Since most operations work on W register (and thus overwrite it) it is handy to have it around.

Each byte must be encoded as two (hexadecimal) ASCII characters. It is best to show it with example of byte 11001001. Here we need to encode 1100 in first ASCII character and 1001 in second. Since most of numeric operations work only on low bits, we need to move first four bits (or nibble) to appropriate place. This is where SWAPF comes in handy since it will swap nibbles (result would be 10011100) and thus our data (1100) will be in proper place. Only thing left after that is actual conversion (in TXD_HEX_NIBBLE).

As soon as first byte is out we move original data back to our W register and use it (1001) for second visit into TXD_HEX_NIBBLE.

TXD_HEX_NIBBLE

Since this function works with lower data bits only (SWAPF ensures this) first step is to trim excess bits - ANDLW ensures that only lower four bits survive.

Those four bits are then “shifted” so value 0 moves to letter ‘0’. Value 15 (highest that we get) ends on letter ‘?’ (because there are some characters between ‘9’ and ‘A’) but we shall sort this later if needed.

Temporary subtraction (SUBLW) and checking whether we are still in positive range (BTFSC) ensures that TXD_HEX_NIBBLE_DONE gets called if our nibble has value between ‘0’ and ‘9’.

Values above 9 get moved for additional 7 places in order to align our original value 10 with letter ‘A’. After this we also continue with TXD_HEX_NIBBLE_DONE.

TXD_HEX_NIBBLE_DONE

This function just moves our stored hexadecimal value back in W register and then calls TXD_BYTE (not shown here) with hexadecimal ASCII in W register. Last RETURN goes back to next nibble (see CALL TXD_HEX_NIBBLE at very beginning) or, if second nibble is sent, goes back to original caller.

Prerequisites

Obvious one is to put byte that is to be encoded in W. This is just how I am used to, you might use separate variable for that if you fancy it better that way.

Important thing is to have TXD_BYTE function somewhere in your code. This function will do actual sending of each ASCII character. Datasheet for each particular PIC has example for this so I will not write it here.

You also need to define variables elsewhere in your program. Only two are needed (var_hex_in and var_hex_out) but do notice that you need to be switched to correct bank (with BANKSEL). Beauty of PICs and bank selection ensures that you need to put some thought in it. I usually just cram it in bank 0.

Enjoy hexadecimal.

300

Illustration

After more than two years of writing I finally cannot fit all my posts on single Blogger page. Magic number was 300 posts. Hopefully there will be much more.

HTC Desire (With Froyo)

Illustration

Two months ago I bought myself a Desire. This was a big deal for me. Windows Mobile developer buying Android phone - betreyal! As I received Android Froyo upgrade last night, I decided to write my experiences with this device usage.

Upgrade

As old Windows Mobile user, I am not used to OS upgrades. It is just not something that happens that much in Windows Mobile world. Even if you get an upgrade, it also means that all your data is gone and all applications need to be reinstalled.

Whoever thought of Android upgrade process is genius. Phone informed me that upgrade is ready, asked me whether I will download it over WiFi or mobile and, after download was over, asked me to confirm upgrade. As simple as it can possibly be.

It took next 15 minutes for upgrade after which I was greeted with all my data, applications and widgets completely intact. I do not think that it can get anything better than this.

Screen

First thing that you see on is 3.7" screen with 480x800 pixels on it. Usage on sunny day is usually crappy - barely anything is visible. You forget all that while inside - pictures are bright and vivid and pure joy. Big part is probably because usage of OLED on my model. Newer models will have SLCD display and, while picture may not be so great, this will bring better battery life.

Battery

Battery-life is usually annoyingly short. That would sum it up. Normal usage will get you through day but not much further. Late night charging is back in fashion.

Camera

Camera is 5MP and probably best phone camera I saw. It is still inferior to any standalone digital camera. Pictures will be good if lighting is excellent - anything less than that and you will probably not be satisfied. Yes, it does have LED flash but only thing that flash is good for is for flashlight applications - for camera not so much.

Camcorder mode is great. It has 720p capture (came with Froyo update) and it gives decent resulting video.

Speed, memory and everything else

This device has fast processor, plenty of memory and I will not write much more. Boring technical specification data can be found at HTC pages.

Annoying stuff

This phone has it’s own death grip. My way of holding phone includes pinkie holding phone’s weight (cross between balance and four edge grip). When I hold this phone in left hand it just happens my little finger fits perfectly over microphone. It would be understatement to say that it’s usage as communication device is slightly compromised.

HTC decided to modify standard Android calendar application. And they did beautiful job - except two small details. Idiotic remainder is turned on by default. Yes, I know that it was turned on Windows Mobile also, but there you could disable it. Here you can choose only what annoying time you want to set it. There is no option to turn default reminders off!

Often I first browse my calendar to find suitable day and only than I add new event. On Windows Mobile I came to expect that new event will default it’s day to one that I am currently viewing and give me next available time as default value. This works ok when you use Add event from list. If you use same function from menu it defaults to current day. If you are not careful, it is easy to make appointment in past while thinking you made it two weeks in future. Yes, it behaves differently whether you use on-screen function or menu item. I hope that this is bug since alternative would be that designer actually thinks this is useful. I dread that world.

It used to be that you cannot send contact via SMS. Froyo finally fixed this so I will not complain too much. I will just say: about time.

Also there is one thing that no smartphone can get right (except iPhone) - input of simple letter Đ (latin letter D with stroke). When this letter is part of your national alphabet this deficiency quickly becomes visible. Mind you, this letter is supported - you just cannot use keyboard to enter it. And yes, this phone is legally imported in Croatia and it is intended for Croatian market.

Conclusion

Even with all annoying deficiencies, I consider this a great phone. I would even dare to say best phone I had yet.

Now I wait for Windows Mobile 7 to throw me off my feet.

64-Bit Registry View

If you are creating application that works with registry (e.g. your own registry editor) you are probably aware that 64-bit and 32-bit applications do not necessarily share registry keys. If you have 32-bit application your view of registry will not match one that 64-bit application gets.

.NET Framework 4.0 helps here a little. There is RegistryView enumeration available so code can specify which “bit-ness” of registry is desired. It works both ways: 32-bit application can specify 64-bit view and 64-bit application can specify 32-bit view.

As always, you cannot get what is not there. If you have 32-bit Windows, specifying 64-bit view will still give you 32-bit one.