private void TerminalJControllerConnected(object sender, EventArgs e) { Invoke((MethodInvoker) delegate() { cbConnectTerminal.Checked = true; cbConnectTerminal.Image = JeromeControl.Properties.Resources.icon_connected; fStatus.pTerminalStatus.BackgroundImage = JeromeControl.Properties.Resources.icon_connected; }); foreach (WX0BTerminalSwitchTemplate st in TerminalTemplate.switches) { terminalJConnection.setLineMode(st.button, 1); terminalJConnection.setLineMode(st.led, 0); } terminalJConnection.setLineMode(TerminalTemplate.pttLED, 0); terminalJConnection.setLineMode(TerminalTemplate.lockLED, 0); terminalJConnection.setLineMode(TerminalTemplate.pttButton, 1); terminalJConnection.setLineMode(TerminalTemplate.lockButton, 1); displayActiveSwitch(); displayLockSwitch(); displayPTT(); WX0BTerminalSwitch s = tx ? lockSwitch : activeSwitch; if (terminalJConnection.connected) { foreach (WX0BTerminalSwitchTemplate st in TerminalTemplate.switches) { terminalJConnection.switchLine(st.led, switches[st] == s ? 1 : 0); } } }
public void switchLine(JeromeController controller, int line, int state) { controller.switchLine(enLine, 0); controller.switchLine(line, state); //Thread.Sleep(1); controller.switchLine(clkLine, 1); //Thread.Sleep(1); controller.switchLine(clkLine, 0); controller.switchLine(enLine, 1); }
protected void controllerConnected(object sender, EventArgs e) { bool senderFound = false; KeyValuePair <JeromeConnectionParams, JeromeConnectionState> senderEntry = connections.FirstOrDefault(x => x.Value.controller == sender && (senderFound = true)); if (!senderFound) { return; } JeromeConnectionParams cp = senderEntry.Key; this.Invoke((MethodInvoker) delegate { connections[cp].watch = false; menuControl[cp].Checked = true; this.Text = cp.name; updateButtonsMode(); }); JeromeController controller = connections[cp].controller; string linesState = controller.readlines(); controller.setLineMode(controllerTemplate.dir, 0); controller.setLineMode(controllerTemplate.pulse, 0); controller.setLineMode(controllerTemplate.enable, 0); controller.setLineMode(controllerTemplate.ptt, 0); controller.switchLine(controllerTemplate.enable, 1); controller.switchLine(controllerTemplate.pulse, 0); controller.switchLine(controllerTemplate.ptt, 0); for (int co = 0; co < controllerTemplate.relays.Length; co++) { controller.setLineMode(controllerTemplate.relays[co], 0); controller.switchLine(controllerTemplate.relays[co], 0); } foreach (int line in controllerTemplate.limits.Values) { controller.setLineMode(line, 1); } controller.lineStateChanged += controllerLineStateChanged; if (linesState[controllerTemplate.limits[-1] - 1] == '0') { limit = -1; } else if (linesState[controllerTemplate.limits[1] - 1] == '0') { limit = 1; } if (position == -1) { rotate(0); } }
private void rotate(int newTarget) { System.Diagnostics.Debug.WriteLine("Rotate to " + newTarget.ToString()); target = newTarget; if (activeConnection.controller == null || !activeConnection.controller.connected || position == newTarget) { return; } if (rotateTask == null) { rotateTask = TaskEx.Run(async() => { JeromeController controller = activeConnection.controller; System.Diagnostics.Debug.WriteLine("start rotate to " + target.ToString()); blinkTimer.Change(1000, 1000); controller.switchLine(controllerTemplate.enable, 0); controller.switchLine(controllerTemplate.ptt, 1); while (target != position && controller.connected) { int dir; if (position == -1) { dir = target == buttonPositions[buttonPositions.Length - 1] ? 1 : -1; } else { dir = target < position ? -1 : 1; } controller.switchLine(controllerTemplate.dir, dir == -1 ? 0 : 1); controller.switchLine(controllerTemplate.pulse, 1); await TaskEx.Delay(5); controller.switchLine(controllerTemplate.pulse, 0); await TaskEx.Delay(5); if (position != -1) { position += dir; } /*if (position == 0 || position == buttonPositions[buttonPositions.Count() - 1]) * { * System.Diagnostics.Debug.WriteLine("Limit reached " + position.ToString()); * break; * }*/ } System.Diagnostics.Debug.WriteLine("Rotated to " + position.ToString()); controller.switchLine(controllerTemplate.pulse, 0); controller.switchLine(controllerTemplate.enable, 1); controller.switchLine(controllerTemplate.ptt, 0); blinkTimer.Change(Timeout.Infinite, Timeout.Infinite); clearRotateTask(); Invoke((MethodInvoker) delegate { lRotation.Visible = false; }); if (position != target) { rotate(target); } }); } }
private void toggleLine(int line, int state) { if (controller != null && controller.connected) { controller.switchLine(line, state); } }
public void setLines(int[] linesStates) { if (jConnection.connected) { for (int c = 0; c < linesStates.Count(); c++) { jConnection.switchLine(FWX0B.ControllerTemplate[c], linesStates[c]); } } }