internal Int32 ReadBatteryType(out wclWeDoBatteryType BatteryType) { BatteryType = wclWeDoBatteryType.btUndefined; if (FBatteryTypeChar == null) { return(wclBluetoothErrors.WCL_E_BLUETOOTH_LE_ATTRIBUTE_NOT_FOUND); } Byte[] Val; Int32 Res = Client.ReadCharacteristicValue(FBatteryTypeChar.Value, wclGattOperationFlag.goNone, out Val); if (Res == wclErrors.WCL_E_SUCCESS && Val != null && Val.Length == 1) { if (Val[0] == 0) { BatteryType = wclWeDoBatteryType.btStandard; } else { if (Val[0] == 1) { BatteryType = wclWeDoBatteryType.btRechargeable; } else { BatteryType = wclWeDoBatteryType.btUnknown; } } } return(Res); }
private void DisconnectHub() { if (FHubConnected) { // Detach all attached devices. DetachDevices(); // We have to release all services. DisconnectServices(); FBatteryType = wclWeDoBatteryType.btUndefined; FHubConnected = false; } }
/// <summary> Creates new WeDo Client. </summary> public wclWeDoHub() { FConnected = false; FHubConnected = false; FBatteryType = wclWeDoBatteryType.btUndefined; FClient = new wclGattClient(); FClient.OnCharacteristicChanged += ClientCharacteristicChanged; FClient.OnConnect += ClientConnect; FClient.OnDisconnect += ClientDisconnect; FDeviceInformation = new wclWeDoDeviceInformationService(FClient, this); FBatteryLevel = new wclWeDoBatteryLevelService(FClient, this); FIo = new wclWeDoIoService(FClient, this); // This service precessed by special way because we need to delegate all methods and events // to the Hub object. FHub = new wclWeDoHubService(FClient, this); FHub.OnButtonStateChanged += HubButtonStateChanged; FHub.OnDeviceAttached += HubDeviceAttached; FHub.OnDeviceDetached += HubDeviceDetached; FHub.OnLowVoltageAlert += HubLowVoltageAlert; FHub.OnHighCurrentAlert += HubHighCurrentAlert; FHub.OnLowSignalAlert += HubLowSignalAlert; // Create attached devices list. FDevices = new List <wclWeDoIo>(); OnConnected = null; OnDisconnected = null; OnButtonStateChanged = null; OnLowVoltageAlert = null; OnDeviceAttached = null; OnDeviceDetached = null; OnHighCurrentAlert = null; OnLowSignalAlert = null; }