scuba zoomed

“Windmills Do Not Work That Way!”*

The life and hobbies of an embedded firmware developer.

Embedded.com - The Use Of Assertions
scuba zoomed
[info]zanedp
There are things we are supposed to do that we don't. Exercise. Avoiding fast foods. Use the assert() macro. Exercise is a real pain that requires time and effort. Fast food can save time, and is carefully designed to seduce us. But asserts take little time or effort, and yet are as rare as the spotted owl. The Linux kernel sports just one thousand invocations of the macro in three million lines of code, an assertion density of just one per 3KLOC.

Historically, though, there's been little good evidence they are effective. Till now. In a paper from Microsoft Research the authors compared the relationship between the density of the assertions and code quality.

Embedded.com - The Use Of Assertions

A follow-up to my "Adventure Paper" post
scuba zoomed
[info]zanedp
A while back, I mentioned National Geographic Adventure Paper.

After some more use, and more submergings, I have additional information to add.

At least with my HP ink, over time, the red starts to bleed and fade, and blue starts to show through onto the other side of the paper.
Tags: ,

LLVM 2.6 is Out
scuba zoomed
[info]zanedp
Sometime, I plan to really check this out. It's so exciting!


LLVM 2.6 Release Notes

Barr Code: Binary Literals in C
grad
[info]zanedp
I think this is a neat C-preprocessor trick for implementing binary literals. Unlike 0b0101 which some compilers support and others support via a patch (gcc), this method is portable:

Barr Code: Binary Literals in C

Here's the interesting part:
// Internal Macros
#define HEX__(n) 0x##n##LU
#define B8__(x) ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x000F0000LU)?16:0) \
+((x&0x00F00000LU)?32:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)

// User-visible Macros
#define B8(d) ((unsigned char)B8__(HEX__(d)))
#define B16(dmsb,dlsb) (((unsigned short)B8(dmsb)<<8) + B8(dlsb))
#define B32(dmsb,db2,db3,dlsb) \
(((unsigned long)B8(dmsb)<<24) \
+ ((unsigned long)B8(db2)<<16) \
+ ((unsigned long)B8(db3)<<8) \
+ B8(dlsb))

Here are some examples of the usage of these macros:
B8(01010101) // 85
B16(10101010,01010101) // 43,605
B32(10000000,11111111,10101010,01010101) // 2,164,238,933

jEdit: Fun w/ search and replace
scuba zoomed
[info]zanedp
I just did a “search” for this regexp:
Num:(\d+),

And had it “replace” with the “return value of a beanshell snippet”:
"Num:" + _1 + ", // 0x" + Integer.toHexString(Integer.parseInt(_1))

So, it changed:
Num:80,
to:
Num:80, // 0x50

Cool!

jEdit

What font is that?
scuba zoomed
[info]zanedp
Here's something neat I ran across:

What the font?

You can upload an image of some text and it will guess what font is being used. Neat!

Cambria -- One of Microsoft's new fonts
scuba zoomed
[info]zanedp
Behold Cambria:


It looks like that when printed, too.

At least on Windows.

Barf.

Typing Special Characters (Intuitive Special Character Entry)
scuba zoomed
[info]zanedp
The Macintosh has had a fairly intuitive method for entering special characters from the keyboard that I'm surprised isn't available on Linux and Windows. (I first used it in Macintosh System 6.0.7 about 20 years ago.) If you know of a tool that works like this or is similarly intuitive for Windows or Linux, please let me know because I will install it immediately!

Below are the special characters I can tell you how to type right off the top of my head and the mnemonic I use to remember them. I miss them sorely on Windows and Linux. These key combinations are definitely one of my favorite things about the Macintosh.

Vowels with an acute accent:
é — option+e, then type an e (as in résumé)
á — option+e, then type an a
í — option+e, then type an i
ó — option+e, then type an o
ú — option+e, then type a u

Vowels with a grave accent:
à — option+`, then type an a (as in french words I never type)
è — option+`, then type an e
etc.

Umlaut:
ü — option+u, then type a u (as in übergeek)
ä — option+u, then type an a
ö — option+u, then type an o
etc.

Tilde:
ñ — option+n, then type an n (as in ñ)
ã — option+n, then type an a

Mathematical, Scientific, and Engineering:
÷ — option+/ (as in / means divide)
° — option+shift+8 (as in * is up high like a degree sign)
± — option++
≠ — option+=
≤ —option+, (comma is on same key as < on keyboard)
≥ — option+. (period is on same key as > on keyboard)
π — option+p (p as in pi)
∂ — option+d (d as in it looks like a d)
Ω — option+z (last letter of greek alphabet)
µ — option+m (m as in mu)
¬ — option+l (it looks like a sideways L)
∆ — option+j

Spanish punctuation:
¿ — option+? (or option+shift+/)
¡ — option+1 (1 has ! on it)

Typographical:
• — option+8 (use a proper bullet instead of an asterisk)
– — option+- (the medium length one)
— — option+shift+- (more keys for the longest one)
™ — option+2
® — option+r
© — option+g (I don't know how I remember this one, but I do)
… — option+;

Miscellaneous:
¢ — option+4 ($ is shift+4)
£ — option+3 (pound == pound [£ == #])
ç — option+c (it looks like a c)
ø — option+o (it's an o with a slash through it)

A few IronPython tips
scuba zoomed
[info]zanedp
If using IronPython, pass these options to ipy.exe to enable tab-completion and pretty colors:

-D -X:TabCompletion -X:ColorfulConsole


I found the tip in the presentation Application Development Using IronPython.

That presentation also shows the way to launch a .NET application using System.Windows.Forms's Application.Run() method.



You can right-click the "IronPython Console" shortcut on your "Start" menu, select "Properties" from the context menu and add these options to the end of the "Target" field to make your everyday life easier. While you're at it, set "QuickEdit Mode" on the "Options" tab: right-click is "paste," "enter" is "copy."
Tags: ,

My Dell
scuba zoomed
[info]zanedp
Why do PCs have such a hard time waking from "standby"? They always have. I've never used one that woke up reliably, except for a Compaq tower that's running Ubuntu. My laptop (a Dell) almost never wakes up from standby after I've undocked it. Or, after I've redocked it. I just have to press-and-hold power.

HTML Documentation from C#
scuba zoomed
[info]zanedp
I'm using Doxygen to generate HTML documentation from my C# code. It recognizes the .NET XML-comments.

Underwater Camera Suggestion
scuba zoomed
[info]zanedp
Underwater cameras need to have the viewfinder on top rather than on the back. I think that will make setting up shots much easier since divers should be horizontal when they're kicking around: having the viewfinder on the back makes people want to get vertical, and it's hard to get "low down" shots, particularly shots near fragile coral heads without damaging them if you have to look through the back of the camera rather than down towards the top.
Tags: ,

Embedded.com - Back to the basics: Doing Hardware Counter/Timer design using High School Science
scuba zoomed
[info]zanedp
My introductory article on understanding counters/timers has been "published:" Back to the basics: Doing Hardware Counter/Timer design using High School Science

In the RSS feed, the editor summarizes it:
Using the same unit-conversion techniques and dimensional analysis techniques learned in high school, Zane Purvis takes non-engineers and newcomers to embedded design step-by-step through the configuration of a counter/timer.

My original title was "Understanding Hardware Counter/Timers Using Techniques from High School Science Class." Not particularly catchy, huh?.

Marmalade for Lindsey (It's been a busy several weeks)
scuba zoomed
[info]zanedp
Life has been busy lately for me. In the last three weeks, I've interviewed for a job, went to Cancún for a week, and spent a week at my new job. It seems like I've had something going on every day since I've been back, too. It feels... healthy to be busy.

I had planned on writing several entries about our trip to Mexico, but haven't gotten around to it, yet. Maybe, later. For now, you'll just have to be content to know that we all had a good time. (Me, Daddy, Kristen, and Lindsey) And, that hardly anyone I talked to in Mexico would even humor me by speaking Spanish to me: they responded to my Spanish with English.

For your viewing please, are pictures from the trip. Charles Francis let me borrow his camera, including underwater housing, for the trip. I thank him for that. It did great. I separated my photos into albums roughly by day.

2009-08-05 Cancún Day 1 — Chichén Itza
       Absolutely amazing. And tons and tons of ruins.


2009-08-06 Cancún Days 2 & 3 — Shopping and Isla Mujeres
       We had to get up earliest for Isla Mujeres, but it was the least interesting part of the trip. The trip from the hotel didn't include enough time for us to actually see the ruins, and didn't give us much time to see the populated part of the island. Our favorite part was collecting sea glass.


2009-08-08 Cancún Day 4 — Scuba
       The crew treated us like royalty. The only thing I had to do was put on my fins and mask: they put our BCs on, buckled them for us, swapped out tanks between dives, rinsed our gear off afterwards... It was a little unnerving for someone coming from my scuba background where I don't even trust my gear after I set it up.


2009-08-09 Cancún Day 5 — Tulúm
       This city is likely the origin of the legend of El Dorado. But, instead of being made of gold, light reflecting off of gold obsidian from a distance looks like metallic gold.


2009-08-10 Cancún Days 6 & 7 — Snorkeling and Last Day
       They made us wear life jackets, and charged us $10 for "biodegradable" sunscreen. Some of the pictures turned out well even considering I couldn't get deeper than 0 ft below the surface.

My article: Understanding Hardware Counters/Timers Using Techniques from High School Science
scuba zoomed
[info]zanedp
I'll be in Mexico, but you can be on the lookout for this:

...I [the editor] am using it [my article on understanding timers] this week as a featured article on the embedded.com home page and later in the week as an Editor's Top Pick in the Embedded.com newsletter, where it will get wide visibility among embedded developers. The web site attracts between 600,000 and 700,000 embedded systems developers to view the site and the newsletter goes out to a subscriber base of 100,000 embedded systems developers.

Critiques of a camera (Intova IC-600)
scuba zoomed
[info]zanedp
My digital camera recently ceased to function properly.* Unfortunately, it did so right before my trip to Cancun (I leave on Monday). Amazon had a 6 MP camera with waterproof housing on sale for $108. I figured I'd take a chance on it for my vacation. It arrived yesterday. I sent it back this morning. Read on for my thoughts on the Intova IC-600 camera.

I had never heard of Intova, and was hoping to be pleasantly surprised. I wasn't expecting much; I got even less.

I never got to test the waterproof housing. The camera on its own was unusable, in my opinion. Totally unacceptable.

With the internal flash turned off, it would work OK. The problem was when the flash was enabled. First of all, zoom features, etc. were disabled while the flash was charging. You could only zoom, autofocus, or take a picture when the flash was completely charged. Though, that's annoying—and could have been eliminated with a different software architecture on the camera—the problem was exacerbated by the fact that the flash wouldn't stay charged for more than ~5 sec at a time. It probably took at least 20 seconds for the flash to recharge each time. The autofocus feature took longer than the amount of time the flash was charged.

After a few cycles of charge + zoom/compose + charge + zoom/compose, you're finally ready to take the picture, but by the time the autofocus has figured out what it needs to do, the flash starts recharging, the autofocus calculations are invalidated, and you have to do it again, and again, and again...

Because of the mostly positive reviews on Amazon, I suspect that I received a defective camera. The problem was likely a short that caused the capacitor that charged the flash to discharge. However, the fact that the flash charging took priority over everything else seemed ridiculous. Why does the software need to dedicate all resources to charging the flash and prevent the user from even zoom while its charging? It doesn't. All it needs to do is close a switch, and let it go for a while (or forever). Likely, the software needs to periodically check to see if the flash has completely charged, but that doesn't take 100% of CPU cycles: a timer or analog comparator can do that when necessary, or just some good old-fashioned cooperative multitasking.

*So, what's wrong with my PowerShot S500? Everything works fine except pictures turn out pinkish/purplish over most of the picture. Since I already own a waterproof housing for it, I've thought about buying another one. A search on ebay finds other S500s with the exact same problem as mine being sold for parts which makes me think the sensors may just be reaching the end of their lives, and it would only be a waste of money to buy another one. Disappointing.

Font Squirrel | Handpicked free fonts for graphic designers with commercial-use licenses.
scuba zoomed
[info]zanedp
Matt told me about this.


Font Squirrel | Handpicked free fonts for graphic designers with commercial-use licenses.

Sensus Conservation Systems
scuba zoomed
[info]zanedp
Today, I signed a job offer from Sensus Conservation Systems.

And, in a sort of self-fulfilling prophecy, I will be an "Embedded Firmware Engineer" just like my blog title says I am!

My first day is August 12.

The devil's on iceskates... and winged porcines are overhead...
scuba zoomed
[info]zanedp
I got a job offer. I'm going to take it.

Figures that just as soon as I figure out how to convert my resume to plaintext easily, I don't need it anymore!

Re-entrancy
scuba zoomed
[info]zanedp
I think I forgot to say the most obvious solution of "disable interrupts"!

List of lists in Python
scuba zoomed
[info]zanedp
I haven't found a better way through my googling, so I'm posting this here. If someone has a suggestion for a better (more pythonic) way of producing a list of lists in Python, please post in the comments. This code may be useful if the number of lists (rows) needed is unknown until runtime and, of course, the data for each of the lists is determined at runtime.

lol = [list() for i in xrange(num_lists)] # build a list of empty lists
lol[0].append("Element 0,0") # example usage x = lol[0][0]

Nintendo Number Conversions / ASCII layout
scuba zoomed
[info]zanedp
When I was little, I wondered why when I got more than 9 lives, or too many coins in a Nintendo game, the number went from 9 to A to B... In Super Mario Bros. (SMB1), you'd start getting crowns and other weird "characters."

In Super Mario Bros. 2 (SMB2), the screen showed that I had J coins. Neat! Previously, I had thought it was just converting to hexadecimal, but apparently, it's using base 20, at least. :)

I imagine the code to do the conversion is something like this C-code: displayed_char = num_coins + '0'. That's an easy method of converting to a character, but not if you haven't done range checking to make sure num_coins is actually in the range [0..9]. There are routines in the code for doing the conversion safely, though, since the number of lives correctly displays values over 9 in SMB2, and the score and number of coins are displayed correctly in SMB1.

There are 7 non-alphanumeric characters after '9' in the ASCII and Unicode tables. So, either that's not the code they're using for converting to a character, or they're using a different character set. Since the game was written in Japan, it's quite likely they were using a different character set. It's also even more likely the game had its own unique charset/charmap. Because of the crowns, bricks, etc. that are seen in the original SMB1, I suspect each game had its own charmap: probably one with 'A' following '9'. It is not uncommon for resource-constrained systems to have their own char maps: why waste memory on characters your application will never display? In fact, for my dive computer and ButterTunes, I've changed some of the character mapping for my own purposes, and several of my students changed the mapping used on their LCDs for class projects.

Now, I'm wondering, why was ASCII designed with those 7 non-alphanumeric characters between '9' and 'A'? Surely there was a reason. Any one reading this know what it was? Converting a nybble to hex would have been a little easier without the gap there.

My guess is that the current layout made conversion of a value to a decimal character easier and makes conversion between capital and lowercase letters easier. As seen above, to convert to a ASCII digit, add '0' or add 48; or set bits 4 and 5. To change from capital to lowercase, set bit 5. To change from lowercase to capital, clear bit 5. A little more complicated conversion to hex is the trade-off. Who displays values to the user in hex, anyway? The networking folks display hex to the user and so do debuggers. Do people using debuggers count as "users"?

Converting LaTeX to plain text
scuba zoomed
[info]zanedp
My résumé is typeset using LaTeX. It generates nice PDFs, but many online job applications require plain-text versions to be submitted.

Here is a sequence that converts my LaTeX file to plain text:

$ latex zdpurvis_resume.tex
$ catdvi -e 1 -U zdpurvis_resume.dvi | sed -re "s/\[U\+2022\]/*/g" | sed -re "s/([^^[:space:]])\s+/\1 /g" > zdpurvis_resume.txt


The -e 1 option to catdvi tells it to output ASCII. If you use 0 instead of 1, it will output Unicode. Unicode will include all the special characters like bullets, emdashes, and Greek letters. It also include ligatures for some letter combinations like "fi" and "fl." You may not like that. So, use -e 1 instead. Use the -U option to tell it to print out the unicode value for unknown characters so that you can easily find and replace them.

The second part of the command finds the string [U+2022] which is used to designate bullet characters (•) and replaces them with an asterisk (*).

The third part eats up all the extra whitespace catdvi threw in to make the text full-justified while preserving spaces at the start of lines (indentation).

After running these commands, you would be wise to search the .txt file for the string [U+ to make sure no Unicode characters that can't be mapped to ASCII were left behind and fix them.

Adventure Paper makes Inkjet Waterproof
scuba zoomed
[info]zanedp
Today, I bought a pack of National Geographic "Adventure Paper" from Great Outdoor Provision Co.  Print on it using your inkjet printer, and you've got a waterproof printout.  It only works in inkjet printers, no laser printers.  They intended it to be used for printing maps, but I can see all kinds of other uses.

I printed out a copy of my nitrox EAD table in color and soaked it in the bathtub.  No smudging at all, even when I rubbed it.

The paper is thicker than standard paper, and feels a little slick.  You can't rip it, but you can cut it.  It doesn't take pencil marks well.

The quality of the printout is high.

Cheaper and quicker than laminating.




Update:  A followup posting is here: http://zanedp.livejournal.com/207414.html
Tags: , ,

Magic Eraser erases Dive Slates
scuba zoomed
[info]zanedp
A "Magic Eraser" is really good at erasing a dive slate without sanding and without Soft Scrub.  Just wet the magic eraser sponge (I'm using the el-cheapo Harris Teeter brand) and then rub the slate.  You don't even need to rub hard.  It'll take off pencil and Sharpie.

No need to have soft scrub and brillo pads with you, anymore.  Now, you just need a magic eraser sponge and water.  Water?  That might be hard to come by while scuba diving, right?

HowStuffWorks.com has an article about how magic erasers work.

Wikipedia has an article that includes other uses of melamine foam.

Tags: ,

Home