Esempio n. 1
0
        internal void OnAnalogStateReceived(FirmataEventArgs <AnalogState> eventArgs)
        {
            AnalogStateReceived?.Invoke(session, eventArgs);

            var value      = eventArgs.Value;
            var initChange = !analogPortState[value.Channel].HasValue;

            if (analogPortState[value.Channel] != value.Level)
            {
                analogPortState[value.Channel] = value.Level;

                AnalogStateChangeReceived?.Invoke(session, eventArgs);
            }
        }
Esempio n. 2
0
        internal void OnDigitalStateReceived(FirmataEventArgs <DigitalPortState> eventArgs)
        {
            DigitalStateReceived?.Invoke(session, eventArgs);

            var value = eventArgs.Value;

            for (int i = 0; i < 8; i++)
            {
                var portPinNumber = value.Port * 8 + i;
                var currentState  = value.IsSet(i);
                var initChange    = !digitalPortState[portPinNumber].HasValue;

                if (digitalPortState[portPinNumber] != currentState)
                {
                    digitalPortState[portPinNumber] = currentState;

                    var pinState = new DigitalPinState(value.Port, portPinNumber, currentState, initChange);
                    DigitalStateChangeReceived?.Invoke(session, pinState);
                    //Console.WriteLine("A_端口 {0} 的数字电平: {1}-{2}-{3}", value.Port, value.IsSet(i) ? 'X' : 'O', i, value.Pins);
                }
            }
        }