internal override void HandleButtons(I2CUIDevice sender, ButtonMask buttons) { bool confirm = false; bool tickAllowed = Buttons == ConfirmationPromptButtons.Tick || Buttons == ConfirmationPromptButtons.TickAndCross; bool crossAllowed = Buttons == ConfirmationPromptButtons.Cross || Buttons == ConfirmationPromptButtons.TickAndCross; if ((buttons & ButtonMask.Button2) == ButtonMask.Button2 && crossAllowed) { confirm = false; } else if ((buttons & ButtonMask.Button5) == ButtonMask.Button5 && tickAllowed) { confirm = true; } else { return; } if (RespondToPrompt != null) { RespondToPrompt(this, confirm); } NotifyExit(); }
internal override void HandleButtons(I2CUIDevice sender, ButtonMask buttons) { if ((buttons & ButtonMask.Button1) == ButtonMask.Button1) HandleBackButton(); else if ((buttons & ButtonMask.Button3) == ButtonMask.Button3) HandleUpButton(); else if ((buttons & ButtonMask.Button4) == ButtonMask.Button4) HandleDownButton(); }
internal override void Activate(I2CUIDevice screen) { base.Activate(screen); Device.ClearScreen(); Device.WriteButtonSymbol(CustomCharacter.Left, ButtonSymbolPosition.Button1); Device.WriteButtonSymbol(CustomCharacter.Up, ButtonSymbolPosition.Button3); Device.WriteButtonSymbol(CustomCharacter.Down, ButtonSymbolPosition.Button4); UpdateScreen(); }
public MenuController(I2CUIDevice device, MenuItem rootMenu) { Device = device; CurrentMenu = rootMenu; DisplayedMenuIndex = 0; Device.ButtonsPushed += HandleButtons; ResetScreenState(); UpdateScreen(); }
internal override void Activate(I2CUIDevice screen) { base.Activate(screen); Device.ClearScreen(); Device.WriteButtonSymbol(CustomCharacter.Left, ButtonSymbolPosition.Button1); UpdateScreen(); TimerCallback callback = delegate (object sender) { UpdateScreen(); }; RefreshTimer = new Timer(callback, null, 0, 250); }
internal override void Activate(I2CUIDevice uiDevice) { base.Activate(uiDevice); Device.ClearScreen(); Device.WriteString(Prompt, 0, 0); if (Buttons == ConfirmationPromptButtons.Cross || Buttons == ConfirmationPromptButtons.TickAndCross) { Device.WriteButtonSymbol(CustomCharacter.Cross, ButtonSymbolPosition.Button2); } if (Buttons == ConfirmationPromptButtons.Tick || Buttons == ConfirmationPromptButtons.TickAndCross) { Device.WriteButtonSymbol(CustomCharacter.Tick, ButtonSymbolPosition.Button5); } }
internal override void HandleButtons(I2CUIDevice sender, ButtonMask buttons) { if ((buttons & ButtonMask.Button1) == ButtonMask.Button1) HandleBackButton(); }
private void HandleButtons(I2CUIDevice sender, ButtonMask buttons) { if (CurrentInfoScreen != null) { CurrentInfoScreen.HandleButtons(sender, buttons); return; } if ((buttons & ButtonMask.Button1) == ButtonMask.Button1) HandleBackButton(); else if ((buttons & ButtonMask.Button3) == ButtonMask.Button3) HandleUpButton(); else if ((buttons & ButtonMask.Button4) == ButtonMask.Button4) HandleDownButton(); else if ((buttons & ButtonMask.Button6) == ButtonMask.Button6) HandleSelectButton(); }
public async void ConnectToScreen(int deviceAddress) { // https://ms-iot.github.io/content/en-US/win10/samples/PinMappingsRPi2.htm // Get a selector string for bus "I2C1" Debug.WriteLine("Looking for I2C bus..."); string aqs = I2cDevice.GetDeviceSelector(); // Find the I2C bus controller with our selector string var dis = await DeviceInformation.FindAllAsync(aqs); if (dis.Count == 0) { Debug.WriteLine("No devices found."); return; } else { Debug.WriteLine("{0} device(s) found.", dis.Count); } // 0x40 is the I2C device address var settings = new I2cConnectionSettings(deviceAddress); settings.BusSpeed = I2cBusSpeed.StandardMode; // Create an I2cDevice with our selected bus controller and I2C settings I2cDevice device = await I2cDevice.FromIdAsync(dis[0].Id, settings); Debug.WriteLine("Got device {0}, {1}", device.DeviceId, device.ConnectionSettings.SlaveAddress); screen = new I2CUIDevice(device); // Menu MenuItem rootMenu = new MenuItem(); MenuItem sensorMenu = new MenuItem("Sensors & Servos"); rootMenu.AddChild(sensorMenu); MenuItem accelerometerMenuItem = new MenuItem("Accelerometer"); accelerometerMenuItem.MenuItemChosen += delegate (MenuItem sender) { menu.PresentInfoScreen(new AccelerometerInfoScreen(car.Accelerometor)); }; sensorMenu.AddChild(accelerometerMenuItem); MenuItem distanceMenuItem = new MenuItem("Distances"); distanceMenuItem.MenuItemChosen += delegate (MenuItem sender) { menu.PresentInfoScreen(new DistancesInfoScreen(car.FrontUltrasonicSensors, car.RearUltrasonicSensor)); }; sensorMenu.AddChild(distanceMenuItem); MenuItem steeringMenuItem = new MenuItem("Steering Servo"); steeringMenuItem.MenuItemChosen += delegate (MenuItem sender) { menu.PresentInfoScreen(new ServoInfoScreen(car.SteeringServo, "Steering")); }; sensorMenu.AddChild(steeringMenuItem); MenuItem throttleMenuItem = new MenuItem("Throttle Servo"); throttleMenuItem.MenuItemChosen += delegate (MenuItem sender) { menu.PresentInfoScreen(new ServoInfoScreen(car.ThrottleServo, "Throttle")); }; sensorMenu.AddChild(throttleMenuItem); // -- MenuItem exitMenuItem = new MenuItem("Shut down"); exitMenuItem.MenuItemChosen += delegate (MenuItem sender) { ConfirmationPromptInfoScreen exitConfirmation = new ConfirmationPromptInfoScreen("Are you sure?"); exitConfirmation.RespondToPrompt += delegate (ConfirmationPromptInfoScreen prompt, bool confirm) { if (confirm) { screen.ClearScreen(); screen.WriteString("Goodbye!", 0, 4); // TODO: Actually shutdown return; } }; menu.PresentInfoScreen(exitConfirmation); }; MenuItem restartProcessMenuItem = new MenuItem("Relaunch"); restartProcessMenuItem.MenuItemChosen += delegate (MenuItem sender) { ConfirmationPromptInfoScreen restartConfirmation = new ConfirmationPromptInfoScreen("Are you sure?"); restartConfirmation.RespondToPrompt += delegate (ConfirmationPromptInfoScreen prompt, bool confirm) { if (confirm) { screen.ClearScreen(); // TODO: Actually relaunch return; } }; menu.PresentInfoScreen(restartConfirmation); }; MenuItem systemMenu = new MenuItem("System"); systemMenu.AddChild(restartProcessMenuItem); systemMenu.AddChild(exitMenuItem); rootMenu.AddChild(systemMenu); menu = new MenuController(screen, rootMenu); }
internal virtual void HandleButtons(I2CUIDevice sender, ButtonMask buttons) { }
internal virtual void Deactivate() { Device = null; }
internal virtual void Activate(I2CUIDevice uiDevice) { Device = uiDevice; }