private static async Task Blinky(Microbit microbit) { MatrixState[] glyphs = { MatrixState.HEART_FULL, MatrixState.HEART_EMPTY, MatrixState.CIRCLE_FULL, MatrixState.CIRCLE_EMPTY, MatrixState.SQUARE_FULL, MatrixState.SQUARE_EMPTY, MatrixState.DIAMOND_FULL, MatrixState.DIAMOND_EMPTY, MatrixState.X_MARK, MatrixState.CHECK_MARK, MatrixState.ARROW_UP, MatrixState.ARROW_UPRIGHT, MatrixState.ARROW_RIGHT, MatrixState.ARROW_DOWNRIGHT, MatrixState.ARROW_DOWN, MatrixState.ARROW_DOWNLEFT, MatrixState.ARROW_LEFT, MatrixState.ARROW_UPLEFT, }; for (var i = 0; i < 50; i++) { await microbit.LedService.WriteLedMatrixState(glyphs[i % glyphs.Length]); await Task.Delay(TimeSpan.FromSeconds(1)); } }
public override bool MatchAction(Reflex reflex, out object param) { // See if there's a filter defining which player we should be. If not, use bit0. if (playerId == GamePadSensor.PlayerId.Dynamic) { playerId = GamePadSensor.PlayerId.All; ReflexData data = reflex.Data; for (int i = 0; i < data.Filters.Count; i++) { if (data.Filters[i] is PlayerFilter) { playerId = ((PlayerFilter)data.Filters[i]).playerIndex; } } } bool shaken = false; #if !NETFX_CORE Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId); if (bit != null) { int currGeneration = bit.State.Generation; if (currGeneration != 0 && currGeneration != prevGeneration) { Vector3 currAccel = bit.State.Acc; Vector3 accelDiff = currAccel - prevAccel; prevAccel = currAccel; prevGeneration = currGeneration; float strength = accelDiff.Length(); // Default range [1, 2] float minStrength = 1; float maxStrength = 2; // 2G - This is the maximum length of micro:bit's accelerometer vector (configured in kodu-microbit.hex). int stronglyCount = reflex.Data.GetFilterCount("filter.strongly"); // Range adjustment upward to [1.5, 2] minStrength += stronglyCount * 0.166f; int weaklyCount = reflex.Data.GetFilterCount("filter.weakly"); // Range adjustment downward to [0.075, 0.2] minStrength -= weaklyCount * 0.308f; maxStrength -= weaklyCount * 0.6f; shaken = (strength >= minStrength && strength <= maxStrength); //System.Diagnostics.Debug.WriteLine(String.Format("range [{0},{1}], value {2}, {3}", minStrength, maxStrength, strength, shaken ? "SHAKE!" : "")); } } #endif param = shaken; return(shaken); }
public override bool MatchAction(Reflex reflex, out object param) { float result = 0; // See if there's a filter defining which player we should be. If not, use pad0. if (playerId == GamePadSensor.PlayerId.Dynamic) { playerId = GamePadSensor.PlayerId.All; ReflexData data = reflex.Data; for (int i = 0; i < data.Filters.Count; i++) { if (data.Filters[i] is PlayerFilter) { playerId = ((PlayerFilter)data.Filters[i]).playerIndex; } } } #if !NETFX_CORE Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId); if (bit != null) { // Get the correct button. switch (pin) { case MicrobitPin.Pin1: result = bit.ReadPinValue(0, Microbit.EPinOperatingMode.Digital); break; case MicrobitPin.Pin2: result = bit.ReadPinValue(1, Microbit.EPinOperatingMode.Digital); break; case MicrobitPin.Pin3: result = bit.ReadPinValue(2, Microbit.EPinOperatingMode.Digital); break; } } #endif // Return as a parameter a vector that can be used for input to the movement system, so // that players can drive and turn bots using gamepad buttons. param = new Vector2(0, result / 255.0f); return(result != 0); }
public override bool MatchAction(Reflex reflex, out object param) { bool result = false; // See if there's a filter defining which player we should be. If not, use bit0. if (playerId == GamePadSensor.PlayerId.Dynamic) { playerId = GamePadSensor.PlayerId.All; ReflexData data = reflex.Data; for (int i = 0; i < data.Filters.Count; i++) { if (data.Filters[i] is PlayerFilter) { playerId = ((PlayerFilter)data.Filters[i]).playerIndex; } } } #if !NETFX_CORE Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId); if (bit != null) { // Get the correct button. switch (button) { case MicrobitButton.Left: result = bit.State.ButtonA.IsPressed(); break; case MicrobitButton.Right: result = bit.State.ButtonB.IsPressed(); break; } } #endif // Return as a parameter a vector that can be used for input to the movement system, so // that players can drive and turn bots using gamepad buttons. param = new Vector2(0, 1); return(result); }
public override bool MatchAction(Reflex reflex, out object param) { UpdateCommands(); // See if there's a filter defining which player we should be. If not, use pad0. if (playerId == GamePadSensor.PlayerId.Dynamic) { playerId = GamePadSensor.PlayerId.All; ReflexData data = reflex.Data; for (int i = 0; i < data.Filters.Count; i++) { if (data.Filters[i] is PlayerFilter) { playerId = ((PlayerFilter)data.Filters[i]).playerIndex; } } } bool match = false; param = null; this.tiltPosition = Vector2.Zero; #if !NETFX_CORE // TODO @*******: use the player# to get the right Microbit, or blended from all if no player#. Microbit bit = MicrobitExtras.GetMicrobitOrNull(playerId); if (bit != null) { tiltPosition = new Vector2(bit.State.Acc.Y, -bit.State.Acc.X); tiltPosition = DeadZone(tiltPosition * tiltPosition * new Vector2(Math.Sign(tiltPosition.X), Math.Sign(tiltPosition.Y)), 0.01f); } #endif param = this.tiltPosition; match = (this.tiltPosition != Vector2.Zero); // only if not centered return(match); } // end of MatchAction()
} // end of c'tor public void Update(Camera camera) { if (Active) { GamePadInput pad = GamePadInput.GetGamePad0(); #if !NETFX_CORE // For games using micro:bit, allow buttons to dismiss ingame dialogs. if (InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { Microbit bit = MicrobitExtras.GetMicrobitOrNull(GamePadSensor.PlayerId.All); if (bit != null) { // Allow either button to dismiss display. if (bit.State.ButtonA.IsPressed() || bit.State.ButtonB.IsPressed()) { Deactivate(); } } } #endif if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); Deactivate(); } if (!string.IsNullOrEmpty(textB)) { if (Actions.B.WasPressed) { Actions.B.ClearAllWasPressedState(); userHitA = false; Deactivate(); } } // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); if (InGame.inGame.State == InGame.States.Active) { InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } // Scroll text??? if (blob.NumLines != 0) { int scroll = MouseInput.ScrollWheel - MouseInput.PrevScrollWheel; if (Actions.Up.WasPressedOrRepeat || scroll > 0) { ScrollDown(); } if (Actions.Down.WasPressedOrRepeat || scroll < 0) { ScrollUp(); } // If we're not shutting down... if (Active) { } // end if not shutting down. } // We should be on top and owning all input // focus so don't let anthing trickle down. GamePadInput.ClearAllWasPressedState(); // Disable the help overlay's tool icon because in some situations // it can overlap the text making it unreadable. HelpOverlay.ToolIcon = null; // If active we need to pre-render the text to the 1k rendertarget since // changing render targets on the Xbox forces a resolve. if (dirty) { PreRender(); dirty = false; } // If we're rendering this into a 1280x720 rt we need a matching camera to calc mouse hits. if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; // Adjust for position and scaling of final rendering. touchHit -= renderPosition; touchHit /= renderScale; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; // Adjust for position and scaling of final rendering. hit -= renderPosition; hit /= renderScale; if (useRtCoords) { //hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // end of Update()
private static async Task TestMicrobit(int scanSeconds) { var microbit = await Microbit.ScanAndConnect(timeout : TimeSpan.FromSeconds(scanSeconds)); if (microbit == null) { Log.Error("BBC Micro:bit not found."); return; } if (microbit.HasDeviceInformationService()) { await SkipIfFail(async() => Log.Information($"System ID: {await microbit.DeviceInformationService.GetSystemId()}")); await SkipIfFail(async() => Log.Information($"Model Number: {await microbit.DeviceInformationService.GetModelNumber()}")); await SkipIfFail(async() => Log.Information($"Serial Number: {await microbit.DeviceInformationService.GetSerialNumber()}")); await SkipIfFail(async() => Log.Information( $"Firmware Revision: {await microbit.DeviceInformationService.GetFirmwareRevision()}")); await SkipIfFail(async() => Log.Information( $"Hardware Revision: {await microbit.DeviceInformationService.GetHardwareRevision()}")); await SkipIfFail(async() => Log.Information( $"Software Revision: {await microbit.DeviceInformationService.GetSoftwareRevision()}")); await SkipIfFail(async() => Log.Information( $"Manufacturer Name: {await microbit.DeviceInformationService.GetManufacturerName()}")); } else { Log.Information($"{microbit} doesn't have DeviceInformationService."); } if (microbit.HasBatteryService()) { await SkipIfFail(async() => Log.Information($"Battery Level: {await microbit.BatteryService.GetBatteryLevel()}")); } else { Log.Information($"{microbit} doesn't have BatteryService."); } await microbit.ButtonService.Subscribe( (button, pressed) => { var b = button == ButtonService.Button.A ? "Button A" : "Button B"; Log.Information(pressed ? $"{b} pressed." : $"{b} released."); return(Task.CompletedTask); }); await microbit.AccelerometerService.WriteAccelerometerPeriod(1000); await microbit.AccelerometerService.Subscribe( (x, y, z) => { Log.Information($"x: {x}, y: {y}, z: {z}."); return(Task.CompletedTask); }); await Blinky(microbit); await microbit.Disconnect(); }
} // end of c'tor public void Update(Camera camera) { if (Active) { // If we've just been activated, ignore input to prevent // accidental dismissal. if (Time.WallClockTotalSeconds < activationTime + deadInputTime) { return; } GamePadInput pad = GamePadInput.GetGamePad0(); if (InGame.inGame.State == InGame.States.Active && InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { #if !NETFX_CORE // For games using micro:bit, allow buttons to dismiss ingame dialogs. if (InGame.inGame.CurrentUpdateMode == InGame.UpdateMode.RunSim) { Microbit bit = MicrobitExtras.GetMicrobitOrNull(GamePadSensor.PlayerId.All); if (bit != null) { // Allow either button to dismiss display. if (bit.State.ButtonA.IsPressed() || bit.State.ButtonB.IsPressed()) { Deactivate(); } } } #endif // We need to be able to slip out to the mini-hub here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.MiniHub.WasPressed) { Actions.MiniHub.ClearAllWasPressedState(); Deactivate(); InGame.inGame.SwitchToMiniHub(); } // We need to be able to slip out to the tool menu here since // continuous, repeated calls to TextDisplay can lock the // user out of control. if (Actions.ToolMenu.WasPressed) { Actions.ToolMenu.ClearAllWasPressedState(); Deactivate(); InGame.inGame.CurrentUpdateMode = InGame.UpdateMode.ToolMenu; } } if (Actions.Select.WasPressed) { Actions.Select.ClearAllWasPressedState(); Deactivate(); } // If we're rendering this into a 1280x720 rt we need a matching camera to calc mouse hits. if (useBackgroundThumbnail) { camera = new PerspectiveUICamera(); camera.Resolution = new Point(1280, 720); } if (GamePadInput.ActiveMode == GamePadInput.InputMode.Touch) { for (int i = 0; i < TouchInput.TouchCount; i++) { TouchContact touch = TouchInput.GetTouchContactByIndex(i); Vector2 touchHit = touch.position; if (useRtCoords) { touchHit = ScreenWarp.ScreenToRT(touch.position); } HandleTouchInput(touch, touchHit); } } else if (GamePadInput.ActiveMode == GamePadInput.InputMode.KeyboardMouse) { Vector2 hit = MouseInput.PositionVec; if (useRtCoords) { hit = MouseInput.GetMouseInRtCoords(); } HandleMouseInput(hit); } } // end if active. } // end of Update()