示例#1
0
        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());
            }
        }
示例#2
0
        /// <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;
            }
        }
 // read GPIO and display it
 private void Timer_Tick(object sender, object e)
 {
     LightLEDs(MCP23S17.ReadRegister16());    // do something with the values
 }
示例#4
0
        private byte CheckLedStatus(byte led)
        {
            UInt16 Inputs = MCP23S17.ReadRegister16();

            return(((Inputs & 1 << led) != 0) ? MCP23S17.On : MCP23S17.Off);
        }