 |
OMAPI
1.8
Open Movement Public API
|
Go to the documentation of this file.
51 static int testDevice(
int deviceId)
53 int firmwareVersion = -1, hardwareVersion = -1;
63 result =
OmGetVersion(deviceId, &firmwareVersion, &hardwareVersion);
65 printf(
"CHECK #%d: Firmware %d, Hardware %d\n", deviceId, firmwareVersion, hardwareVersion);
72 printf(
"CHECK #%d: Battery at %d%% (%s)\n", deviceId, result, (result >= 100) ?
"charged" :
"charging");
76 result =
OmGetAccelerometer(deviceId, &accelerometer[0], &accelerometer[1], &accelerometer[2]);
80 printf(
"CHECK #%d: Accelerometer at (x = %d, y = %d, z = %d)\n", deviceId, accelerometer[0], accelerometer[1], accelerometer[2]);
90 printf(
"CHECK #%d: Self-test: OK\n", deviceId);
95 printf(
"CHECK #%d: Self-test: FAILED (diagnostic 0x%04x)\n", deviceId, result);
107 printf(
"CHECK #%d: Memory health: FAILED (at least one plane has (or is near to having) no free blocks)\n", deviceId);
111 printf(
"CHECK #%d: Memory health: WARNING (only %d free blocks on worst plane)\n", deviceId, result);
115 printf(
"CHECK #%d: Memory health: OK (at least %d free blocks on each plane)\n", deviceId, result);
126 printf(
"CHECK #%d: Battery health: NOTICE (%d cycles)\n", deviceId, result);
130 printf(
"CHECK #%d: Battery health: OK (%d cycles)\n", deviceId, result);
150 static void deviceCallback(
void *reference,
int deviceId,
OM_DEVICE_STATUS status)
154 printf(
"TEST #%d: Device CONNECTED\n", deviceId);
155 testDevice(deviceId);
159 printf(
"TEST #%d: Device REMOVED\n", deviceId);
163 printf(
"TEST #%d: Error, unexpected status %d\n", deviceId, status);
182 printf(
"Waiting for devices...\n");
197 deviceIds = (
int *)malloc(numDevices *
sizeof(
int));
204 if (result < numDevices) { numDevices = result; }
207 for (i = 0; i < numDevices; i++)
209 printf(
"TEST #%d: Device already CONNECTED\n", deviceIds[i]);
210 testDevice(deviceIds[i]);
222 printf(
"Key pressed, shutting down...\n");
237 printf(
"TEST: self-test all connected devices.\n");
239 if (argc > 1 && !strcmp(argv[1],
"-wait")) { wait = 1; }
Device is being removed, or is already removed.
Device has been connected.
int OmSetDeviceCallback(OmDeviceCallback deviceCallback, void *reference)
Sets the callback function that is called whenever a device is added or removed.
const char * OmErrorString(int status)
Returns an error string for the specified API return code.
int OmGetMemoryHealth(int deviceId)
Determine the health of the NAND flash memory on the specified device.
int OmGetAccelerometer(int deviceId, int *x, int *y, int *z)
Gets the specified device's current accelerometer values.
#define OM_FAILED(value)
Macro to check the specified return value for failure.
int OmSetLed(int deviceId, OM_LED_STATE ledState)
Sets the specified device's LED colour.
int test_main(int argc, char *argv[])
int OmGetVersion(int deviceId, int *firmwareVersion, int *hardwareVersion)
Returns the firmware and hardware versions of the specified device.
int OmGetBatteryLevel(int deviceId)
Queries the specified device for the current battery charging level.
#define OM_VERSION
A numeric code for current API version defined in this header file.
#define OM_MEMORY_HEALTH_ERROR
Threshold at or below which the OmGetMemoryHealth() result should be treated as a failure.
int OmShutdown(void)
Shuts down the Open Movement API.
int OmSelfTest(int deviceId)
Performs a firmware-specific self-test on the specified device (e.g.
#define OM_MEMORY_HEALTH_WARNING
Threshold at or below which the OmGetMemoryHealth() result should be treated as a warning.
int OmGetDeviceIds(int *deviceIds, int maxDevices)
Obtains the device IDs of all connected devices.
int OmGetBatteryHealth(int deviceId)
Determine the health of the battery on the specified device.
int OmStartup(int version)
Initializes the Open Movement API.
OM_DEVICE_STATUS
Device states used in the OmDeviceCallback handler.