//private readonly GameBootstrapper bootstrapper; public ShellViewModel() { //this.bootstrapper = new GameBootstrapper(SimulatorRegistrations); //var gameBox = this.bootstrapper.Box; var boxBaseOptions = new BoxBaseOptions { IdleTimeout = TimeSpan.FromMinutes(3) }; var gameBox = new BoxSimulator(boxBaseOptions); this.game = new SimpleGame(gameBox, new SimpleGameOptions { LightUp = TimeSpan.FromMilliseconds(400), Pause = TimeSpan.FromMilliseconds(200), Retries = 3, MaxChainLength = 5, MaxSpeedFactor = 4 }); this.GreenOne = new LightyButtonViewModel(Colors.Green, GetLightableButton(gameBox, BoxBase.GreenOneButtonIdentifier)); this.YellowOne = new LightyButtonViewModel(Colors.Gold, GetLightableButton(gameBox, BoxBase.YellowOneButtonIdentifier)); this.RedOne = new LightyButtonViewModel(Colors.Red, GetLightableButton(gameBox, BoxBase.RedOneButtonIdentifier)); this.BlueOne = new LightyButtonViewModel(Colors.Blue, GetLightableButton(gameBox, BoxBase.BlueOneButtonIdentifier)); this.WhiteOne = new LightyButtonViewModel(Colors.LightGray, GetLightableButton(gameBox, BoxBase.WhiteOneButtonIdentifier)); this.GreenTwo = new LightyButtonViewModel(Colors.Green, GetLightableButton(gameBox, BoxBase.GreenTwoButtonIdentifier)); this.YellowTwo = new LightyButtonViewModel(Colors.Gold, GetLightableButton(gameBox, BoxBase.YellowTwoButtonIdentifier)); this.RedTwo = new LightyButtonViewModel(Colors.Red, GetLightableButton(gameBox, BoxBase.RedTwoButtonIdentifier)); this.BlueTwo = new LightyButtonViewModel(Colors.Blue, GetLightableButton(gameBox, BoxBase.BlueTwoButtonIdentifier)); this.WhiteTwo = new LightyButtonViewModel(Colors.LightGray, GetLightableButton(gameBox, BoxBase.WhiteTwoButtonIdentifier)); }
public BoxSimulator(BoxBaseOptions options) : base(options) { var models = new[] { new LightyButtonModel(GreenOneButtonIdentifier), new LightyButtonModel(YellowOneButtonIdentifier), new LightyButtonModel(RedOneButtonIdentifier), new LightyButtonModel(BlueOneButtonIdentifier), new LightyButtonModel(WhiteOneButtonIdentifier), new LightyButtonModel(WhiteTwoButtonIdentifier), new LightyButtonModel(BlueTwoButtonIdentifier), new LightyButtonModel(RedTwoButtonIdentifier), new LightyButtonModel(YellowTwoButtonIdentifier), new LightyButtonModel(GreenTwoButtonIdentifier) }; this.LedButtonPinPins = models.ToList(); this.lookup = this.LedButtonPinPins.ToDictionary(lbpp => lbpp.ButtonIdentifier, lbpp => lbpp); this.IdleTimer = this.LedButtonPinPins .Select(lbpp => lbpp.Button) .Merge() .Select(s => false) .Throttle(this.Options.IdleTimeout); this.OnButtonDown = this.LedButtonPinPins.Select(lbpp => lbpp.ButtonDown).Merge(); this.OnButtonUp = this.LedButtonPinPins.Select(lbpp => lbpp.ButtonUp).Merge(); this.OnButton = this.LedButtonPinPins.Select(lbpp => lbpp.Button).Merge(); this.Reset = Observable.FromEvent <ResetArgs>(action => this.ResetEvent += action, action => this.ResetEvent -= action); }
public Box(BoxBaseOptions options, GpioController gpioController) : base(options) { Log.Verbose("Constructing LED Button configs..."); var lightableButtons = new[] { new LightableButtonConfig(18 /* 12 */, 27 /* 13 */, GreenOneButtonIdentifier), new LightableButtonConfig(23 /* 16 */, 22 /* 15 */, YellowOneButtonIdentifier), new LightableButtonConfig(24 /* 18 */, 10 /* 19 */, RedOneButtonIdentifier), new LightableButtonConfig(25 /* 22 */, 9 /* 21 */, BlueOneButtonIdentifier), new LightableButtonConfig(8 /* 24 */, 11 /* 23 */, WhiteOneButtonIdentifier), new LightableButtonConfig(7 /* 26 */, 5 /* 29 */, WhiteTwoButtonIdentifier), new LightableButtonConfig(12 /* 32 */, 6 /* 31 */, BlueTwoButtonIdentifier), new LightableButtonConfig(16 /* 36 */, 13 /* 33 */, RedTwoButtonIdentifier), new LightableButtonConfig(20 /* 38 */, 19 /* 35 */, YellowTwoButtonIdentifier), new LightableButtonConfig(21 /* 40 */, 26 /* 37 */, GreenTwoButtonIdentifier) }; Log.Verbose("Generating LedButtonPinPins..."); this.LedButtonPinPins = lightableButtons.Select(lb => { Log.Verbose($"Opening LED Pin {lb.LedPin}, setting output..."); gpioController.OpenPin(lb.LedPin, PinMode.Output); Log.Verbose($"Setting LED {lb.LedPin} to Low..."); gpioController.Write(lb.LedPin, PinValue.Low); Log.Verbose($"Opening Button Pin {lb.ButtonPin} as Input..."); gpioController.OpenPin(lb.ButtonPin, PinMode.InputPullDown); Log.Verbose("Wrap LightableButton"); return(new LightableButton(gpioController, lb)); }).ToList(); Log.Verbose("Creating lookup..."); this.lookup = this.LedButtonPinPins.ToDictionary( lbpp => new ButtonIdentifier(lbpp.Player, lbpp.Color), lbpp => lbpp); Log.Verbose("Creating IdleTimer..."); this.IdleTimer = this.LedButtonPinPins .Select(lbpp => lbpp.Button) .Merge() .Select(s => false) .Throttle(this.Options.IdleTimeout); this.OnButtonDown = this.LedButtonPinPins .Select(lbpp => lbpp.ButtonDown) .Merge(); this.OnButtonUp = this.LedButtonPinPins .Select(lbpp => lbpp.ButtonUp) .Merge(); this.OnButton = this.LedButtonPinPins .Select(lbpp => lbpp.Button) .Merge(); var ctrlAltDeleteButtons = new[] { GreenOneButtonIdentifier, GreenTwoButtonIdentifier }; var pressedCtrlAltDeleteButtons = ctrlAltDeleteButtons .Select(id => this.lookup[id].Button) .CombineLatest() .Throttle(TimeSpan.FromSeconds(1)) .Where(latest => latest.All(button => button.IsPressed)) .Select(list => new ResetArgs()); pressedCtrlAltDeleteButtons.Subscribe(list => { Log.Information("CtrlAltDelete happened!"); }); this.Reset = pressedCtrlAltDeleteButtons; }