private string GetPiFaceStatus() { try { UInt16 inputs = MCP23S17.ReadRegister16(); JObject status = new JObject( new JProperty("LED", new JObject( new JProperty("LED0", ((inputs & 1 << PiFaceDigital2.LED0) != 0) ? "on" : "off"), new JProperty("LED1", ((inputs & 1 << PiFaceDigital2.LED1) != 0) ? "on" : "off"), new JProperty("LED2", ((inputs & 1 << PiFaceDigital2.LED2) != 0) ? "on" : "off"), new JProperty("LED3", ((inputs & 1 << PiFaceDigital2.LED3) != 0) ? "on" : "off"), new JProperty("LED4", ((inputs & 1 << PiFaceDigital2.LED4) != 0) ? "on" : "off"), new JProperty("LED5", ((inputs & 1 << PiFaceDigital2.LED5) != 0) ? "on" : "off"), new JProperty("LED6", ((inputs & 1 << PiFaceDigital2.LED6) != 0) ? "on" : "off"), new JProperty("LED7", ((inputs & 1 << PiFaceDigital2.LED7) != 0) ? "on" : "off") )), new JProperty("Switch", new JObject( new JProperty("SW0", ((inputs & 1 << PiFaceDigital2.SW0) == 0) ? "on" : "off"), new JProperty("SW1", ((inputs & 1 << PiFaceDigital2.SW1) == 0) ? "on" : "off"), new JProperty("SW2", ((inputs & 1 << PiFaceDigital2.SW2) == 0) ? "on" : "off"), new JProperty("SW3", ((inputs & 1 << PiFaceDigital2.SW3) == 0) ? "on" : "off") ))); return(status.ToString()); } catch (Exception ex) { return("에러발생" + ex.ToString()); } }
/// <summary>Updates the values from the Pi.</summary> internal void UpdateValuesFromPi() { var result = MCP23S17.ReadRegister16(); // do something with the values for (int i = 0; i < 8; i++) { var bitIsOn = (result & (1 << i)) != 0; this.Inputs.First(input => input.Id == i).IsOn = !bitIsOn; bitIsOn = (result & (1 << (i + 8))) != 0; this.Outputs.First(input => input.Id == i).IsOn = bitIsOn; } }
private async void InitSPIchip() { try { await MCP23S17.InitSPI(); MCP23S17.InitMCP23S17(); MCP23S17.setPinMode(0x00FF); MCP23S17.pullupMode(0x00FF); MCP23S17.WriteWord(0x0000); } catch (Exception ex) { } }
private async void InitSPI() { try { await MCP23S17.InitSPI(); MCP23S17.InitMCP23S17(); MCP23S17.setPinMode(0x00FF); // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default MCP23S17.pullupMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default MCP23S17.WriteWord(0x0000); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default } catch (Exception ex) { } }
/// <summary>Initializes the pi face.</summary> public async Task InitializePiFace() { await MCP23S17.InitializeSpiDevice(); MCP23S17.Initialize(); MCP23S17.SetPinMode(0x00FF); // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default MCP23S17.SetPullUpMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default MCP23S17.WriteWord(0x0000); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default // ReSharper disable once ExceptionNotDocumented this.timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(200) }; this.timer.Tick += this.TimerOnTick; this.timer.Start(); this.SendStatus(); }
private string ControlPiFaceLed(string[] query) { int targetLedNo; string resultString = "XXXXXXX"; if (int.TryParse(query[1], out targetLedNo) == true && targetLedNo < 8) { MCP23S17.WritePin(LedAdress[targetLedNo], this.CheckLedStatus(LedAdress[targetLedNo]) == MCP23S17.On ? MCP23S17.Off : MCP23S17.On); //MCP23S17.WritePin(LedAdress[targetLedNo], Convert.ToByte(query[1])); resultString = "ok"; } return(resultString); }
private void TimerOutputs_Tick(object sender, object e) { if (OnFlag == 0) { MCP23S17.pullupMode(PFDII.LED2, Off); MCP23S17.WritePin(PFDII.LED2, On); MCP23S17.WritePin(PFDII.LED3, On); MCP23S17.WritePin(PFDII.LED4, On); OnFlag = 1; } else { MCP23S17.WritePin(PFDII.LED2, Off); MCP23S17.WritePin(PFDII.LED3, Off); MCP23S17.WritePin(PFDII.LED4, Off); OnFlag = 0; } }
/* Initialize GPIO, SPI, and the display */ private async void InitAll() { try { await MCP23S17.InitSPI(); MCP23S17.InitMCP23S17(); MCP23S17.setPinMode(0x00FF); // 0x0000 = all outputs, 0xffff=all inputs, 0x00FF is PIFace Default MCP23S17.pullupMode(0x00FF); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default MCP23S17.WriteWord(0x0000); // 0x0000 = no pullups, 0xffff=all pullups, 0x00FF is PIFace Default Switch0.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch0_PointerPressed), true); Switch0.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch0_PointerReleased), true); Switch1.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch1_PointerPressed), true); Switch1.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch1_PointerReleased), true); Switch2.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch2_PointerPressed), true); Switch2.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch2_PointerReleased), true); Switch3.AddHandler(PointerPressedEvent, new PointerEventHandler(Switch3_PointerPressed), true); Switch3.AddHandler(PointerReleasedEvent, new PointerEventHandler(Switch3_PointerReleased), true); initTimer(); } catch (Exception ex) { //Text_Status.Text = "Exception: " + ex.Message; //if (ex.InnerException != null) //{ // Text_Status.Text += "\nInner Exception: " + ex.InnerException.Message; //} //return; } }
// read GPIO and display it private void Timer_Tick(object sender, object e) { LightLEDs(MCP23S17.ReadRegister16()); // do something with the values }
private void LED7_Unchecked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.LED7, Off); }
private void LED1_Unchecked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.LED1, Off); RelayA.IsChecked = false; // LED1 and RelayB are the same output pin }
private void LED0_Checked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.LED0, On); RelayB.IsChecked = true; // LED0 and RelayA are the same output pin }
private void RelayB_Unchecked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.RelayB, Off); RelayBImage.Source = RelayOff.Source; LED0.IsChecked = false;; }
private void RelayB_Checked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.RelayB, On); RelayBImage.Source = RelayOn.Source; LED0.IsChecked = true;; }
public MCP23S17RegisterBase(int address, MCP23S17 chip) { this.address = address; this.chip = chip; }
private byte CheckLedStatus(byte led) { UInt16 Inputs = MCP23S17.ReadRegister16(); return(((Inputs & 1 << led) != 0) ? MCP23S17.On : MCP23S17.Off); }
public MCP23S17RegisterBit(int bit_num, int address, MCP23S17 chip) : base(address, chip) { this.bit_num = bit_num; }
private void LED6_Checked(object sender, RoutedEventArgs e) { MCP23S17.WritePin(PFDII.LED6, On); }