/// <summary> /// Looks up the list of switches for a matching gesture and returns /// a clone of the matching switch object /// </summary> /// <param name="gesture">The gesture string</param> /// <param name="switches">Collection of switches for the actuator</param> /// <param name="createSwitchDel">Delegate that creates a clone of the switch</param> /// <returns></returns> private static IActuatorSwitch getSwitchForGesture( String gesture, IEnumerable <IActuatorSwitch> switches, CreateSwitchDelegate createSwitchDel) { foreach (var switchObj in switches) { var imageSwitch = switchObj; if (String.Compare(imageSwitch.Source, gesture, true) == 0) { Log.Debug("Found switch object " + switchObj.Name + " for gesture" + gesture); return(createSwitchDel(switchObj)); } } return(null); }
/// <summary> /// Looks up the list of switches for a matching gesture and returns /// a clone of the matching switch object /// </summary> /// <param name="gesture">The gesture string</param> /// <param name="switches">Collection of switches for the actuator</param> /// <param name="createSwitchDel">Delegate that creates a clone of the switch</param> /// <returns></returns> private static IActuatorSwitch getSwitchForGesture( String gesture, IEnumerable<IActuatorSwitch> switches, CreateSwitchDelegate createSwitchDel) { foreach (var switchObj in switches) { var imageSwitch = switchObj; if (String.Compare(imageSwitch.Source, gesture, true) == 0) { Log.Debug("Found switch object " + switchObj.Name + " for gesture" + gesture); return createSwitchDel(switchObj); } } return null; }
/// <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> /// 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; }