Beispiel #1
0
        private void OnNewValueEvent(object sender, ArduinoSerialCom.ValueChangedEventArgs valueChangedEventArgs)
        {
            TypeStaticValue value = _serial.getValue(valueChangedEventArgs.Index);

            if (valueChangedEventArgs.Index == _tempIndex && value.getType() == TypeStaticValue.StaticType.INT)
            {
                _lastTemp = (double)value.getIntValue() / 100;
            }
            else if (valueChangedEventArgs.Index == _lightIndex && value.getType() == TypeStaticValue.StaticType.INT)
            {
                _lastLight = value.getIntValue();
            }
            else if (valueChangedEventArgs.Index == _windDirectionIndex && value.getType() == TypeStaticValue.StaticType.INT)
            {
                _lastWindDirection = value.getIntValue();
            }
            PrintWeatherMessage();
        }
        private bool parseValue(int begin, int end)
        {
            byte            typebyte = _readBuffer[begin + 1];
            byte            index    = _readBuffer[begin];
            TypeStaticValue value    = null;

            try
            {
                switch (typebyte)
                {
                case 0x0:
                    value = new TypeStaticValue(_readBuffer[begin + 2]);
                    break;

                case 0x1:
                    value = new TypeStaticValue(parseUInt(_readBuffer[begin + 2], _readBuffer[begin + 3]));
                    break;

                case 0x2:
                    value = new TypeStaticValue((char)_readBuffer[begin + 2]);
                    break;

                case 0x3:
                    value = new TypeStaticValue(parseString(begin + 2, end));
                    break;
                }
            }
            catch (Exception err)
            {
            }
            if (value != null)
            {
                emitNewValue(index, value);
                return(true);
            }
            else
            {
                return(false);
            }
        }
 public ReceivedValueEventArgs(int index, TypeStaticValue value)
 {
     Index = index;
     Value = value;
 }
 private void emitNewValue(int index, TypeStaticValue v)
 {
     onNewValue?.Invoke(this, new ReceivedValueEventArgs(index, v));
 }