Free42 Extensions to the HP-42S Instruction Set

iPhone Accelerometer, Location Services, and Compass Support

Starting with version 1.4.66, Free42 for iPhone and iPod touch has three new functions to query the device's hardware. They are:

ACCEL  Query the accelerometer. The three components of the acceleration vector are returned in the X, Y, and Z registers. Holding the device facing you, in portrait orientation, and the dock connector pointing towards the floor, positive X is acceleration toward the left, positive Y is acceleration downwards, and positive Z is acceleration away from you -- or, in terms of gravity, positive X is gravity pulling to the right, positive Y is gravity pulling upwards, and positive Z is gravity pulling toward you.
Note: Accelerations are returned in units of Earth gravities, not m/s2 as you might expect. The iPhone API documentation does not mention the specific conversion factor used by the device.

LOCAT  Query Location Services*. The location is returned as follows: latitude in X, longitude in Y, elevation in Z, and horizontal and vertical accuracy in a two-element vector in T. The latitude and longitude are given in decimal degrees, with North and East being positive; the elevation and accuracies are given in meters. If an accuracy is -1, that means that the corresponding measurement is not valid.
* The iPod touch uses Skyhook (a proprietary WiFi-MAC-to-location mapping service) to determine its position; the first generation iPhone uses Skyhook and cellular triangulation, and the iPhone 3G and 3GS have a built-in GPS receiver. All of these means of determining the device's location are exposed through the unified Location Services API.

HEADING  Query the compass. This only works on the iPhone 3GS; other devices return Nonexistent. It returns the following data: magnetic heading in X, true heading in Y, heading accuracy in Z, and the raw magnetic vector in a three-element vector in T. The headings and accuracy are given in degrees, where North is 0, East is 90, and so on; the components of the magnetic vector are given in microteslas. The components are oriented with respect to the device along the same axes as the accelerometer readouts.

HP-41 Time Module Emulation

I have implemented the following HP-41 Time Module functions: ADATE ATIME ATIME24 CLK12 CLK24 DATE DATE+ DDAYS DMY DOW MDY TIME
I have not implemented these HP-41 Time Module functions:
Live Clock Display: CLKT CLKTD CLOCK
Clock Control: CORRECT RCLAF SETAF SETDATE SETIME T+X
Stopwatch: RCLSW RUNSW SETSW STOPSW SW
Alarms: ALMCAT ALMNOW XYZALM

These functions are documented in detail in the HP-82182A Time Module Owner's Manual and the HP-41CX Owner's Manual, both of which can be viewed on-line here, here, and here, or you can get them in PDF on CD-ROM or DVD-ROM here.

Note: the date functions handle dates between October 15, 1582, and September 10, 4320. The former is the first day of the Gregorian Calendar, and the latter is 999,999 days later.
The format in which the date functions accept and return dates is MM.DDYYYY when in MDY mode, and DD.MMYYYY when in DMY mode.

ADATE  Appends the contents of the X register to the ALPHA register, formatted as a date value: in DMY mode, DD.MMYYYY is displayed as DD.MM.YYYY, and in MDY mode, MM.DDYYYY is displayed as MM/DD/YYYY. If the number of digits of the display mode is 4 or less, the century part is omitted; if it is 2 or less, the entire year part is omitted; and if it is 0, the months or days part is omitted (in DMY or MDY mode, respectively).

ATIME  Appends the contents of the X register to the ALPHA register, formatted as a time value: HH.MMSSss is displayed as HH:MM:SS.ss. In CLK12 mode, times with HH between -23 and 23 are displayed in 12-hour format: -23 to -13 as -HH-12 PM; -12 to -1 as -HH PM; 0 as 12 AM; 1 to 11 as HH AM; 12 as 12 PM; 13 to 23 as HH-12 PM. When |HH| ≥ 24, the sign is ignored, and HH is shown as is, with no AM or PM appended. In CLK24 mode, HH between -1 and -11 are displayed as -HH+12; all other values are shown as |HH|. No AM or PM are displayed.
If the number of digits of the display mode is 4 or less, the centiseconds part is omitted; if it is 2 or less, the seconds part is omitted; and if it is 0, the minutes part is omitted.

ATIME24  Like ATIME (see above), except it always formats the time in 24-hour format, regardless of the CLK12/CLK24 setting.

CLK12  Display the time in 12-hour format with AM/PM.

CLK24  Display the time in 24-hour format.

DATE  Returns the current date to the X register. In MDY mode, the date is returned as MM.DDYYYY, and in DMY mode, it is returned as DD.MMYYYY. In addition, when executed from the keyboard, this also displays the date formatted as "MM/DD/YYYY DOW" or "DD.MM.YYYY DOW", respectively.

DATE+  Takes a date from the Y register, and adds a number of days from the X register.

DDAYS  Calculates the number of days between the date in the Y register and the date in the X register. If the date in the Y register is earlier, then the result will be positive.

DMY  Display, return, and accept dates in day/month/year format.

DOW  Calculates the day of the week for the date in the X register. Returns a number from 0 to 6, where 0 is Sunday, 1 is Monday, and so on. When this function is executed from the keyboard, the day is also displayed in a human-friendly format, i.e. MON for Monday, TUE for Tuesday, etc.

MDY  Display, return, and accept dates in month/day/year format.

TIME  Returns the current time in the X register. The time is returned in HH.MMSSss format, with HH from 0 to 23, regardless of the CLK12/CLK24 setting. In addition, when executed from the keyboard, it displays the time in "HH:MM:SS AM" or "HH:MM:SS" format, when the display format is CLK12 or CLK24, respectively.

Go back.