diff options
| author | hc <haocheng.xie@respiree.com> | 2026-04-13 15:17:52 +0800 |
|---|---|---|
| committer | hc <haocheng.xie@respiree.com> | 2026-04-13 15:17:52 +0800 |
| commit | d6d9a09d505d11148599a95a5be3e1351edbe0ac (patch) | |
| tree | a5f5891983d1ff207e99f683a5e151519cef4980 /libs/ihealth-sdk/doc/am4.md | |
| parent | e4fb9966e762852bf17f21c8406501d42fae0b61 (diff) | |
Local iHealth SDK, device detail screen, iOS event fixes
Diffstat (limited to 'libs/ihealth-sdk/doc/am4.md')
| -rw-r--r-- | libs/ihealth-sdk/doc/am4.md | 388 |
1 files changed, 388 insertions, 0 deletions
diff --git a/libs/ihealth-sdk/doc/am4.md b/libs/ihealth-sdk/doc/am4.md new file mode 100644 index 0000000..4646f49 --- /dev/null +++ b/libs/ihealth-sdk/doc/am4.md | |||
| @@ -0,0 +1,388 @@ | |||
| 1 | # AM4 Workflow | ||
| 2 | |||
| 3 | ## Import AM4 Module | ||
| 4 | |||
| 5 | ```js | ||
| 6 | import { | ||
| 7 | AM4Module, | ||
| 8 | AMProfileModule | ||
| 9 | } from '@ihealth/ihealthlibrary-react-native'; | ||
| 10 | ``` | ||
| 11 | |||
| 12 | ## APIs | ||
| 13 | |||
| 14 | ### Add and remove listener | ||
| 15 | |||
| 16 | ```js | ||
| 17 | // add | ||
| 18 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 19 | console.log(event); | ||
| 20 | }); | ||
| 21 | |||
| 22 | // remove | ||
| 23 | notifyListener.remove(); | ||
| 24 | ``` | ||
| 25 | |||
| 26 | ### get all connected am4 devices | ||
| 27 | |||
| 28 | ```js | ||
| 29 | AM4Module.getAllConnectedDevices(); | ||
| 30 | ``` | ||
| 31 | |||
| 32 | ### disconnect a am4 devices | ||
| 33 | |||
| 34 | ```js | ||
| 35 | AM4Module.disconnect(mac); | ||
| 36 | ``` | ||
| 37 | |||
| 38 | ### erase am4 memory | ||
| 39 | |||
| 40 | ```js | ||
| 41 | AM4Module.reset(mac); | ||
| 42 | |||
| 43 | // response | ||
| 44 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 45 | if (event.action === AMProfileModule.ACTION_RESET_AM) { | ||
| 46 | if (0 === event[AMProfileModule.RESET_AM]) { | ||
| 47 | console.log('reset fail'); | ||
| 48 | } else if (1 === event[AMProfileModule.RESET_AM]) { | ||
| 49 | console.log('reset success'); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | }); | ||
| 53 | ``` | ||
| 54 | |||
| 55 | ### get the user id bound to the device | ||
| 56 | |||
| 57 | ```js | ||
| 58 | AM4Module.getUserId(mac); | ||
| 59 | |||
| 60 | // response | ||
| 61 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 62 | if (event.action === AMProfileModule.ACTION_USERID_AM) { | ||
| 63 | console.log(event[AMProfileModule.USERID_AM]); | ||
| 64 | } | ||
| 65 | }); | ||
| 66 | ``` | ||
| 67 | |||
| 68 | ### set the user id to the device | ||
| 69 | |||
| 70 | ```js | ||
| 71 | // id: user id, the range is 0~0x7fffffff | ||
| 72 | AM4Module.setUserId(mac, id); | ||
| 73 | |||
| 74 | // response | ||
| 75 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 76 | if (event.action === AMProfileModule.ACTION_SET_USERID_SUCCESS_AM) { | ||
| 77 | console.log('set success'); | ||
| 78 | } | ||
| 79 | }); | ||
| 80 | ``` | ||
| 81 | |||
| 82 | ### setAlarmClock | ||
| 83 | |||
| 84 | ```js | ||
| 85 | |||
| 86 | /** | ||
| 87 | * id: alarm clock id, you can set up to 3 alarm clocks | ||
| 88 | * hour: clock hour | ||
| 89 | * min: clock minates | ||
| 90 | * isRepeat: one time or repeat | ||
| 91 | * weeks: available on the day of the week | ||
| 92 | * isOn: open or close | ||
| 93 | */ | ||
| 94 | |||
| 95 | AM4Module.setAlarmClock(mac, 1, 12, 0, true, [1, 1, 1, 1, 1, 0, 0], false); | ||
| 96 | |||
| 97 | // response | ||
| 98 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 99 | if (event.action === AMProfileModule.ACTION_SET_ALARMINFO_SUCCESS_AM) { | ||
| 100 | console.log('set success'); | ||
| 101 | } | ||
| 102 | }); | ||
| 103 | ``` | ||
| 104 | |||
| 105 | ### get alarm clock ids | ||
| 106 | |||
| 107 | ```js | ||
| 108 | AM4Module.getAlarmClockNum(mac); | ||
| 109 | |||
| 110 | // response | ||
| 111 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 112 | if (event.action === AMProfileModule.ACTION_SET_ALARMINFO_SUCCESS_AM) { | ||
| 113 | console.log(event[AMProfileModule.GET_ALARMNUM_AM]); // e.g. 3 | ||
| 114 | console.log(event[AMProfileModule.GET_ALARMNUM_ID_AM]); // e.g. [1, 2, 3] | ||
| 115 | } | ||
| 116 | }); | ||
| 117 | ``` | ||
| 118 | |||
| 119 | ### get alarm clock detail | ||
| 120 | |||
| 121 | ```js | ||
| 122 | AM4Module.getAlarmClockDetail(mac, [1, 3, 2]); | ||
| 123 | |||
| 124 | // response | ||
| 125 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 126 | if (event.action === AMProfileModule.ACTION_GET_ALARMINFO_AM) { | ||
| 127 | let dataArray = event[BPProfileModule.GET_ALARM_CLOCK_DETAIL]; | ||
| 128 | if (dataArray == undefined) { | ||
| 129 | result = "There is not offline data in device" | ||
| 130 | }else { | ||
| 131 | for (let i = 0; i < dataArray.length; i++) { | ||
| 132 | let offlineData = dataArray[i]; | ||
| 133 | console.log(offlineData[AMProfileModule.GET_ALARM_ID_AM]); | ||
| 134 | console.log(offlineData[AMProfileModule.GET_ALARM_TIME_AM]); | ||
| 135 | console.log(offlineData[AMProfileModule.GET_ALARM_ISREPEAT_AM]); | ||
| 136 | console.log(offlineData[AMProfileModule.GET_ALARM_WEEK_AM]); | ||
| 137 | console.log(offlineData[AMProfileModule.GET_ALARM_ISON_AM]); | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | }); | ||
| 142 | ``` | ||
| 143 | |||
| 144 | ### delete alarm clock by id | ||
| 145 | |||
| 146 | ```js | ||
| 147 | AM4Module.deleteAlarmClock(mac, 1); | ||
| 148 | |||
| 149 | // response | ||
| 150 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 151 | if (event.action === AMProfileModule.ACTION_DELETE_ALARM_SUCCESS_AM) { | ||
| 152 | console.log('delete success'); | ||
| 153 | } | ||
| 154 | }); | ||
| 155 | ``` | ||
| 156 | |||
| 157 | ### set activity reminder interval | ||
| 158 | |||
| 159 | ```js | ||
| 160 | /** | ||
| 161 | * hour | ||
| 162 | * min | ||
| 163 | * isOn: open or close | ||
| 164 | */ | ||
| 165 | AM4Module.setActivityRemind(mac, 0, 30, false); | ||
| 166 | |||
| 167 | // response | ||
| 168 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 169 | if (event.action === AMProfileModule.ACTION_SET_ACTIVITYREMIND_SUCCESS_AM) { | ||
| 170 | console.log('set success'); | ||
| 171 | } | ||
| 172 | }); | ||
| 173 | ``` | ||
| 174 | |||
| 175 | ### get activity reminder interval | ||
| 176 | |||
| 177 | ```js | ||
| 178 | AM4Module.getActivityRemind(mac); | ||
| 179 | |||
| 180 | // response | ||
| 181 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 182 | if (event.action === AMProfileModule.ACTION_GET_ACTIVITY_REMIND_AM) { | ||
| 183 | console.log('get success'); | ||
| 184 | } | ||
| 185 | }); | ||
| 186 | ``` | ||
| 187 | |||
| 188 | ### get am4 information | ||
| 189 | |||
| 190 | ```js | ||
| 191 | AM4Module.queryAMState(mac); | ||
| 192 | |||
| 193 | // response | ||
| 194 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 195 | if (event.action === AMProfileModule.ACTION_QUERY_STATE_AM) { | ||
| 196 | // 0 indicates waist | ||
| 197 | // 1 indicates wrist | ||
| 198 | // 2 indicates sleep | ||
| 199 | console.log(event[AMProfileModule.QUERY_STATE_AM]); | ||
| 200 | // battery level 0~10 | ||
| 201 | console.log(event[AMProfileModule.QUERY_BATTERY_AM]); | ||
| 202 | } | ||
| 203 | }); | ||
| 204 | ``` | ||
| 205 | |||
| 206 | ### set user id to the am4 device | ||
| 207 | |||
| 208 | ```js | ||
| 209 | // The user id range is from 0 to 0x7fffffff | ||
| 210 | AM4Module.setUserId(mac, 8); | ||
| 211 | |||
| 212 | // response | ||
| 213 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 214 | if (event.action === AMProfileModule.ACTION_SET_USERID_SUCCESS_AM) { | ||
| 215 | console.log('set success'); | ||
| 216 | } | ||
| 217 | }); | ||
| 218 | ``` | ||
| 219 | |||
| 220 | ### set user information to the am4 device | ||
| 221 | |||
| 222 | ```js | ||
| 223 | /** | ||
| 224 | * age | ||
| 225 | * height(cm) | ||
| 226 | * weight(lbs) | ||
| 227 | * gender 0: female, 1: male | ||
| 228 | * unit 0: miles, 1: kilometre | ||
| 229 | * target the goal of steps, the range is from 4 ~ 65535 | ||
| 230 | * activityLevel 1: sedentary, 2: active, 3: very active | ||
| 231 | */ | ||
| 232 | AM4Module.setUserInfo(mac, 25, 183, 80, AMProfileModule.AM_SET_MALE, AMProfileModule.AM_SET_UNIT_METRIC, 10000, 1, 30); | ||
| 233 | |||
| 234 | // response | ||
| 235 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 236 | if (event.action === AMProfileModule.ACTION_SET_USERINFO_SUCCESS_AM) { | ||
| 237 | console.log('set success'); | ||
| 238 | } | ||
| 239 | }); | ||
| 240 | ``` | ||
| 241 | |||
| 242 | ### get user information stored in the am4 device | ||
| 243 | |||
| 244 | ```js | ||
| 245 | AM4Module.getUserInfo(mac); | ||
| 246 | |||
| 247 | // response | ||
| 248 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 249 | if (event.action === AMProfileModule.ACTION_GET_USERINFO_AM) { | ||
| 250 | console.log(event[AMProfileModule.GET_USER_AGE_AM]); | ||
| 251 | console.log(event[AMProfileModule.GET_USER_STEP_AM]); | ||
| 252 | console.log(event[AMProfileModule.GET_USER_HEIGHT_AM]); | ||
| 253 | console.log(event[AMProfileModule.GET_USER_SEX_AM]); | ||
| 254 | console.log(event[AMProfileModule.GET_USER_WEIGHT_AM]); | ||
| 255 | console.log(event[AMProfileModule.GET_USER_UNIT_AM]); | ||
| 256 | console.log(event[AMProfileModule.GET_USER_AGE_AM]); | ||
| 257 | console.log(event[AMProfileModule.GET_USER_TARGET1_AM]); | ||
| 258 | console.log(event[AMProfileModule.GET_USER_TARGET2_AM]); | ||
| 259 | console.log(event[AMProfileModule.GET_USER_TARGET3_AM]); | ||
| 260 | } | ||
| 261 | }); | ||
| 262 | ``` | ||
| 263 | |||
| 264 | ### set bmr to the am4 device | ||
| 265 | |||
| 266 | ```js | ||
| 267 | // bmr Basal Metabolic Rate | ||
| 268 | AM4Module.setUserBmr(mac, 2000); | ||
| 269 | |||
| 270 | // response | ||
| 271 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 272 | if (event.action === AMProfileModule.ACTION_SET_BMR_SUCCESS_AM) { | ||
| 273 | console.log('set success'); | ||
| 274 | } | ||
| 275 | }); | ||
| 276 | ``` | ||
| 277 | |||
| 278 | ### get activity steps | ||
| 279 | |||
| 280 | ```js | ||
| 281 | AM4Module.syncActivityData(mac); | ||
| 282 | |||
| 283 | // response | ||
| 284 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 285 | if (event.action === AMProfileModule.ACTION_SYNC_ACTIVITY_DATA_AM) { | ||
| 286 | let dataArray = event[AMProfileModule.SYNC_ACTIVITY_EACH_DATA_AM]; | ||
| 287 | if (dataArray == undefined) { | ||
| 288 | result = "There is not offline data in device" | ||
| 289 | }else { | ||
| 290 | for (let i = 0; i < dataArray.length; i++) { | ||
| 291 | let offlineData = dataArray[i]; | ||
| 292 | console.log(offlineData[AMProfileModule.SYNC_ACTIVITY_DATA_TIME_AM]); | ||
| 293 | console.log(offlineData[AMProfileModule.SYNC_ACTIVITY_DATA_STEP_AM]); | ||
| 294 | console.log(offlineData[AMProfileModule.SYNC_ACTIVITY_DATA_CALORIE_AM]); | ||
| 295 | console.log(offlineData[AMProfileModule.SYNC_ACTIVITY_DATA_STEP_LENGTH_AM]); | ||
| 296 | console.log(offlineData[AMProfileModule.DATAID]); | ||
| 297 | } | ||
| 298 | } | ||
| 299 | } | ||
| 300 | }); | ||
| 301 | ``` | ||
| 302 | |||
| 303 | ### get current activity steps | ||
| 304 | |||
| 305 | ```js | ||
| 306 | AM4Module.syncRealData(mac); | ||
| 307 | |||
| 308 | // response | ||
| 309 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 310 | if (event.action === AMProfileModule.ACTION_SYNC_REAL_DATA_AM) { | ||
| 311 | console.log(offlineData[AMProfileModule.SYNC_REAL_STEP_AM]); | ||
| 312 | console.log(offlineData[AMProfileModule.SYNC_REAL_CALORIE_AM]); | ||
| 313 | console.log(offlineData[AMProfileModule.SYNC_REAL_TOTALCALORIE_AM]); | ||
| 314 | } | ||
| 315 | }); | ||
| 316 | ``` | ||
| 317 | |||
| 318 | ### set current time to am4 device | ||
| 319 | |||
| 320 | ```js | ||
| 321 | AM4Module.syncRealData(mac); | ||
| 322 | |||
| 323 | // response | ||
| 324 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 325 | if (event.action === AMProfileModule.ACTION_SYNC_TIME_SUCCESS_AM) { | ||
| 326 | console.log('set success'); | ||
| 327 | } | ||
| 328 | }); | ||
| 329 | ``` | ||
| 330 | |||
| 331 | ### set hour mode (12 or 24) to am4 device | ||
| 332 | |||
| 333 | ```js | ||
| 334 | /** | ||
| 335 | * AMProfileModule.AM_SET_12_HOUR_MODE(0) | ||
| 336 | * AMProfileModule.AM_SET_24_HOUR_MODE(1) | ||
| 337 | * AMProfileModule.AM_SET_EXCEPT_EUROPE_12_HOUR_MODE(2) | ||
| 338 | * AMProfileModule.AM_SET_EUROPE_12_HOUR_MODE(3) | ||
| 339 | * AMProfileModule.AM_SET_EXCEPT_EUROPE_24_HOUR_MODE(4) | ||
| 340 | * AMProfileModule.AM_SET_EUROPE_24_HOUR_MODE | ||
| 341 | **/ | ||
| 342 | AM4Module.setHourMode(mac, AMProfileModule.AM_SET_24_HOUR_MODE); | ||
| 343 | |||
| 344 | // response | ||
| 345 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 346 | if (event.action === AMProfileModule.ACTION_SET_HOUR_MODE_SUCCESS_AM) { | ||
| 347 | console.log('set success'); | ||
| 348 | } | ||
| 349 | }); | ||
| 350 | ``` | ||
| 351 | |||
| 352 | ### get hour mode (12 or 24) from am4 device | ||
| 353 | |||
| 354 | |||
| 355 | ```js | ||
| 356 | AM4Module.getHourMode(mac); | ||
| 357 | |||
| 358 | // response | ||
| 359 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 360 | if (event.action === AMProfileModule.ACTION_GET_HOUR_MODE_AM) { | ||
| 361 | console.log(event[AMProfileModule.GET_HOUR_MODE_AM]); | ||
| 362 | } | ||
| 363 | }); | ||
| 364 | ``` | ||
| 365 | |||
| 366 | ### get sleep data stored in the am4 | ||
| 367 | |||
| 368 | ```js | ||
| 369 | AM4Module.syncSleepData(mac); | ||
| 370 | |||
| 371 | // response | ||
| 372 | notifyListener = DeviceEventEmitter.addListener(AM4Module.Event_Notify, (event) => { | ||
| 373 | if (event.action === AMProfileModule.ACTION_SYNC_SLEEP_DATA_AM) { | ||
| 374 | let dataArray = event[AMProfileModule.SYNC_SLEEP_DATA_AM]; | ||
| 375 | if (dataArray == undefined) { | ||
| 376 | result = "There is not offline data in device" | ||
| 377 | }else { | ||
| 378 | for (let i = 0; i < dataArray.length; i++) { | ||
| 379 | let offlineData = dataArray[i]; | ||
| 380 | console.log(offlineData[AMProfileModule.SYNC_SLEEP_EACH_DATA_AM]); | ||
| 381 | console.log(offlineData[AMProfileModule.SYNC_SLEEP_DATA_TIME_AM]); | ||
| 382 | console.log(offlineData[AMProfileModule.SYNC_SLEEP_DATA_LEVEL_AM]); | ||
| 383 | console.log(offlineData[AMProfileModule.DATAID]); | ||
| 384 | } | ||
| 385 | } | ||
| 386 | } | ||
| 387 | }); | ||
| 388 | ``` | ||
