def read_battery_state(self): """Triggers a battery state notification. N.B. that a :meth:`~notifications` call that registers a callback for battery state should have been done prior to calling this method. """ if self.callback is None: warnings.warn("No battery callback is registered!", RuntimeWarning) libmetawear.mbl_mw_datasignal_read(self.data_signal)
def temperature_callback(data): if data.contents.type_id == DataTypeId.FLOAT: data_ptr = cast(data.contents.value, POINTER(c_float)) print("Temperature read: {0:.2f} C".format(data_ptr.contents.value)) else: raise RuntimeError('Incorrect data type id: ' + str(data.contents.type_id)) # On-Die temperature (channel 0) is always present. channel = 0 # Subscribe to notifications data_signal = libmetawear.mbl_mw_multi_chnl_temp_get_temperature_data_signal( c.board, channel) fcn_dptr = Fn_DataPtr(temperature_callback) libmetawear.mbl_mw_datasignal_subscribe(data_signal, fcn_dptr) for i in range(5): libmetawear.mbl_mw_datasignal_read(data_signal) time.sleep(1.0) # Unsubscribe to notifications libmetawear.mbl_mw_datasignal_unsubscribe(data_signal) time.sleep(1.0) c.disconnect()