Saturday, July 17, 2010

Creating a Time-Lapse Video of Screen Captures

I recently came across a really interesting web site that provided a graphical representation of real-time electricity prices in the wholesale market (something relevant to my day job). The image updated every five minutes, which gave you an interesting real-time perspective. However, there was no option to view past data for a historical perspective. That was disappointing to me because as cool as it was to see the data in real-time, it had a much more significant meaning when compared to recent history.

That inspired me to find a way to capture the screen image every so often and assemble a collection of the images together to view as a video. That couldn't be hard to do, could it?

Well, it really wasn't that hard! Here's how I accomplished the task.

The web site that I wanted to capture the image from uses the Adobe Scalable Vector Graphics ("SVG") viewer. This plugin requires the use of Microsoft Windows and Internet Explorer (Yes, I know it will run on older version of OS X, but we're talking circa 2001 folks; I've updated my operating system since then!) Requiring Adobe SVG was very disappointing since I run mostly Apple Mac OS X machines in my home office. However, I use VMWare Fusion to run Windows 7 Ultimate on the Mac Pro and I also keep an old Sony Vaio desktop around to run Windows 7 Home Professional for these purposes.


For several years, I have used a very powerful and easy-to-use Microsoft Windows screen capture application called MWSnap. Windows 7 does include a built-in screen capture utility, but it is extremely simple and lacks many of the functions that can be found in the basic MWSnap application. The most significant function is the file naming capability. MWSnap allows the use of variables for date and time allowing you to automatically time-stamp the image file. The application also allows you to automatically save the image that you capture. The very best thing about the MWSnap application? It's freeware with donations accepted. Wow! With these features, we were halfway there.

Now we needed a way to automate the screen capture process. Enter the wonderful Windows freeware utility, AutoHotkey. This handy application allows the user to create a script of keyboard and mouse commands along with a powerful set of logic controls to automate almost any process on a Microsoft Windows computer. Although the application has an extremely robust set of features, we only required a relatively simple set of keyboard commands. Through trial and error, we found the biggest trick was to include several pauses to provide Windows or the subject web site sufficient time to respond to the AutoHotkey commands; a simple, but important point for you to remember.

AutoHotkey allows you to create a command script in a text file. Then when you select that script from File Explorer, the application will begin the execution of your custom AutoHotkey commands. For our purposes, we needed to perform a few different tasks. The Adobe SVG plug-in on our subject web site was set to automatically refresh the graphic image every five minutes. However, we found that this process appeared to stop on its own after an hour or two. We decided the best thing was to force a browser screen refresh; launch MWSnap; send the keyboard commands to MWSnap to select and capture the browser screen image (automatically saving the image file with a date and time stamp); and then close MWSnap and patiently wait five minutes to begin the process over again. We included a loop to execute this set of commands for a certain number of hours.

The AutoHotkey script file that we used was very similar to this:

; Pause 5 seconds before starting.
; This will give you time to close the File Explorer window and
; place your mouse pointer in the window that you want captured.
    Sleep, 5000
; Loop ( 36 hours = 432 interations )
    Loop, 432
    {
; Refresh the browser window
    Send, {F5}
; Pause 10 seconds ( 1 second = 1,000 )
    Sleep, 10000
; Page down to view the desired image
    Send, {PGDN}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Open the MWSnap application
    Send, {LWIN}
    Send, mwsnap {ENTER}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Select image in browser window
    Send, {ALT}
    Send, c
    Send, w
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Capture image and autosave according to MWSnap settings
    Send, {ENTER}
; Pause 5 seconds ( 1 second = 1,000 )
    Sleep, 5000
; Close the MWSnap application
    Send, {ALT}
    Send, f
    Send, x
; Pause ( 5 minutes = 300,000, but subtratct the time spent pausing in the script )
    Sleep, 270000
    }

You may find the AutoHotkey script commands very intuitive. If not, a quick read of the well-written documentation in the help file will quickly get you on your way to writing your own command scripts.

After testing the script a few times, it was simply a matter of navigating to the subject web site, firing-off the AutoHotkey script and letting MWSnap capture the images as planned. In the case of my script, 36 hours later I had all of the images that I wanted.

At this point I copied the image files to my Mac Pro to be imported into iPhoto, and then into iMovie where the images were easily assembled into a MPEG-4 video with informative title slides and smooth transitions. I assume that Microsoft Windows Live MovieMaker has similar capabilities, but it is an application that I have not used for many years. If MovieMaker doesn't meet your needs, there are a number of third-party applications that allow you to create a slideshow from a collection of images. Google Picasa is one that I have used in the past. However, it is limited on capabilities for titles, transitions and slideshow speed control.

The finished product from my efforts is presented below. The process was simple enough (and rather fun) that I have a number of new ideas for other time-lapse, screen capture projects. I hope that this short tutorial provides you with some helpful information so that you can create your own time-lapse video. Good luck with your project!

Wednesday, July 14, 2010

Ford Escape Hybrid Brake Failure - Revisited

In a previous blog post, we discussed our unfortunate and frustrating experience with the brake failure on our 2005 Ford Escape Hybrid ("FEH"). More specifically, the failure of the regenerative braking system due to a defective master cylinder and hydraulic control unit ("HCU"). Since posting that information, we have heard from many other Ford Escape and Mercury Mariner Hybrid owners who have experienced the same problem. Most all of them described the harrowing experience of having the electro-hydraulic brakes resort to failsafe mode; some resulting in accidents or near-misses.

I am happy to report that after replacing the defective master cylinder and HCU at a cost of more than $7,000, the regenerative brakes on my FEH have worked without incident for more than six months. No more warning lamps, alarms, or death-defying stops using the hand-controlled emergency parking brake. 

As fully described in my related post, Ford was unresponsive to this matter. In fact, the service managers at three different dealerships either refused to acknowledge this was an issue with the FEH, or failed to bring the problem to my attention, even though Ford had recognized that this was a problem only a few months after I purchased the vehicle. We had previously encouraged anyone else having this problem to file a complaint with the Office of Defects Investigation ("ODI") at the National Highway Traffic Safety Administration ("NHTSA"). If you have not already done so, you can file a safety complaint at this web site... http://www-odi.nhtsa.dot.gov/ivoq/ or by calling the NHTSA Safety Hotline, Monday through Friday from 8:00 a.m. to 8:00 p.m. at (888) 327-4236, TTY: (800) 424-9153.

A number of complaints have already been filed. I have reproduced some of those below to help give you an idea of how similar the problems are amongst those who have experienced this brake failure.

ODI Case Number: 10181021
Component: SERVICE BRAKES, HYDRAULIC:ANTILOCK:ABS WARNING LIGHT
Details: COMPLETE BRAKE FAILURE. FIRST TIME IT OCCURRED WAS ON THE INTERSTATE - 65 MILES AN HOUR AND THE BRAKE LIGHT AND THE ABS LIGHT CAME ON AND THERE WAS A BEEP. THERE WERE THEN NO BRAKES AT ALL. LUCKILY, I WAS ABLE TO GET TO THE SIDE OF THE ROAD AND COAST TO A STOP. TURNED OFF THE TRUCK AND STARTED IT AGAIN AND IT HAD BRAKES. ON THIS LAST INCIDENT, THE SAME THING IN THE SAME ORDER HAPPENED. THANKFULLY, MY WIFE WAS ABLE TO GET THE VEHICLE TO COAST TO A STOP WITHOUT HITTING ANYONE OR ANYTHING. THIS PROBLEM IS VERY DANGEROUS. IT IS INTERMITTENT THUS MAKING IT HARD TO DIAGNOSE. *JB
Occurrences: 2Injuries: 0
Fail Date: 01/27/2007Deaths: 0
Date added to datbase: 1/29/2007 

ODI Case Number: 10204195
Component: SERVICE BRAKES, HYDRAULIC
Details: THE BRAKES HAVE COMPLETELY STOPPED WORKING (EXCEPT FOR THE EMERGENCY BRAKE) 3 TIMES IN ONE MONTH, 4 TIMES IN TWO YEARS. *TR
Occurrences: 4Injuries: 0
Fail Date: 08/26/2007Deaths: 0
Date added to datbase: 9/26/2007 

ODI Case Number: 10221386
Component: SERVICE BRAKES, HYDRAULIC:SWITCHES:BRAKE LIGHT
Details: SERVICE BRAKE SYS MESSAGE ON 2005 FORD ESCAPE HYBRID ALONG WITH BRAKE WARNING LIGHT. *TR
Occurrences: 1Injuries: 0
Fail Date: 03/15/2008Deaths: 0
Date added to datbase: 3/16/2008 

ODI Case Number: 10234772
Component: SERVICE BRAKES, HYDRAULIC
Details: HAVE HAD THE "SERVICE BRAKE SYSTEM" MESSAGE AND THE DASH "BRAKE" INDICATOR LIGHT GO ON RANDOMLY WITHOUT BRAKING FOR A COUPLE OF MONTHS (BEGAN IN MAY 2008) IT HAS BEEN TO THE DEALER TWICE (IN JUNE 2008) AND IS NOW DOING IT AGAIN. THE DEALER REPLACED AN ELECTRICAL HARNESS THIS FIRST TIME AND CLEANED CONTACTS ACCORDING TO A FORD SERVICE ALERT THE SECOND. I ALSO HAD A SIMILAR PROBLEM IN THE FALL OF 2007. THE "SERVICE BRAKE SYSTEM MESSAGE" APPEARED AND THE DASH "BRAKE" INDICATOR LIGHT CAME ON OVER A THREE WEEK PERIOD FOLLOWED BY THE 4X4 SYSTEM AND ABS SYSTEM MAKING NOISE, JERKING THE CAR SEVERAL TIMES AND THEN SHUTTING DOWN WHILE I WAS DRIVING (NOVEMBER 2007). THIS WAS FIXED BY THE DEALER BUT NOW THE CARS INDICATOR LIGHTS ARE TURNING ON AGAIN AND THE PROBLEM DOES NOT SEEM TO ABLE TO FIXED. I AM WORRIED THE BRAKE SYSTEM WILL FAIL AGAIN. *TR
Occurrences: 1Injuries: 0
Fail Date: 07/18/2008Deaths: 0
Date added to datbase: 7/18/2008 

ODI Case Number: 10276404
Component: SERVICE BRAKES, HYDRAULIC
Details: BRAKE SYSTEM FAILURE ON 2005 FORD ESCAPE HYBRID: HIGHWAY DRIVING, NO BRAKING DURING FAILURE - ABS LIGHT COMES ON WITH "SERVICE BRAKE SYSTEM" MESSAGE ON CONSOLE. TOOK TO DEALER WHERE THEY "DIAGNOSED" MASTER CYLINDER FAILURE. REPLACED MASTER CYLINDER. 06 JULY 09 BRAKE SYSTEM FAILURE ON 2005 FORD ESCAPE HYBRID: NORMAL CITY DRIVING UNDER 35MPH ABS LIGHT COMES ON WITH "SERVICE BRAKE SYSTEM" MESSAGE ON CONSOLE. *TR
Occurrences: 1Injuries: 0
Fail Date: 06/26/2009Deaths: 0
Date added to datbase: 7/11/2009 

ODI Case Number: 10306490
Component: SERVICE BRAKES, ELECTRIC
Details: MY 2005 FORD ESCAPE HYBRID HAVE 140,000 MILES ON IT FOR THE PAST 3 WEEKS THE ABS LIGHT AND THE RED TRIANGLE STOP THE CAR SAFELY COME ON WHEN I START THE CAT. I PULL OVER SHUT THE CAR OFF RESTART AND ALL IS WELL UNTIL THE NEXT TIME. *TR
Occurrences: 1Injuries: 0
Fail Date: 01/25/2010Deaths: 0
Date added to datbase: 2/5/2010 

ODI Case Number: 10308285
Component: SERVICE BRAKES, HYDRAULIC
Details: FORD HYBRID ESCAPE BRAKE LIGHT KEEPS COMING ON. I HAVE TO TURN IT OFF AND THEN BACK ON TO GET THE LIGHT OUT. DEALER SAYS ITS A GROUND FAULT AND FORD HAS A NEW WIRING HARNESS, BUT I AM REQUIRED TO PAY FOR IT, ITS AN 05 WITH LESS THAN 8,000 MILES ON IT, YET I AM TO PAY AND FIX FORDS PROBLEM, AND WE ARE TALKING BRAKES HERE, THAT FORD KNOWS ABOUT AND HAS ALREADY IDENTIFIED AND HAS A FIX FOR. IT NEEDS A RECALL. THE ELECTRIC STEERING HAS ALREADY FAILED ONCE AND HAD TO HAVE A NEW COMPUTER FOR THIS. FORD IS HIDING PROBLEMS WITH THE CAR. *TR
Occurrences: 1Injuries: 0
Fail Date: 02/01/2010Deaths: 0
Date added to datbase: 2/10/2010 

ODI Case Number: 10314433
Component: SERVICE BRAKES, HYDRAULIC
Details: WE HAVE EXPERIENCED AN UNUSUAL PROBLEM WITH THE BRAKING SYSTEM IN OUT 2005 FORD ESCAPE HYBRID. THERE HAVE BEEN MAY EPISODES OF THE YELLOW ABS AND THE RED BRAKE WARNING LAMP LIGHTING UP AND THE ALARM SOUNDING OVER THE PAST YEAR. THIS WOULD HAPPEN FOR A COUPLE OF DAYS AND THEN AFTER SHUTTING-OFF THE VEHICLE AND RESTARTING, THE BRAKES RETURNED TO NORMAL OPERATION. WE SPOKE WITH THE SERVICE DEPARTMENT AT OUR DEALERSHIP ABOUT THIS AND BECAUSE THE WARNING LIGHT WASNT ON AT THE TIME, THEY SAID THERE WAS NOTHING THEY COULD DO TO DETECT THE PROBLEM. THE LAST TIME THIS HAPPENED THE BRAKES REVERTED TO FAIL SAFE MODE REQUIRING A "PEDAL TO THE FLOOR" EFFORT TO SLOW THE VEHICLE TO A SAFE STOP LUCKILY WHILE PULLING INTO OUR DRIVEWAY . AFTER THIS WE HAD THE CAR TOWED TO THE DEALER AND WERE TOLD WE NEEDED A NEW "HCU" UNIT AND MASTER CYLINDER WITH A TOTAL REPAIR COST OF $4K+. I DECIDED TO DO SOME RESEARCH AND DISCOVERED MANY CASES OF THE EXACT SAME THING HAPPENING WITH THE SAME YEAR AND MODEL ESCAPE. WE ARE GOING TO WAIT A FEW DAYS TO THINK BEFORE MOVING FORWARD WITH THE REPAIR. *TR
Occurrences: 1Injuries: 0
Fail Date: 02/24/2010Deaths: 0
Date added to datbase: 2/25/2010 

ODI Case Number: 10324854
Component: SERVICE BRAKES, ELECTRIC
Details: 2005 FORD ESCAPE HYBRID CAR HAS 65,000 MILES ON IT WITH NO HISTORY OF BRAKE TROUBLE. COMING DOWNILL THE ABS/BRAKE LIGHTS CAME ON ALONG WITH AN ALARM AND IMMEDIATE LOSS OF THE BRAKES. HAD TO USE MECHANICAL EMERGENCY BRAKES TO STOP. CALLED DEALERSHIP NEXT MORNING TO TOW IT IN, THEN READ ON LINE TO TRY RESTARTING THE CAR THE NEXT DAY AND THE PROBLEM MIGHT BE GONE. CAR STARTED, NO BRAKE ISSUES APPARENT (NO LIGHTS, BRAKES FUNCTIONAL) SO DROVE IT TO DEALERSHIP FOR REVIEW/REPAIR. TOOK COPIES OF ONLINE RESEARCH SHOWING THIS IS AN ISSUE WITH THE CAR. DEALERSHIP CLAIMED IT WAS THE REAR AIR CONDITIONER (HOLE IN THE EVAPORATOR CORE) - THEY HAD REPAIRED THE AC 4 MONTHS PREVIOUSLY, WHICH ONLY LASTED FOR 6 WEEKS. PLANNED TO HAVE THEM REPAIR IT AT THE 65,000 MILE SERVICE ANYWAY. PAID $1033. DROVE CAR HOME THAT NIGHT AND THE ABS/BRAKE LIGHTS WENT ON, ALARM SOUNDED BUT THIS TIME NOT A TOTAL LOSS OF BRAKES. INSTEAD WHENEVER PRESSURE IS APPLIED TO THE BRAKE PEDAL, THERE IS A LOUD THUMPING NOISE FROM THE FRONT BRAKES AND SHUDDERING THROUGHOUT THE CAR. PLAN IS TO RETURN TO DEALERSHIP AFTER THE WEEKEND AND BRING LATEST RESEARCH SHOWING FAULTY HCU UNITS HAVE BEEN FOUND TO BE AN UNDERLYING CAUSE, WHICH FORD IS DENYING. *TR
Occurrences: 1Injuries: 0
Fail Date: 03/31/2010Deaths: 0
Date added to datbase: 4/10/2010 

It would appear as though all of these cases are related to the problem as described in Ford's Technical Service Bulletin TSB 0585 (issued August 5, 2005), which states:

ABS AND BRAKE WARNING LAMP ON WITH DTC C1526 - DTC C1524 MAY ALSO BE PRESENT VEHICLES BUILT PRIOR TO 2/11/2005

ISSUE: Some 2005 Escape Hybrid vehicles built prior to 2/11/2005, may exhibit the yellow ABS and the red brake warning lamps illuminating after the engine is started, and an increase in brake pedal effort. Diagnostic trouble code (DTC) C1526 (Brake Pedal Travel Sensor) will be present in the ABS module, C1524 (Brake Pedal Travel Sensor Calibration Incomplete) may also be present.

ACTION: Install a revised master cylinder. Refer to Workshop Manual Section 206-06.

PART NUMBER PART NAME: 5M6Z-2140-B Master Cylinder

My experience, and that of others, has been that the resolution also includes the replacement of the defective HCU. At this point, the repair of the poorly designed brake system is the sole responsibility of the vehicle owner. I believe that the only way Ford will address this important safety matter is if the NHTSA will take notice. If you have had a problem with the regenerative braking system on your Ford Escape or Mecury Mariner Hybrid, please consider notifying the NHTSA. By contacting the NHTSA, you may help bring this important safety matter to the attention of other owners of these vehicles.

Saturday, July 10, 2010

Improve Your Air Conditioner Efficiency. Clean that Evaporator Coil!

It's been a pretty hot summer here in the Mid-Atlantic. Temperatures have been in the high 90ºs for several days, and the humidity has often been unbearable. During this kind of uncomfortable weather, we are reminded how the contractor who built our house must have saved a few bucks by skimping on the size of the heat pump / air conditioner. The system is adequate for nine or ten months of the year, but in extreme heat or cold, it simply cannot keep up.

We've always been good about maintaining our HVAC system's components to get the most efficiency possible and to help save on our household energy costs. At a minimum, we keep the outdoor condensor unit clear of debris and give it a good water rinse several times each year. We also change the filter in the air handler on a regular basis, at least every three months if not more often during heavy heating and cooling periods.

It was during the most recent filter change that I had the idea to inspect the evaporator coil. You do know what an evaporator coil is, right? [grin] Okay. If you are not familiar with how a heat pump / air conditioner works, here is a really (really) short primer.

A heat pump / air conditioner works on the basic principle of heat transfer. The device moves heat from one place to another; either from outside the house to inside (for heating) or from inside the house to outside (for cooling). This process is done by using refrigerant as the heat transfer medium, a compressor to move the refrigerant, and two sets of coils; one outside the home, the other inside. Although the components all make it look rather complicated, the concept and technology is really pretty simple.

I've already mentioned the outdoor condensor unit. Many people already understand the importance of keeping this device clear of debris and clean. It certainly helps that the unit is relatively large,  obvious, and many times kind of noisy. That serves as a good reminder to give it some attention.

The evaporator coil is just as important to the function of the heat pump / air conditioner. However, since it resides snugly inside the air handler hidden away in your house, it is rather inconspicuous and often ignored. In theory, if you use a good air filter and change it on a regular basis, the evaporator coil should remain clean and tidy. At least that is the theory that I always worked under.

I was prompted to look at the evaporator coil after I had noticed that the air conditioner had become less efficient over time. Even after changing the filter, the air flow from the vents throughout the house was not as cool or as strong as I expected it to be. I knew that there was a problem and suspected that the compressor was failing or that the refrigerant was low. After disconnecting the electrical power to the compressor and the air handler, I removed the access panel to the evaporator coil. The first thing that I noticed was how very cold the evaporator coil was. The compressor and refrigerant level was obviously okay. Then I noticed how the filter really didn't fit that well. It was the correctly-sized filter for this air handler, but the design allows what I consider too much space around the filter's perimeter. Then, when I looked at the evaporator coil, I realized that the space around the filter was quite likely the source of my air conditioner's loss of efficiency.

To be fair, I have seen worse. In another house where I lived, the previous owners had removed the filter completely and operated the heat pump / air conditioner without one. The result was an evaporator coil that was almost entirely plugged. However, I was surprised at the amount of dust and debris collected on this evaporator coil since we had been so good about maintaining the filter.

I knew that I could carefully remove the obvious dirt with a vacuum and brush, but it would be difficult to adequately clean the critical area between the fins of the coil without some assistance. The space is very confined and too difficult to tackle with a water bath or spray, so I decided to use a solvent that was made for the job.

The local home improvement stores were well-stocked with cleaning solutions for the outdoor condensor unit, but none of them seemed to have anything that was made for the evaporator coil located inside the house. I was very concerned about what I used to clean the evaporator coil. I had very legitimate concerns with the solvent's safety. Be certain what you use is non-flammable, non-conductive, and non-toxic. This is critical to your safety while performing the cleaning, and for the safety of the building inhabitants (both humans and pets) after you place the system back into operation. The risk of possible explosion, fire or toxic effects is real and must be carefully considered.

A day of research helped me to discover the Virginia Brand, Blast-A-Coil coil cleaner, distributed by Parker Hannifin Corporation and available for purchase on line from several industrial supply retailers, including Grainger. This solvent was perfect for the job. The coil cleaner comes in an 18 ounce aerosol can. It is made to clean grease, dirt, lint and other debris from the coil surface, and it does not require rinsing after application. More importantly, it is USDA accepted for use in federally inspected meat and poultry plants; it's safe to use indoors and around humans.

The Blast-A-Coil solvent is primarily trichloroethylene. This is a strong and effective cleaning agent, with an interesting history of being used as a medical anesthetic. Prolonged and repeated exposure to trichloroethylene can have serious health consequences, but it is considered safe to use in well-ventilated areas for short periods of time.

I purchased two cans of the cleaner, and recommend that quantity for a typical residential application. Before using the cleaner, I used a vacuum and stiff brush to carefully remove as much of the debris from the evaporator coil as possible. Then after placing a portable fan to blow fresh air in the direction of the air handler and donning safety glasses, I liberally applied the solvent cleaner. The contents discharged quickly from the can in a strong spray / stream, so it should be aimed and applied very carefully.

After allowing the residual solvent to completely evaporate, I inspected the newly cleaned coil. I was pleasantly surprised to observe that it was noticeably much cleaner! I reassembled the air handler, installed a new filter, and reconnected the electrical power to the compressor and air handler. Now it was time to test the air conditioner to see if my efforts made a difference.

Without an anemometer or air flow meter, I cannot provide an exact metric for the improvement. However, I can vouch that the temperature and volume of air coming from the vents throughout the house has greatly improved. And even though the heat pump / air conditioner is not as large as I would like, the unit we have installed is now much more efficient at heating and cooling the house helping us to be more comfortable and saving energy at the same time.

When diagnosing the operation of your heat pump / air conditioner, don't forget all of the components; especially those that stay tucked away inside the air handler in your house. Maybe your evaporator coil needs to be cleaned like ours did. Cleaning it of dirt and debris will make a real difference!

Thursday, June 17, 2010

Javascript Math Functions and Calculator Fun

It's been a few years since I have had to perform any real engineering work. As a senior member of a management consulting firm, my days seem to be focused on business development and project management. However, my wife recently requested some assistance to help develop a special feature for her blog site that got my coding juices flowing again.

My wife has an interest in health, wellness and fitness, and follows the point-counting process for tracking meals. She has used a spreadsheet version of a 'points calculator' and an on line PHP version that we found on a dedicated website, but she wanted a calculator that would be easily accessible to her website visitors. That was my clue to get involved.

With my engineering education and work experience, the majority of my programming experience has been in FORTRAN and machine code. Although I have also had the opportunity to dabble in a number of other languages over the past 30 years. Wanting to make the points calculator an easy plug-in for any blog hosting service that she would ever use, I knew that I would have to code something that could be called from HTML, or just go straight to Javascript and keep the code right within the web page.

I believe that Javascript offers many advantages for a number of typical website functions. There have been security concerns, especially with computers using the Microsoft Windows operating system, but those issues can normally be managed by keeping the operating system up-to-date and using current virus and malware protection; a practice that most computer users follow. Javascript security issues typically do not concern OS X or Linux users. Therefore, Javascript seemed to be the answer to my language question.

The points formula is often cited to follow this convention: Points = Calories / 50 + Fat Grams / 12 - Fiber Grams / 5, where Fiber Grams cannot be greater than 4. Simple enough calculation. The Javascript Math functions were only required to accommodate the Fiber Gram restriction and to round the final answer to one decimal position. Now the only trick was to pass the data between HTML and the Javascript routine.

I decided that the easiest way to accomplish the task was to use the HTML Form Tag, passing the input to a Javascript routine for processing. I was concerned about user input error, so I spent some extra time to code validation routines to make certain that the numeric fields are not blank or filled with non-numeric characters. An incorrect entry will open a dialog box with a warning message and highlight the entry field in error.

I was not familiar with performing more advanced math operations in Javascript. Fortunately, there are many fine sources found online to help educate me. One of my favorite resources for HTML, CSS and Javascript assistance is w3schools.com. Here I found a good introduction to the Javascript Math Object.

Without boring you with a narrative of the coding trial and error, the final version of the calculator, complete with the HTML for the Form, is presented below. The working version can be found at pointsinmylife.com. Forgive me for the use of Tables in the Form, but I found them to be the most effective method to get consistent presentation format results across different browsers.

<script type="text/javascript">
function Calculate(calories, fat, fiber, form)
{
if (form.calories.value == "" || isNaN(form.calories.value)) {
alert( "Please enter a valid number for Calories." );
form.calories.focus();
return false ;
}
if (form.fat.value == "" || isNaN(form.fat.value)) {
alert( "Please enter a valid number for Fat Grams." );
form.fat.focus();
return false ;
}
if (form.fiber.value == "" || isNaN(form.fiber.value)) {
alert( "Please enter a valid number for Fiber Grams." );
form.fiber.focus();
return false ;
}
var A = parseFloat(calories);
var B = parseFloat(fat);
var C = parseFloat(fiber);
form.points.value = Math.round (((A / 50) + (B / 12) - (Math.min(C,4) / 5)) * 10) / 10;
}
function ClearForm(form)
{
form.calories.value = "";
form.fat.value = "";
form.fiber.value = "";
form.points.value = "";
}
</script>
<form method="post">
<table>
<tr colspan="2">
<td width="80%">
Enter Calories:
</td>
<td width="20%" align="right">
<input type="TEXT" name="calories" size="3" />
</td>
</tr>
<tr colspan="2">
<td width="80%">
Enter Fat Grams:
</td>
<td width="20%" align="right">
<input type="TEXT" name="fat" size="3" />
</td>
</tr>
<tr colspan="2">
<td width="80%">
Enter Fiber Grams:
</td>
<td width="20%" align="right">
<input type="TEXT" name="fiber" size="3" />
</td>
</tr>
<tr colspan="2">
<td width="80%">
Calculated Points:
</td>
<td width="20%" align="right">
<input type="TEXT" name="points" size="3" readonly style="border: none; font-weight: bold; color: #990000; background: #99bb55;" />
</td>
</tr>
<tr colspan="2">
<td width="80%">
<input type="button" value="Clear Fields" name="ClearButton" onclick="ClearForm(this.form)" />
</td>
<td width="20%" align="right">
<input type="button" value="Calculate" name="CalculateButton" onclick="return Calculate(this.form.calories.value, this.form.fat.value, this.form.fiber.value, this.form);" />
</td>
</tr>
</table>
</form>
<br />

Sunday, May 23, 2010

Mac Magic Mouse Performance Problems - Resolved!


We love our Mac Pro. It's getting a little dated (2006 vintage), but over time we have upgraded the OS X operating system, graphics card, monitors, and added a bunch of hard drive capacity and memory. It remains a real screamer that can get some processor intensive video and graphics work done in a very quick and impressive manner.

Our one complaint was with the Apple bluetooth wireless keyboard and Mighty Mouse. Ordered as original equipment, the devices never seemed to operate like we expected they would. The keyboard would occasionally miss keystrokes and the mouse would operate the pointer rather erratically. Since the Mac Pro sits directly under the desk and mere inches away from the mouse and keyboard, we knew that signal strength was likely not a problem, so we chalked it up to some kind of local bluetooth interference. We tried hard to eliminate any sources of stray signals, uninstalled and reinstalled the devices, cleared the PRAM and NVRAM... just about everything that we could think of to resolve the problem. After months of attempting to use the wireless keyboard and mouse, we came to the conclusion that the problem was somehow associated with our home office environment and finally gave-up and purchased the Apple USB wired equivalents. As you might expect, the wired keyboard and Might Mouse worked flawlessly, but kept us tethered to the Mac Pro. We were disappointed, but productive nonetheless.


Then several months ago, Apple introduced the Magic Mouse. Being familiar with the benefits of multitouch from it's use on our MacBook Air and iPhone, we were very excited and intrigued about using that kind of function on the Mac Pro. However, I was reluctant to purchase the device because of the previous problems experienced with the bluetooth wireless keyboard and Mighty Mouse. With a leap of faith, we placed our order with Apple.

For the first few months, the Magic Mouse worked as promised. We were relieved. It is a great input device and we highly recommend it for anyone with a Mac using OS X. But then it happened...

After recently upgrading our dual monitor display, we began to experience performance problems with the Magic Mouse. It was behaving just like the old bluetooth Mighty Mouse did with sluggish and erratic pointer movement. Apparently, the new monitors were causing some kind of interference with the bluetooth signal. Facing the prospect of switching back to the wired Mighty Mouse, we decided to do some additional research.

After scouring Google search results on several different keywords, we came across a forum post on thelocale.org. The writer had experienced similar problems with their Mac Pro, and had discovered that the bluetooth and internal Airport module had been wired incorrectly upon initial assembly at the Apple factory.

Carefully following the instructions provided in the forum post (and also available here in a nice and clean PDF format), we re-wired the bluetooth and Airport modules and PRESTO! The Mac Pro's bluetooth performance problems were immediately resolved. Now the Magic Mouse works perfectly with no problems of slow or erratic pointer movement.

We take no credit for determining the problem, but wanted to re-post the solution on this blog in the event that it might help anyone else who is having a similar problem. Our sincere thanks to thelocale.org user rectangular@gmail.com for publishing the orignal solution.