private void OnButtonPress(uint data1, uint data2, DateTime time) { if (!_ready) { return; // pressing the button before the unit is ready will do nothing } if (_handlingButtonPress) { return; // if this gets called multiple times in succession, ignore the repeats } lock (_lock) { _handlingButtonPress = true; _button.Interrupt = Port.InterruptMode.InterruptNone; // does this suppress further interrupts? Recording = !Recording; // Flip the recording flag if (Recording) { StatusLed.Flash(); } else { StatusLed.Off(); } Thread.Sleep(250); // glitch filtering _button.Interrupt = Port.InterruptMode.InterruptEdgeHigh; _handlingButtonPress = false; } }
public Controller() { _ready = false; _handlingButtonPress = false; Recording = false; StatusLed.Off(); _button = new InterruptPort(Pins.GPIO_PIN_D7, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeHigh); _button.OnInterrupt += new NativeEventHandler(OnButtonPress); }
public MqttClientWrapper(string brokerAddress, string deviceId, StatusLed statusLed) { _brokerAddress = brokerAddress; _deviceId = deviceId; _sendTopic = $"devices/{_deviceId}/messages/events/"; _client = new MqttClient(_brokerAddress); _client.MqttMsgPublishReceived += OnMessageReceived; WifiDriver.OnWifiConnected += () => { _isConnectedToNetwork = true; }; WifiDriver.OnWifiDisconnected += () => { _isConnectedToNetwork = false; }; WifiDriver.OnWifiDuringConnection += () => { _isConnectedToNetwork = false; }; }
public DisplayFrame WithStatus(StatusLed status, bool value) { if (!Enum.IsDefined(typeof(StatusLed), status)) { throw new ArgumentOutOfRangeException(nameof(status)); } var newStatusLeds = new Dictionary <StatusLed, bool>(_statusLeds); newStatusLeds[status] = value; return(new DisplayFrame(_characters, newStatusLeds)); }
public static DisplayFrame FromDecimal(decimal value, StatusLed signLed) { if (value < MinDecimalValue || value > MaxDecimalValue) { throw new ArgumentOutOfRangeException(nameof(value)); } bool sign = value < 0m; value = Math.Abs(value); int integerDigits = value.NumIntegerDigits(); int fractionalDigits = value.NumFractionalDigits(); int totalDigits = integerDigits + fractionalDigits; if (totalDigits > CharacterCount) { value = Decimal.Round(value, CharacterCount - integerDigits); totalDigits = CharacterCount; fractionalDigits = totalDigits - integerDigits; } var frame = new DisplayFrame(); for (int i = 0; i < integerDigits; i++) { bool dot = (i == integerDigits - 1) && (fractionalDigits > 0); var character = DisplayCharacter.FromDigit(value.GetDigit(integerDigits - i - 1), dot); frame = frame.WithCharacter(totalDigits - i - 1, character); } for (int i = 0; i < fractionalDigits; i++) { var character = DisplayCharacter.FromDigit(value.GetDigit(-i - 1)); frame = frame.WithCharacter(fractionalDigits - i - 1, character); } if (sign) { if (totalDigits == CharacterCount) { frame = frame.WithStatus(signLed, true); } else { var character = DisplayCharacter.FromSymbol('-'); frame = frame.WithCharacter(totalDigits, character); } } return(frame); }
public static void Main() { Debug.Print("Start!"); #if DALMATIAN Led = new StatusLed(); Led.SetBlueLed(true); Thread.Sleep(200); Led.SetBlueLed(false); #endif _dp = new DigiPotClick(Hardware.SocketOne, 200); // WARNING THIS IS TEST CODE THAT DOES NOT EXIT TO DISPATCHER - NO EVENTS FIRED!!! // WARNING THIS IS TEST CODE THAT DOES NOT EXIT TO DISPATCHER - NO EVENTS FIRED!!! // WARNING THIS IS TEST CODE THAT DOES NOT EXIT TO DISPATCHER - NO EVENTS FIRED!!! while (true) { #if DALMATIAN Led.SetRedLed(true); Thread.Sleep(200); Led.SetRedLed(false); #endif Debug.Print("Pos1"); _dp.Resistance = 50; #if DALMATIAN Led.SetRedLed(true); Thread.Sleep(500); Led.SetRedLed(false); Thread.Sleep(100); #endif Thread.Sleep(1000); Debug.Print("Pos2"); _dp.Resistance = 100; #if DALMATIAN Led.SetGreenLed(true); Thread.Sleep(500); Led.SetGreenLed(false); Thread.Sleep(100); #endif Debug.Print("Pos3"); _dp.Resistance = 150; #if DALMATIAN Led.SetBlueLed(true); Thread.Sleep(500); Led.SetBlueLed(false); Thread.Sleep(100); #endif Debug.Print("Pos4"); _dp.Resistance = 200; #if DALMATIAN Led.SetRedLed(true); Thread.Sleep(500); Led.SetRedLed(false); Thread.Sleep(100); #endif Debug.Print("Pos5"); _dp.Resistance = 250; #if DALMATIAN Led.SetGreenLed(true); Thread.Sleep(500); Led.SetGreenLed(false); Thread.Sleep(100); #endif Debug.Print("Pos6"); #if DALMATIAN Led.SetRedLed(true); Thread.Sleep(500); Led.SetRedLed(false); Thread.Sleep(100); #endif Thread.Sleep(1000); } // ReSharper disable once FunctionNeverReturns }
public int SetConsoleLed(ColorLed color, StatusLed st) { return(CCAPISetConsoleLed((int)color, (int)st)); }
public void NotifyReady() { StatusLed.On(); _ready = true; }
public static void WriteDecimal(this DisplayDriver driver, decimal value, StatusLed signLed = StatusLed.Blue) { driver.WriteFrame(DisplayFrame.FromDecimal(value, signLed)); }