/// <summary> /// Notifies that a switch-up was detected /// </summary> /// <param name="switchObj">The switch that caused the trigger</param> private void notifySwitchUp(IActuatorSwitch switchObj) { if (EvtSwitchUp != null) { EvtSwitchUp(this, new ActuatorSwitchEventArgs(switchObj)); } }
/// <summary> /// Helper function to trigger an event that a switch was triggered. This /// function is called by the derived classes /// </summary> /// <param name="switchObj">Switch that caused the event</param> protected virtual void OnSwitchTriggered(IActuatorSwitch switchObj) { switchObj.Action = SwitchAction.Trigger; if (EvtSwitchActivated != null) { EvtSwitchTriggered(this, new ActuatorSwitchEventArgs(switchObj)); } }
/// <summary> /// Runds the command mapped to the specified switch. Checks /// the command permissions if it CAN be executed. /// </summary> /// <param name="switchObj">The switch object</param> private void runSwitchMappedCommand(IActuatorSwitch switchObj) { bool runCommand = true; String onTrigger = switchObj.Command; var form = _currentPanel.UIControl; if (form is IScannerPanel) { var panelCommon = (form as IScannerPanel).PanelCommon; var arg = new CommandEnabledArg(null, onTrigger); panelCommon.CheckCommandEnabled(new CommandEnabledArg(null, onTrigger)); if (arg.Handled) { if (!arg.Enabled) { Log.Debug("Command " + onTrigger + " is not currently enabled"); return; } else { Log.Debug("Command " + onTrigger + " IS ENABLED"); } } else { Log.Debug("arg.handled is false for " + onTrigger); var cmdDescriptor = CommandManager.Instance.AppCommandTable.Get(onTrigger); if (cmdDescriptor != null && !cmdDescriptor.EnableSwitchMap) { Log.Debug("EnableswitchMap is not enabled for " + onTrigger); runCommand = false; } } } else { Log.Debug("Dialog is active. Will not handle"); runCommand = false; } if (runCommand) { Log.Debug("Executing OnTrigger command " + onTrigger + " for panel..." + _currentPanel.Name); PCode pcode = new PCode { Script = "run(" + onTrigger + ")" }; var parser = new Parser(); if (parser.Parse(pcode.Script, ref pcode)) { _interpreter.Execute(pcode); } } }
/// <summary> /// Returns the action associated with the switch. These actions /// are configured in the switch map config file. First checks the /// animation config file to see if there is a mapping there. If not /// goes to the global mapping table /// </summary> /// <param name="switchObj">the switch object</param> /// <returns>associated pCode</returns> private PCode getOnTrigger(IActuatorSwitch switchObj) { const string defaultWidgetClass = "default"; Log.Debug(); if (_switchConfig == null) { return(null); } // check local switchmap first PCode pCode = _switchConfig.GetOnTrigger(switchObj); if (pCode != null) { Log.Debug("Found local pcode for " + switchObj.Name); return(pCode); } Log.Debug("Did not find local switchconfig. Checking global one"); // if this panel is a member of a 'class' of panels(configured thru // the subclass attribute), check if there is a switch map for the class. // otherwise, just use the default one. var widgetClass = (_currentPanel != null) ? _currentPanel.SubClass : String.Empty; if (String.IsNullOrEmpty(widgetClass)) { widgetClass = defaultWidgetClass; } Log.Debug("widgetclass: " + widgetClass); SwitchConfig switchConfig = ActuatorManager.Instance.SwitchConfigMap; PCode retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); if (retVal != null) { return(retVal); } if (widgetClass != defaultWidgetClass) { Log.Debug("Could not find PCode for " + widgetClass + ", trying default"); widgetClass = defaultWidgetClass; retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); } Log.IsNull("retval ", retVal); return(retVal); }
/// <summary> /// Invoked when a switch is activated. Inform the mouse /// mover objects that a switch activation was detected /// </summary> /// <param name="switchObj">Switch that was activated</param> /// <param name="handled">true if it was handled</param> private void AppActuatorManager_EvtSwitchHook(IActuatorSwitch switchObj, ref bool handled) { handled = false; if (_gridMouseMover != null) { _gridMouseMover.Actuate(); handled = true; } }
/// <summary> /// Event handler for when a swtich trigger event is detected. /// Notify ACAT /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void sensor_EvtSwitchTrigger(object sender, InputSensorSwitchEventArgs e) { if (actuatorState == State.Running) { IActuatorSwitch actuatorSwitch = find(e.Gesture); if (actuatorSwitch != null) { OnSwitchTriggered(actuatorSwitch); } } }
/// <summary> /// Event handler for when a swtich trigger event is detected. /// Notify ACAT /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void sensor_EvtSwitchTrigger() { if (actuatorState == State.Running) { IActuatorSwitch actuatorSwitch = find("SerSwi"); if (actuatorSwitch != null) { OnSwitchTriggered(actuatorSwitch); } } }
/// <summary> /// Trigger an event that this switch was triggered /// </summary> /// <param name="switchObj">Which switch caused the trigger</param> private void act(IActuatorSwitch switchObj) { bool handled = false; notifySwitchHooks(switchObj, ref handled); if (!handled) { Log.Debug("ACT on Switch " + switchObj.Name); notifySwitchActivated(switchObj); } }
/// <summary> /// An actuator switch trigger event was detected. Stops /// the timer /// </summary> /// <param name="switchObj">switch that actuated</param> /// <param name="handled">set to true</param> private void AppActuatorManager_EvtSwitchHook(IActuatorSwitch switchObj, ref bool handled) { bool h = false; _form.Invoke(new MethodInvoker(delegate { if (_timer.Enabled) { stopTimer(); h = true; } })); handled = h; }
/// <summary> /// Invoked when data is received. Converted to string /// and parsed. After parsing, switch trigger event is raised /// </summary> /// <param name="packet"></param> protected virtual void onDataReceived(byte[] packet) { String strData = ASCIIEncoding.ASCII.GetString(packet, 0, packet.Length); Log.Debug("Received data: " + strData); // parse the string, find the switch that causes the trigger IActuatorSwitch switchObj = WinsockCommon.parseAndGetSwitch(strData, Switches, CreateSwitch); if (switchObj != null) { triggerEvent(switchObj); } }
/// <summary> /// Invoked when a switch is activated. Inform the radar/grid /// mover objects that a switch activation was detected /// </summary> /// <param name="switchObj">Switch that was activated</param> /// <param name="handled">true if it was handled</param> private void AppActuatorManager_EvtSwitchHook(IActuatorSwitch switchObj, ref bool handled) { handled = false; switch (_mode) { case MouseMode.Radar: handled = _radarMouseMover.Actuate(); break; case MouseMode.Grid: handled = _gridMouseMover.Actuate(); break; } }
/// <summary> /// Initializes the switch object from the passed switch object /// </summary> /// <param name="switchObj">Source switch object</param> public ActuatorSwitchBase(IActuatorSwitch switchObj) { Name = switchObj.Name; Source = switchObj.Source; _isActive = switchObj.IsActive; AcceptTime = switchObj.AcceptTime; Confidence = switchObj.Confidence; Timestamp = switchObj.Timestamp; Action = switchObj.Action; BeepFile = switchObj.BeepFile; Audio = switchObj.Audio; Actuator = switchObj.Actuator; _acceptTimer = switchObj.AcceptTimer; Actuate = switchObj.Actuate; Tag = switchObj.Tag; }
/// <summary> /// Depending on the switch action, raises events such as /// switch engaged, switch disengaged etc /// </summary> /// <param name="switchObj"></param> protected void triggerEvent(IActuatorSwitch switchObj) { switch (switchObj.Action) { case SwitchAction.Down: OnSwitchActivated(switchObj); break; case SwitchAction.Up: OnSwitchDeactivated(switchObj); break; case SwitchAction.Trigger: OnSwitchTriggered(switchObj); break; } }
/// <summary> /// This is the callback function from ACAT vision. This is /// in form of a string. /// Format of the string is: /// gesture=gesturetype;action=gestureevent;conf=confidence;time=timestamp;actuate=flag;tag=userdata /// where /// gesturetype is a string representing the gesture. This is used as /// the 'source' field in the actuator switch object /// gestureevent should be a valid value from the SwitchAction enum /// confidence Integer representing the confidence level, for future use /// timestamp Timestamp of when the switch event triggered (in ticks) /// flag true/false. If false, the switch trigger event will be ignored /// userdata Any user data /// Eg /// gesture=G1;action=trigger;conf=75;time=3244394443 /// </summary> /// <param name="text"></param> private void callbackFromVision(string text) { var gesture = String.Empty; IActuatorSwitch actuatorSwitch = parseActuatorMsgAndGetSwitch(text, ref gesture); if (actuatorSwitch != null) { triggerEvent(actuatorSwitch); } else if (gesture == "CALIB_START") // begin camera calibration { // if the camera status form is currently displayed, close it dismissCameraStatus(); try { Log.Debug("Received CALIB_START"); Log.Debug("Calling RequestCalibration"); RequestCalibration(); Log.Debug("Returned from RequestCalibration"); } catch (Exception ex) { Log.Debug("Exception " + ex); } } else if (gesture == "CALIB_END") // end camera calibration { Log.Debug("CALIB_END"); // if we are in the initialization state, signal that // we are done if (_initInProgress) { OnInitDone(); _initInProgress = false; } VisionSensor.hideVideoWindow(); OnEndCalibration(); } }
/// <summary> /// Notifies that a switch was triggered /// </summary> /// <param name="switchObj">The switch that caused the trigger</param> private void notifySwitchActivated(IActuatorSwitch switchObj) { AuditLog.Audit(new AuditEventSwitchActuate(switchObj.Name, "Actuate", switchObj.Actuator.Name, switchObj.Tag, 0)); if (EvtSwitchActivated == null) { Log.Debug("No subscribers. Returning"); return; } var delegates = EvtSwitchActivated.GetInvocationList(); foreach (var del in delegates) { var switchActivated = (SwitchActivated)del; Log.Debug("Calling begininvoke for " + switchObj.Name); switchActivated.BeginInvoke(this, new ActuatorSwitchEventArgs(switchObj), null, null); } }
/// <summary> /// Returns onTrigger Pcode for the specified switch for the /// specified screen /// </summary> /// <param name="screen">Name of the screen</param> /// <param name="actuatorSwitch">Input switch</param> /// <returns>null if there is no onTrigger</returns> /// public PCode GetOnTrigger(String screen, IActuatorSwitch actuatorSwitch) { try { Log.Debug("Scanner: " + screen); var actuatorName = actuatorSwitch.Actuator.Name; Log.Debug("actuatorname: " + actuatorName); SwitchMap switchMap; if (_switchMapTable.TryGetValue(screen.ToLower(), out switchMap)) { Log.Debug("Getting swithcmapActuator for " + actuatorName); var switchMapActuator = switchMap[actuatorName]; Log.IsNull("switchMapActuator ", switchMapActuator); if (switchMapActuator != null) { Log.Debug("Geting switchElement " + actuatorSwitch.Name); var switchElement = switchMapActuator[actuatorSwitch.Name]; Log.IsNull("switchElement ", switchElement); if (switchElement != null) { Log.Debug("Found switchelement"); return(switchElement.OnTrigger); } } } else { Log.Debug("switchmap is null"); } } catch (Exception ex) { Log.Debug(ex.ToString()); } Log.Debug("Returning null"); return(null); }
/// <summary> /// Plays a beep associated with the switch. If none, plays /// the default beep /// </summary> /// <param name="switchObj">the source siwtch</param> private void playBeep(IActuatorSwitch switchObj) { try { if (CoreGlobals.AppPreferences.SelectClick) { if (switchObj.Audio != null) { switchObj.Audio.Play(); } else { playDefaultBeep(); } } } catch (Exception ex) { Log.Exception(ex); } }
/// <summary> /// Notifies all subscribers that want to be hooked into the switch /// events that a switch has been triggered. If handled is true /// the subscriber has handled the event. The input manager will /// not handle the event /// </summary> /// <param name="switchObj"></param> /// <param name="handled"></param> private void notifySwitchHooks(IActuatorSwitch switchObj, ref bool handled) { handled = false; bool evtHandled = false; if (EvtSwitchHook == null) { return; } Log.Debug(); var delegates = EvtSwitchHook.GetInvocationList(); foreach (var del in delegates) { var switchHook = (SwitchHook)del; switchHook.Invoke(switchObj, ref evtHandled); if (evtHandled) { handled = true; } } }
/// <summary> /// Initializes a new instance of the class. Copies /// members over from switchObj /// </summary> /// <param name="switchObj">Switch object to clone</param> public VisionActuatorSwitch(IActuatorSwitch switchObj) : base(switchObj) { }
/// <summary> /// Initializes a new instance of the ActuatorSwitchEventArgs class /// </summary> /// <param name="actuatorSwitch">The switch object</param> public ActuatorSwitchEventArgs(IActuatorSwitch actuatorSwitch) { SwitchObj = actuatorSwitch; }
/// <summary> /// Helper function to trigger an event that a switch was disengaged. This /// function is called by the derived classes /// </summary> /// <param name="switchObj">Switch that caused the event</param> protected virtual void OnSwitchDeactivated(IActuatorSwitch switchObj) { switchObj.Action = SwitchAction.Up; EvtSwitchDeactivated(this, new ActuatorSwitchEventArgs(switchObj)); }
/// <summary> /// A switch was activated. Figure out the context and execute the /// appropriate action. The input manager triggers this event. Every /// switch has an action that is configured in the swtichconfigmap file. /// The action is executed depending on the state of the animation player. /// </summary> /// <param name="sender">event sender</param> /// <param name="e">event args</param> private void actuatorManager_EvtSwitchActivated(object sender, ActuatorSwitchEventArgs e) { IActuatorSwitch switchObj = e.SwitchObj; try { if (_player == null || _currentPanel == null) { return; } Log.Debug("switch: " + switchObj.Name); Log.Debug(" Panel: " + _currentPanel.Name); if (_currentPanel.UIControl is System.Windows.Forms.Form) { bool visible = Windows.GetVisible(_currentPanel.UIControl); Log.Debug("Form: " + _currentPanel.UIControl.Name + ", playerState: " + _player.State + ", visible: " + visible); if (!visible) { return; } } // get the action associated with the switch PCode onTrigger = getOnTrigger(switchObj); if (onTrigger == null) { Log.Debug("OnTrigger is null. returning"); return; } Log.Debug("onTrigger.HasCode: " + onTrigger.HasCode()); // execute action if the player is in the right state. if (_player.State != PlayerState.Stopped && _player.State != PlayerState.Unknown && _player.State != PlayerState.Paused && onTrigger.HasCode()) { Log.Debug("Executing OnTrigger for panel..." + _currentPanel.Name); _interpreter.Execute(onTrigger); return; } if (_player.State == PlayerState.Timeout || _player.State == PlayerState.Interrupted) { Log.Debug("Calling player transition for firstanimation"); _player.Transition(_firstAnimation); return; } Log.Debug("PLayer state is " + _player.State); if (_player.State != PlayerState.Running) { Log.Debug(_currentPanel.Name + ": Player is not Running. Returning"); return; } playBeep(switchObj); AnimationWidget highlightedWidget = _player.HighlightedWidget; Animation currentAnimation = _player.CurrentAnimation; highlightedWidget = _switchDownHighlightedWidget; currentAnimation = _switchDownAnimation; if (highlightedWidget == null) { highlightedWidget = _switchAcceptedHighlightedWidget; currentAnimation = _switchAcceptedAnimation; } if (highlightedWidget == null) { highlightedWidget = _player.HighlightedWidget; currentAnimation = _player.CurrentAnimation; } resetSwitchEventStates(); if (currentAnimation != null && highlightedWidget != null) { setSwitchState(false); var widgetName = (highlightedWidget.UIWidget is IButtonWidget) ? "Button" : highlightedWidget.UIWidget.Name; AuditLog.Audit(new AuditEventUISwitchDetect(switchObj.Name, _currentPanel.Name, highlightedWidget.UIWidget.GetType().Name, widgetName)); Log.Debug(_currentPanel.Name + ": Switch on " + highlightedWidget.UIWidget.Name + " type: " + highlightedWidget.UIWidget.GetType().Name); // check if the widget has a onSelect code fragment. If so execute it. Otherwise // then check if the animation seq that this widget is a part of, has a onSelect. // If it does, execute that. PCode code; SetSelectedWidget(highlightedWidget.UIWidget); if (highlightedWidget.OnSelect.HasCode()) { code = highlightedWidget.OnSelect; _interpreter.Execute(code); } else if (currentAnimation.OnSelect.HasCode()) { code = currentAnimation.OnSelect; _interpreter.Execute(code); } } else { Log.Debug(_currentPanel.Name + ": No current animation or highlighed widget!!"); } } catch (Exception ex) { Log.Debug(ex.ToString()); } finally { setSwitchState(false); } }
/// <summary> /// Returns onTrigger Pcode for the specified switch for the /// specified scanner /// </summary> /// <param name="scanner">Name of the scanner</param> /// <param name="actuatorSwitch">Input switch</param> /// <returns>null if there is no onTrigger</returns> /// public PCode GetOnTrigger(String scanner, IActuatorSwitch actuatorSwitch) { try { Log.Debug("Scanner: " + scanner); var actuatorName = actuatorSwitch.Actuator.Name; Log.Debug("actuatorname: " + actuatorName); SwitchMap switchMap; if (_switchMapTable.TryGetValue(scanner.ToLower(), out switchMap)) { Log.Debug("Getting swithcmapActuator for " + actuatorName); var switchMapActuator = switchMap[actuatorName]; Log.IsNull("switchMapActuator ", switchMapActuator); if (switchMapActuator != null) { Log.Debug("Geting switchElement " + actuatorSwitch.Name); var switchElement = switchMapActuator[actuatorSwitch.Name]; Log.IsNull("switchElement ", switchElement); if (switchElement != null) { Log.Debug("Found switchelement"); return switchElement.OnTrigger; } } } else { Log.Debug("switchmap is null"); } } catch (Exception ex) { Log.Debug(ex.ToString()); } Log.Debug("Returning null"); return null; }
/// <summary> /// Gets the default action associated with the switch. Default /// action applies to all screens for which a custom switch action /// has not been specified. /// </summary> /// <param name="switchObj">the switch object</param> /// <returns>PCode representing the action, null if none</returns> public PCode GetOnTrigger(IActuatorSwitch switchObj) { return GetOnTrigger(DefaultAttr, switchObj); }
/// <summary> /// Initialize the keyboard actuator object /// </summary> /// <param name="switchObj"></param> public KeyboardSwitch(IActuatorSwitch switchObj) : base(switchObj) { }
/// <summary> /// Initializes a new instance of the class. Copies /// members over from switchObj /// </summary> /// <param name="switchObj">Switch object to clone</param> public WordsPlusSwitch(IActuatorSwitch switchObj) : base(switchObj) { }
/// <summary> /// Class factory to create the winsock client actuator switch which is a /// clone of the switch specified /// </summary> /// <param name="sourceSwitch">source switch to clone</param> /// <returns>Winsock switch object</returns> public virtual IActuatorSwitch CreateSwitch(IActuatorSwitch sourceSwitch) { return new WinsockSwitch(sourceSwitch); }
/// <summary> /// Disambigates signals from various switches and acts upon them. Disambiguation /// logic has not been implemented. this is TODO. /// Maintains a list of switches that are currently held down. When the swithches /// are released, it checks to see how long they were held and then triggers an /// event. /// </summary> /// <param name="switches">switch collection</param> /// <param name="switchObj">Which switch to act on</param> private void disambiguateAndAct(Dictionary <String, IActuatorSwitch> switches, IActuatorSwitch switchObj) { IActuatorSwitch switchActivated = null; long elapsedTime = 0; switch (switchObj.Action) { case SwitchAction.Down: lock (switches) { if (!switches.ContainsKey(switchObj.Name)) { Log.Debug("switches does not contain " + switchObj.Name + ". adding it"); // add it to the current list of active switches switches.Add(switchObj.Name, switchObj); switchObj.AcceptTimer.Restart(); } else { Log.Debug("switches already contains " + switchObj.Name); } } break; case SwitchAction.Up: // remove from the list of currently accepted switches lock (switches) { switchObj.RegisterSwitchUp(); if (switches.ContainsKey(switchObj.Name)) { Log.Debug("switches contains " + switchObj.Name); var activeSwitch = switches[switchObj.Name]; elapsedTime = (activeSwitch != null && activeSwitch.AcceptTimer.IsRunning) ? activeSwitch.AcceptTimer.ElapsedMilliseconds : 0; if (switchObj.Actuate && activeSwitch != null && activeSwitch.AcceptTimer.IsRunning && activeSwitch.AcceptTimer.ElapsedMilliseconds >= CoreGlobals.AppPreferences.AcceptTime) { Log.Debug("Switch accepted!"); switchActivated = switchObj; } else { Log.Debug("Switch not found or actuate is false or timer not running or elapsedTime < accept time"); } switches.Remove(switchObj.Name); } else { Log.Debug("switches does not contain " + switchObj.Name); } } break; case SwitchAction.Trigger: lock (switches) { if (switches.ContainsKey(switchObj.Name)) { switches.Remove(switchObj.Name); } } if (switchObj.Actuate) { switchActivated = switchObj; } break; } AuditLog.Audit(new AuditEventSwitchActuate(switchObj.Name, switchObj.Action.ToString(), switchObj.Actuator.Name, switchObj.Tag, elapsedTime)); if (switchActivated != null) { act(switchObj); } }
/// <summary> /// Gets the default action associated with the switch. Default /// action applies to all screens for which a custom switch action /// has not been specified. /// </summary> /// <param name="switchObj">the switch object</param> /// <returns>PCode representing the action, null if none</returns> public PCode GetOnTrigger(IActuatorSwitch switchObj) { return(GetOnTrigger(DefaultAttr, switchObj)); }
/// <summary> /// An actuator switch trigger event was detected. Stop /// the timer /// </summary> /// <param name="switchObj">switch that actuated</param> /// <param name="handled">set to true</param> private void AppActuatorManager_EvtSwitchHook(IActuatorSwitch switchObj, ref bool handled) { bool h = false; _form.Invoke(new MethodInvoker(delegate { if (_timer.Enabled) { stopTimer(); h = true; } })); handled = h; }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="switchObj">Source switch from which to create a clone</param> public WinsockSwitch(IActuatorSwitch switchObj) : base(switchObj) { }
/// <summary> /// Parses the string sent over the tcp/ip connection and /// extracts information from it. Then looks up /// the list of switches, matches the gesture with the /// switch and creates a clone of the switch object and /// returns the switch object /// Format of the packet is: /// gesture=gesturetype;action=gestureevent;conf=confidence;time=timestamp;actuate=flag;tag=userdata /// where /// gesturetype is a string representing the gesture. This is used as /// the 'source' field in the actuator switch object /// gestureevent should be a valid value from the SwitchAction enum /// confidence Integer representing the confidence level, for future use /// timestamp Timestamp of when the switch event triggered (in ticks) /// flag true/false. If false, the switch trigger event will be ignored /// userdata Any user data /// Eg /// gesture=G1;action=trigger;conf=75;time=3244394443 /// </summary> /// <param name="strData">Data</param> /// <param name="switches">Actuator switch collection</param> /// <param name="createSwitchDel">A delegate function that creates an actuator switch object</param> /// <returns>A clone of the matching switch object from the collection</returns> public static IActuatorSwitch parseAndGetSwitch( String strData, ICollection <IActuatorSwitch> switches, CreateSwitchDelegate createSwitchDel) { IActuatorSwitch actuatorSwitch = null; String gesture = String.Empty; var switchAction = SwitchAction.Unknown; String tag = String.Empty; int confidence = -1; long time = -1; bool actuate = true; var tokens = strData.Split(';'); foreach (var token in tokens) { String[] nameValue = token.Split('='); if (nameValue.Length == 2) { switch (nameValue[0]) { case "gesture": // G1, G2, ... gesture = nameValue[1]; break; case "action": // Up, Down, Trigger switchAction = getSwitchAction(nameValue[1]); break; case "time": // in Ticks time = parseLong(nameValue[1]); break; case "confidence": // integer 0 to 100 confidence = (int)parseLong(nameValue[1]); break; case "actuate": actuate = String.Compare(nameValue[1], "true", true) == 0; break; case "tag": tag = nameValue[1]; break; } } } if (!String.IsNullOrEmpty(gesture) && switchAction != SwitchAction.Unknown) { actuatorSwitch = getSwitchForGesture(gesture, switches, createSwitchDel); actuatorSwitch.Action = switchAction; actuatorSwitch.Confidence = confidence; actuatorSwitch.Timestamp = time; actuatorSwitch.Actuate = actuate; actuatorSwitch.Tag = tag; } return(actuatorSwitch); }
/// <summary> /// Helper function to trigger an event that a switch was triggered. This /// function is called by the derived classes /// </summary> /// <param name="switchObj">Switch that caused the event</param> protected virtual void OnSwitchTriggered(IActuatorSwitch switchObj) { switchObj.Action = SwitchAction.Trigger; EvtSwitchTriggered(this, new ActuatorSwitchEventArgs(switchObj)); }
/// <summary> /// Class factory to create the winsock client actuator switch which is a /// clone of the switch specified /// </summary> /// <param name="sourceSwitch">source switch to clone</param> /// <returns>Winsock switch object</returns> public override IActuatorSwitch CreateSwitch(IActuatorSwitch sourceSwitch) { return(new WinsockSwitch(sourceSwitch)); }
/// <summary> /// Class factory to create the winsock client actuator switch which is a /// clone of the switch specified /// </summary> /// <param name="sourceSwitch">source switch to clone</param> /// <returns>Winsock switch object</returns> public virtual IActuatorSwitch CreateSwitch(IActuatorSwitch sourceSwitch) { return(new WinsockSwitch(sourceSwitch)); }
/// <summary> /// Class factory to create the switch object from an existing /// switch object /// </summary> /// <param name="sourceSwitch">Source switch to clone</param> /// <returns>Vision actuator switch object</returns> public override IActuatorSwitch CreateSwitch(IActuatorSwitch sourceSwitch) { return(new VisionActuatorSwitch(sourceSwitch)); }
/// <summary> /// Disambigates signals from various switches and acts upon them. Disambiguation /// logic has not been implemented. this is TODO. /// Maintains a list of switches that are currently held down. When the swithches /// are released, it checks to see how long they were held and then triggers an /// event. /// </summary> /// <param name="switches">switch collection</param> /// <param name="switchObj">Which switch to act on</param> private void disambiguateAndAct(Dictionary<String, IActuatorSwitch> switches, IActuatorSwitch switchObj) { IActuatorSwitch switchActivated = null; long elapsedTime = 0; switch (switchObj.Action) { case SwitchAction.Down: lock (switches) { if (!switches.ContainsKey(switchObj.Name)) { Log.Debug("switches does not contain " + switchObj.Name + ". adding it"); // add it to the current list of active switches switches.Add(switchObj.Name, switchObj); switchObj.AcceptTimer.Restart(); } else { Log.Debug("switches already contains " + switchObj.Name); } } break; case SwitchAction.Up: // remove from the list of currently accepted switches lock (switches) { switchObj.RegisterSwitchUp(); if (switches.ContainsKey(switchObj.Name)) { Log.Debug("switches contains " + switchObj.Name); var activeSwitch = switches[switchObj.Name]; elapsedTime = (activeSwitch != null && activeSwitch.AcceptTimer.IsRunning) ? activeSwitch.AcceptTimer.ElapsedMilliseconds : 0; if (switchObj.Actuate && activeSwitch != null && activeSwitch.AcceptTimer.IsRunning && activeSwitch.AcceptTimer.ElapsedMilliseconds >= CoreGlobals.AppPreferences.AcceptTime) { Log.Debug("Switch accepted!"); switchActivated = switchObj; } else { Log.Debug("Switch not found or actuate is false or timer not running or elapsedTime < accept time"); } switches.Remove(switchObj.Name); } else { Log.Debug("switches does not contain " + switchObj.Name); } } break; case SwitchAction.Trigger: lock (switches) { if (switches.ContainsKey(switchObj.Name)) { switches.Remove(switchObj.Name); } } if (switchObj.Actuate) { switchActivated = switchObj; } break; } AuditLog.Audit(new AuditEventSwitchActuate(switchObj.Name, switchObj.Action.ToString(), switchObj.Actuator.Name, switchObj.Tag, elapsedTime)); if (switchActivated != null) { act(switchObj); } }
/// <summary> /// Returns the action associated with the switch. These actions /// are configured in the switch map config file. First checks the /// animation config file to see if there is a mapping there. If not /// goes to the global mapping table /// </summary> /// <param name="switchObj">the switch object</param> /// <returns>associated pCode</returns> private PCode getOnTrigger(IActuatorSwitch switchObj) { const string defaultWidgetClass = "default"; Log.Debug(); if (_switchConfig == null) { return null; } // check local switchmap first PCode pCode = _switchConfig.GetOnTrigger(switchObj); if (pCode != null) { Log.Debug("Found local pcode for " + switchObj.Name); return pCode; } Log.Debug("Did not find local switchconfig. Checking global one"); // if this panel is a member of a 'class' of panels(configured thru // the subclass attribute), check if there is a switch map for the class. // otherwise, just use the default one. var widgetClass = (_currentPanel != null) ? _currentPanel.SubClass : String.Empty; if (String.IsNullOrEmpty(widgetClass)) { widgetClass = defaultWidgetClass; } Log.Debug("widgetclass: " + widgetClass); SwitchConfig switchConfig = ActuatorManager.Instance.SwitchConfigMap; PCode retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); if (retVal != null) { return retVal; } if (widgetClass != defaultWidgetClass) { Log.Debug("Could not find PCode for " + widgetClass + ", trying default"); widgetClass = defaultWidgetClass; retVal = switchConfig.GetOnTrigger(widgetClass, switchObj); } Log.IsNull("retval ", retVal); return retVal; }