OMAPI  1.8
Open Movement Public API
clear.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009-2012, Newcastle University, UK.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
23  * POSSIBILITY OF SUCH DAMAGE.
24  */
25 
42 /* Headers */
43 #include <stdlib.h>
44 #include <stdio.h>
45 #include <string.h>
46 
47 /* API header */
48 #include "omapi.h"
49 
50 
51 /* Clear function */
52 int clear(void)
53 {
54  int numDevices;
55  int *deviceIds;
56  int result;
57  int i;
58 
59  /* Start the API */
60  result = OmStartup(OM_VERSION);
61  if (OM_FAILED(result)) { printf("ERROR: OmStartup() %s\n", OmErrorString(result)); return -1; }
62 
63  /* Query the current number of devices attached */
64  result = OmGetDeviceIds(NULL, 0);
65  if (OM_FAILED(result)) { printf("ERROR: OmGetDeviceIds() %s\n", OmErrorString(result)); return -1; }
66  numDevices = result;
67 
68  /* Get the currently-attached devices ids */
69  deviceIds = (int *)malloc(numDevices * sizeof(int));
70  result = OmGetDeviceIds(deviceIds, numDevices);
71  if (OM_FAILED(result)) { printf("ERROR: OmGetDeviceIds() %s\n", OmErrorString(result)); return -1; }
72  /* Cope with fewer devices being returned (if some were just removed).
73  * If more devices were just attached, we'll ignore them for now.
74  * (Production code wouldn't typically use OmGetDeviceIds but would instead work asynchronously with OmDeviceCallback) */
75  if (result < numDevices) { numDevices = result; }
76 
77  /* For each device currently connected... */
78  for (i = 0; i < numDevices; i++)
79  {
80  int deviceId = deviceIds[i];
81 
82  /* Set the LED to red */
83  result = OmSetLed(deviceId, OM_LED_RED);
84  if (OM_FAILED(result)) { printf("WARNING: OmSetLed() %s\n", OmErrorString(result)); }
85 
86  /* Zero the session id */
87  printf("CLEARING #%d: SessionId = 0...\n", deviceId);
88  result = OmSetSessionId(deviceId, 0);
89  if (OM_FAILED(result)) { printf("WARNING: OmSetSessionId() %s\n", OmErrorString(result)); }
90 
91  /* Clear the metadata */
92  printf("CLEARING #%d: Metadata = <clear>...\n", deviceId);
93  result = OmSetMetadata(deviceId, NULL, 0);
94  if (OM_FAILED(result)) { printf("WARNING: OmSetMetadata() %s\n", OmErrorString(result)); }
95 
96  /* Disable logging */
97  printf("CLEARING #%d: Delays = <never-log>...\n", deviceId);
99  if (OM_FAILED(result)) { printf("WARNING: OmSetDelays() %s\n", OmErrorString(result)); }
100 
101  /* Configure the sample rate to the defaults */
102  printf("CLEARING #%d: AccelConfig = <defaults>...\n", deviceId);
104  if (OM_FAILED(result)) { printf("WARNING: OmSetAccelConfig() %s\n", OmErrorString(result)); }
105 
106  /* Clear the data and commit the settings */
107  printf("CLEARING #%d: Clear data and commit...\n", deviceId);
108  result = OmEraseDataAndCommit(deviceId, OM_ERASE_QUICKFORMAT);
109  if (OM_FAILED(result))
110  {
111  printf("WARNING: OmEraseDataAndCommit() %s\n", OmErrorString(result));
112  }
113  else
114  {
115  /* Set the LED to green */
116  result = OmSetLed(deviceId, OM_LED_GREEN);
117  if (OM_FAILED(result)) { printf("WARNING: OmSetLed() %s\n", OmErrorString(result)); }
118  }
119 
120  }
121 
122  /* Free our list of device ids */
123  free(deviceIds);
124 
125  /* Shutdown the API */
126  result = OmShutdown();
127  if (OM_FAILED(result)) { printf("ERROR: OmShutdown() %s\n", OmErrorString(result)); return -1; }
128 
129  return 0;
130 }
131 
132 
133 /* Main function */
134 int clear_main(int argc, char *argv[])
135 {
136  printf("CLEAR: clear all attached devices.\n");
137  printf("\n");
138  if (argc > 1 && strcmp(argv[1], "ALL") == 0)
139  {
140  return clear();
141  }
142  else
143  {
144  printf("Usage: clear ALL\n");
145  printf("\n");
146  printf("Where: ALL: is a case-sensitive word 'ALL' to confirm clearing all attached devices.\n");
147  printf("\n");
148  printf("Example: clear ALL\n");
149  printf("\n");
150  }
151  return -1;
152 }
153 
OM_ACCEL_DEFAULT_RANGE
#define OM_ACCEL_DEFAULT_RANGE
Default accelerometer range configuration is +/- 8 G.
Definition: omapi.h:761
OmSetSessionId
int OmSetSessionId(int deviceId, unsigned int sessionId)
Sets the specified device's session identifier to be used at the next recording session.
OM_DATETIME_INFINITE
#define OM_DATETIME_INFINITE
Special date/time value for "infinitely late".
Definition: omapi.h:1090
OmErrorString
const char * OmErrorString(int status)
Returns an error string for the specified API return code.
omapi.h
Open Movement API.
OM_LED_RED
rgb(1,0,0) Red
Definition: omapi.h:491
OM_ERASE_QUICKFORMAT
Device file-system is re-created and a new data file is created with the current metadata.
Definition: omapi.h:697
OM_FAILED
#define OM_FAILED(value)
Macro to check the specified return value for failure.
Definition: omapi.h:1033
OmSetLed
int OmSetLed(int deviceId, OM_LED_STATE ledState)
Sets the specified device's LED colour.
OM_ACCEL_DEFAULT_RATE
#define OM_ACCEL_DEFAULT_RATE
Default accelerometer rate configuration is 100Hz.
Definition: omapi.h:753
OmSetAccelConfig
int OmSetAccelConfig(int deviceId, int rate, int range)
Sets the specified device's accelerometer configuration to be used at the next recording session.
OM_VERSION
#define OM_VERSION
A numeric code for current API version defined in this header file.
Definition: omapi.h:225
clear
int clear(void)
Definition: clear.c:52
printf
#define printf(...)
Definition: download.c:57
OmShutdown
int OmShutdown(void)
Shuts down the Open Movement API.
OmSetDelays
int OmSetDelays(int deviceId, OM_DATETIME startTime, OM_DATETIME stopTime)
Sets the specified device's delayed activation start and stop times to use for a new recording sessio...
OM_LED_GREEN
rgb(0,1,0) Green
Definition: omapi.h:489
OmGetDeviceIds
int OmGetDeviceIds(int *deviceIds, int maxDevices)
Obtains the device IDs of all connected devices.
OmSetMetadata
int OmSetMetadata(int deviceId, const char *metadata, int size)
Sets the specified device's metadata scratch buffer to be used for the next recording session.
OmStartup
int OmStartup(int version)
Initializes the Open Movement API.
OmEraseDataAndCommit
int OmEraseDataAndCommit(int deviceId, OM_ERASE_LEVEL eraseLevel)
Erases the specified device storage and commits the metadata and settings.
clear_main
int clear_main(int argc, char *argv[])
Definition: clear.c:134