public static void KeyCodeToDirection( KeypadKeyCode keyCode, ref eDirectionType direction) { var lookup = new FPGA.Collections.ReadOnlyDictionary <KeypadKeyCode, eDirectionType>() { { KeypadKeyCode.D2, eDirectionType.Up }, { KeypadKeyCode.D8, eDirectionType.Down }, { KeypadKeyCode.D4, eDirectionType.Left }, { KeypadKeyCode.D6, eDirectionType.Right } }; direction = lookup[keyCode]; }
public static void Controls( // ADC FPGA.OutputSignal <bool> ADC1NCS, FPGA.OutputSignal <bool> ADC1SLCK, FPGA.OutputSignal <bool> ADC1DIN, FPGA.InputSignal <bool> ADC1DOUT, // keypad FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, ref KeysDTO controlsState) { KeypadKeyCode internalCode = 0; FPGA.Config.Link(internalCode, out controlsState.KeyCode); ushort adcChannel1Value = 32767, adcChannel2Value = 32767; FPGA.Config.Link(adcChannel1Value, controlsState.X); FPGA.Config.Link(adcChannel2Value, controlsState.Y); Sequential keypadHandler = () => { Keypad4x4.ReadASCIICode(K7, K6, K5, K4, K3, K2, K1, K0, out internalCode); }; FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(20), keypadHandler); Sequential joystickHandler = () => { while (true) { ADC102S021.Read(out adcChannel1Value, out adcChannel2Value, ADC1NCS, ADC1SLCK, ADC1DIN, ADC1DOUT); } }; FPGA.Config.OnStartup(joystickHandler); }
public static void ReadASCIICode( FPGA.OutputSignal <bool> K7, FPGA.OutputSignal <bool> K6, FPGA.OutputSignal <bool> K5, FPGA.OutputSignal <bool> K4, FPGA.InputSignal <bool> K3, FPGA.InputSignal <bool> K2, FPGA.InputSignal <bool> K1, FPGA.InputSignal <bool> K0, out KeypadKeyCode code ) { byte rawCode = 0; ReadCode(K7, K6, K5, K4, K3, K2, K1, K0, out rawCode); FPGA.Collections.ReadOnlyDictionary <byte, Drivers.KeypadKeyCode> asciiLookup = new FPGA.Collections.ReadOnlyDictionary <byte, Drivers.KeypadKeyCode>() { { 0, Drivers.KeypadKeyCode.None }, { 1, Drivers.KeypadKeyCode.D1 }, { 2, Drivers.KeypadKeyCode.D2 }, { 3, Drivers.KeypadKeyCode.D3 }, { 4, Drivers.KeypadKeyCode.STOP }, { 5, Drivers.KeypadKeyCode.D4 }, { 6, Drivers.KeypadKeyCode.D5 }, { 7, Drivers.KeypadKeyCode.D6 }, { 8, Drivers.KeypadKeyCode.GO }, { 9, Drivers.KeypadKeyCode.D7 }, { 10, Drivers.KeypadKeyCode.D8 }, { 11, Drivers.KeypadKeyCode.D9 }, { 12, Drivers.KeypadKeyCode.LOCK }, { 13, Drivers.KeypadKeyCode.ENT }, { 14, Drivers.KeypadKeyCode.D0 }, { 15, Drivers.KeypadKeyCode.ESC }, { 16, Drivers.KeypadKeyCode.PWR }, }; code = asciiLookup[rawCode]; }
public static void LEDControl( KeypadKeyCode keyCode, FPGA.OutputSignal <bool> DOUT) { bool internalDOUT = false; FPGA.Config.Link(internalDOUT, DOUT); Func <bool> hasCode = () => keyCode != 0; int position = 0, direction = 0; FPGA.Config.Suppress("W0003", position); uint intensity = 6; bool autoPilotEnabled = false; uint[] buff = new uint[5]; Sequential autoPilotHandler = () => { if (!autoPilotEnabled) { return; } HandlePosition(position, direction, 0, buff.Length, out position); }; FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(300), autoPilotHandler); Sequential codeHandler = () => { // there is race condition possible - code can go down while handler is executed switch (keyCode) { case KeypadKeyCode.GO: autoPilotEnabled = true; break; case KeypadKeyCode.STOP: autoPilotEnabled = false; break; case KeypadKeyCode.D4: direction = -1; if (!autoPilotEnabled) { HandlePosition(position, direction, 0, buff.Length, out position); } break; case KeypadKeyCode.D5: direction = 0; break; case KeypadKeyCode.D6: direction = 1; if (!autoPilotEnabled) { HandlePosition(position, direction, 0, buff.Length, out position); } break; case KeypadKeyCode.D2: intensity = intensity == 10 ? 10 : intensity + 1; break; case KeypadKeyCode.D8: intensity = intensity == 0 ? 0 : intensity - 1; break; } FPGA.Runtime.WaitForAllConditions(!hasCode()); }; FPGA.Config.OnSignal(hasCode(), codeHandler); Sequential ledHandler = () => { for (byte i = 0; i < buff.Length; i++) { uint data = 0; if (i == position) { data = (intensity * 25); } buff[i] = data; } Graphics.Draw(buff, out internalDOUT); }; const bool trigger = true; FPGA.Config.OnSignal(trigger, ledHandler); Sequential onStartup = () => { var outerRow = new FPGA.OutputSignal <byte>(); var outerCol = new FPGA.OutputSignal <byte>(); var dto = new Position(); FPGA.Config.Link(dto.row, outerRow); FPGA.Config.Link(dto.col, outerCol); DTOTest(dto); }; FPGA.Config.OnStartup(onStartup); }
public static void LEDControl( KeypadKeyCode keyCode, FPGA.OutputSignal <bool> DOUT, FPGA.OutputSignal <bool> Servo ) { bool internalDOUT = false; FPGA.Config.Link(internalDOUT, DOUT); byte servoValue = 0; MG996R.Continuous(servoValue, Servo); uint[] buff = new uint[64]; byte baseColor = 5; Sequential ledHandler = () => { uint color = 0; switch (keyCode) { case KeypadKeyCode.STOP: color = (uint)(baseColor << 16); break; case KeypadKeyCode.GO: color = (uint)((baseColor << 8) | (baseColor << 16)); break; case KeypadKeyCode.LOCK: color = (uint)(baseColor << 8); break; case KeypadKeyCode.D2: baseColor++; break; case KeypadKeyCode.D8: baseColor--; break; // servo control case KeypadKeyCode.ENT: servoValue = 0; break; case KeypadKeyCode.D0: servoValue = 60; break; case KeypadKeyCode.ESC: servoValue = 120; break; case KeypadKeyCode.PWR: servoValue = 180; break; } for (byte i = 0; i < buff.Length; i++) { buff[i] = color; } Graphics.Draw(buff, out internalDOUT); }; const bool trigger = true; FPGA.Config.OnSignal(trigger, ledHandler); }