public async static void ConfigureGpio() { try { await Bus1.Connect(); } catch (Exception) { Debug.WriteLine("No se ha podido conectar con el dispositivo I2C 0x20."); } Bus1.SetPortDirection(0, 0x00); Bus1.SetPortDirection(1, 0x00); Bus1.WritePort(0, 0x00); Bus1.WritePort(1, 0x00); Reset.SetDriveMode(GpioPinDriveMode.Output); Reset.Write(GpioPinValue.High); Buzzer.SetDriveMode(GpioPinDriveMode.Output); Buzzer.Write(GpioPinValue.Low); EntranceRSw1.SetDriveMode(GpioPinDriveMode.Input); TerraceRSw2.SetDriveMode(GpioPinDriveMode.Input); GarageRSw3.SetDriveMode(GpioPinDriveMode.Input); BedroomCurtain.SetDriveMode(GpioPinDriveMode.Input); LivingRoomCurtain.SetDriveMode(GpioPinDriveMode.Input); BathroomCurtain.SetDriveMode(GpioPinDriveMode.Input); GarageDoor.SetDriveMode(GpioPinDriveMode.Input); LightSensor.SetDriveMode(GpioPinDriveMode.Input); }
public static void InitListeners() { EntranceRSw1.ValueChanged += (sender, args) => { if (IsAlarmActivated && EntranceRSw1.Read() == GpioPinValue.Low) { TriggerAlarm("terraza"); } }; TerraceRSw2.ValueChanged += (sender, args) => { if (IsAlarmActivated && TerraceRSw2.Read() == GpioPinValue.Low) { TriggerAlarm("entrada"); } }; GarageRSw3.ValueChanged += (sender, args) => { if (IsAlarmActivated && GarageRSw3.Read() == GpioPinValue.Low) { TriggerAlarm("garaje"); } }; LightSensor.ValueChanged += (sender, args) => { AutoLights(); }; LivingRoomCurtain.ValueChanged += (sender, args) => { if (LivingRoomCurtain.Read() == GpioPinValue.Low && GroundFloorPage.Current != null) { Debug.WriteLine("living_room_curatain state changed"); DevicePage.Current.EnableCurtainButton("living_room_curtain"); } }; BedroomCurtain.ValueChanged += (sender, args) => { if (BedroomCurtain.Read() == GpioPinValue.Low && FirstFloorPage.Current != null) { Debug.WriteLine("bedroom_curatain state changed"); DevicePage.Current.EnableCurtainButton("bedroom_curtain"); } }; BathroomCurtain.ValueChanged += (sender, args) => { if (BathroomCurtain.Read() == GpioPinValue.Low && FirstFloorPage.Current != null) { Debug.WriteLine("bathroom_curatain state changed"); DevicePage.Current.EnableCurtainButton("bathroom_curtain"); } }; GarageDoor.ValueChanged += (sender, args) => { if (GarageDoor.Read() == GpioPinValue.Low && GroundFloorPage.Current != null) { Debug.WriteLine("garage_door state changed"); DevicePage.Current.EnableDoorButton("garage_door"); } }; }