The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/psmv: Implement battery status function

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2494>

+58 -2
+58 -2
src/xrt/drivers/psmv/psmv_driver.c
··· 321 321 struct xrt_vec3_i32 gyro_bias; 322 322 }; 323 323 324 + enum psmv_battery_state 325 + { 326 + //! Battery is between 0% and 20% 327 + BATTERY_STATE_0_20 = 0x00, 328 + //! Battery is between 20% and 40% 329 + BATTERY_STATE_20_40 = 0x01, 330 + //! Battery is between 40% and 60% 331 + BATTERY_STATE_40_60 = 0x02, 332 + //! Battery is between 60% and 80% 333 + BATTERY_STATE_60_80 = 0x03, 334 + //! Battery is between 80% and 100% 335 + BATTERY_STATE_80_100 = 0x04, 336 + //! Battery is full 337 + BATTERY_STATE_100 = 0x05, 338 + //! Battery is charging 339 + BATTERY_STATE_CHARGING = 0xEE, 340 + //! Battery is plugged in, but is full 341 + BATTERY_STATE_CHARGING_FULL = 0xFE, 342 + }; 343 + 324 344 /*! 325 345 * Input package for ZCM1. 326 346 */ ··· 339 359 struct psmv_vec3_u16_wire gyro_f2; 340 360 uint8_t temp_mag[6]; 341 361 uint8_t timestamp_low; 342 - uint8_t pad[49 - 44]; 362 + uint8_t ext_data[5]; 343 363 }; 364 + static_assert(sizeof(struct psmv_input_zcm1) == 49, "bad struct size"); 344 365 345 366 /*! 346 367 * Input package for ZCM2. ··· 364 385 uint8_t pad1[2]; 365 386 uint8_t timestamp_low_copy; 366 387 }; 388 + static_assert(sizeof(struct psmv_input_zcm2) == 44, "bad struct size"); 367 389 368 390 /*! 369 391 * A parsed sample of accel and gyro. ··· 382 404 uint32_t buttons; 383 405 uint16_t timestamp; 384 406 uint16_t timestamp_copy; 385 - uint8_t battery; 407 + enum psmv_battery_state battery; 386 408 uint8_t seq_no; 387 409 388 410 ··· 948 970 return XRT_SUCCESS; 949 971 } 950 972 973 + static xrt_result_t 974 + psmv_get_battery_status(struct xrt_device *xdev, bool *out_present, bool *out_charging, float *out_charge) 975 + { 976 + struct psmv_device *psmv = psmv_device(xdev); 977 + 978 + float charge = 0.0; 979 + float charging = false; 980 + switch (psmv->last.battery) { 981 + case BATTERY_STATE_0_20: charge = 0.1; break; 982 + case BATTERY_STATE_20_40: charge = 0.3; break; 983 + case BATTERY_STATE_40_60: charge = 0.5; break; 984 + case BATTERY_STATE_60_80: charge = 0.7; break; 985 + case BATTERY_STATE_80_100: charge = 0.9; break; 986 + case BATTERY_STATE_100: charge = 1.0; break; 987 + case BATTERY_STATE_CHARGING: 988 + // this is a gross estimate, but it's the best we can do 989 + charge = 0.5; 990 + charging = true; 991 + break; 992 + case BATTERY_STATE_CHARGING_FULL: 993 + charge = 1.0; 994 + charging = true; 995 + break; 996 + } 997 + 998 + *out_charging = charging; 999 + *out_charge = charge; 1000 + 1001 + *out_present = true; 1002 + 1003 + return XRT_SUCCESS; 1004 + } 951 1005 952 1006 /* 953 1007 * ··· 1037 1091 psmv->base.update_inputs = psmv_device_update_inputs; 1038 1092 psmv->base.get_tracked_pose = psmv_device_get_tracked_pose; 1039 1093 psmv->base.set_output = psmv_device_set_output; 1094 + psmv->base.get_battery_status = psmv_get_battery_status; 1040 1095 psmv->base.name = XRT_DEVICE_PSMV; 1041 1096 psmv->base.binding_profiles = binding_profiles; 1042 1097 psmv->base.binding_profile_count = ARRAY_SIZE(binding_profiles); ··· 1228 1283 // clang-format on 1229 1284 1230 1285 psmv->base.supported.orientation_tracking = true; 1286 + psmv->base.supported.battery_status = true; 1231 1287 psmv->base.supported.position_tracking = psmv->ball != NULL; 1232 1288 psmv->base.device_type = XRT_DEVICE_TYPE_ANY_HAND_CONTROLLER; 1233 1289