public async static Task GlobalActionIO(IOActions action, int target) { Debug.WriteLine("Begin GlobalActionIO: "); try { if (SensorsCharacteristicsList != null) { if (SensorsCharacteristicsList[(int)SensorIndexes.IO_SENSOR] != null) { if (SensorsCharacteristicsList[(int)SensorIndexes.IO_SENSOR].Configuration != null) { if (SensorsCharacteristicsList[(int)SensorIndexes.IO_SENSOR].Data != null) { await SensorsCharacteristicsList[(int)SensorIndexes.IO_SENSOR].ActionIO(action, target); } } } } } catch (Exception ex) { Debug.WriteLine("Error: GlobalActionIO() - " + ex.Message); } Debug.WriteLine("End GlobalActionIO: "); }
private async Task ActionIO(IOActions action, int target) { Debug.WriteLine("Begin ActionIO: "); //Set in Remote mode byte[] bytes = new byte[] { 0x00 };//off bool res = true; try { if (action == IOActions.Enable) { if (!IO_IsOn) { //Turn IO ON bytes[0] = 0; res = await this.WriteSensor(bytes, ServiceCharacteristicsEnum.Data); if (res) { bytes[0] = 1;//on res = await this.WriteSensor(bytes, ServiceCharacteristicsEnum.Configuration); if (res) { IO_IsOn = true; Debug.WriteLine("Sensor IO enabled."); } } if (!res) { Debug.WriteLine("Sensor IO enable failed."); } } } else if ((action == IOActions.On) || (action == IOActions.AllOff)) { if (IO_IsOn) { if (action == IOActions.AllOff) { target = 0; } if (!(new List <int> { 0, 1, 2, 4, 3, 5, 6, 7 }.Contains(target))) { return; } //Turn on target/s (Could toggle) bytes[0] = (byte)target; res = await this.WriteSensor(bytes, ServiceCharacteristicsEnum.Data); if (res) { switch (target) { case 0: Debug.WriteLine("LEDS/BUZZ OFF"); break; case 1: Debug.WriteLine("LED1 ON"); break; case 2: Debug.WriteLine("LED21 ON"); break; case 4: Debug.WriteLine("BUZZ ON"); break; case 3: Debug.WriteLine("LEDs 1&2 ON"); break; case 5: Debug.WriteLine("BUZZ & LED1 ON"); break; case 6: Debug.WriteLine("BUZZ & LED2 ON"); break; case 7: Debug.WriteLine("LEDs 1&2 + BUZZ ON"); break; } } else { Debug.WriteLine("IO failed for target {0}", target); } } } else { //Disable if (IO_IsOn) { bytes[0] = 0; res = await this.WriteSensor(bytes, ServiceCharacteristicsEnum.Data); if (res) { bytes[0] = 0;//off res = await this.WriteSensor(bytes, ServiceCharacteristicsEnum.Configuration); } if (res) { IO_IsOn = false; Debug.WriteLine("Sensor IO disabled"); } else { Debug.WriteLine("Sensor IO disable failed"); } } } } catch (Exception ex) { Debug.WriteLine("Error: ActionIO() - " + ex.Message); } Debug.WriteLine("End ActionIO: "); }