private void changeOutput(DIOPins pinToChange, bool shouldSetHigh) { UpdateOutputEvent clickTarget = new UpdateOutputEvent(pinToChange, shouldSetHigh); if (_uiDelegate != null) { log.Debug(string.Format("Adding UpdateOutputEvent (pin to set : {0} should set high : {1}) to UIProcessing queue", pinToChange, shouldSetHigh)); _uiDelegate.enqueueEvent(clickTarget); } }
/// <summary> /// Attempts to return the value of a pin. If for some reason the dictionary can not get the value /// it will throw an exception /// </summary> /// <param name="pin">The pin to get the state of</param> /// <returns>True if the pin is high, false if it is not</returns> public bool getPinState(DIOPins pin) { bool toReturn = false; if (!_pinStates.TryGetValue(pin, out toReturn)) { throw new Exception(); } return(toReturn); }
public static bool getDeviceOnState(DIOPins pinToSetOn) { switch (pinToSetOn) { case DIOPins.Heater_AN1: return(true); case DIOPins.AirSolenoid_AN0: return(true); case DIOPins.WaterPump_AN2: return(true); case DIOPins.AirPump_AN3: return(true); default: throw new Exception(); } }
public void toggleOutput(ToggleOutputEvent inToggleOutputEvent) { if (_deviceConnected) { bool currentState; DIOPins pinToToggle = inToggleOutputEvent._pinToToggle; _pinStates.TryGetValue(pinToToggle, out currentState); log.Debug(string.Format("Trying to set pin {0} with current state {1}, to state {2}", pinToToggle, currentState, !currentState)); if (currentState) { _physicalLayer.setOutputState(new UpdateOutputEvent(inToggleOutputEvent._pinToToggle, false)); _pinStates.TryUpdate(pinToToggle, false, true); } else { _physicalLayer.setOutputState(new UpdateOutputEvent(inToggleOutputEvent._pinToToggle, true)); _pinStates.TryUpdate(pinToToggle, true, false); } } else { log.Error("Can not toggle output because device is not connected"); } }
/// <summary> /// Lets you control the outputs /// /// If the user inputs a pin and state, then a new event is created and the event is /// passed to the designated responder /// </summary> /// <param name="pinToChange">The pin you want to change the state of</param> /// <param name="inShouldSetHigh">The state you want the pin to take. True = high, false = low</param> public void controlOutput(DIOPins pinToChange, bool inShouldSetHigh) { controlOutput(new UpdateOutputEvent(pinToChange, inShouldSetHigh)); }
/// <summary> /// Tells the physical layer to toggle the given pin. /// Uses a dictionary to determine the current state of the /// pin and tells the physical layer to put the pin in the oposite state /// /// Then it updates the dictionary to the new state /// /// If a pin in passed in it will create a new event and then pass the /// event to the designated responder /// </summary> /// <param name="pinToToggle"></param> public void toggleOutput(DIOPins pinToToggle) { ToggleOutputEvent toggleOutputEvent = new ToggleOutputEvent(pinToToggle); toggleOutput(toggleOutputEvent); }
private void handleUpdateOutputEvent(DIOPins pinToChange, bool shouldSetHigh) { _logicalLayer.controlOutput(pinToChange, shouldSetHigh); }
private void handleToggleOutputEvent(DIOPins pinToToggle) { _logicalLayer.toggleOutput(pinToToggle); }
//*************************** EventInterface End **************************************************// /// <summary> /// Method which the processing thread will execute in order to /// process the ui event queue. /// /// Will stop when the _shouldStop flag is set /// </summary> private void processQueue() { while (!_shouldStop) { //Get out the newest event log.Debug("Waiting for new event in UIHandle_LLSL processing queue"); _enqueueEvent.WaitOne(100); if (_eventQueue.Count() < 1) { continue; } log.Debug("UIHandle_LLSL processing thread received item enqueued event"); Event newEvent; bool dequeueSuccessful = _eventQueue.TryDequeue(out newEvent); if (!dequeueSuccessful) { continue; } log.Info(string.Format("UIHandle_LLSL processing queue dequeued event {0}", newEvent.getEventIdentifier())); //Decide what to do with the event switch (newEvent.getEventIdentifier()) { case EventIdentifier.GenericEvent: break; case EventIdentifier.ConnectRequest: log.Debug("Handling ConnectRequest ui event"); handleConnectEvent(); break; case EventIdentifier.ToggleLEDRequest: log.Debug("Handling toggleLED ui event"); handleToggleLEDEvent(); break; case EventIdentifier.FlashLEDRequest: log.Debug("Handling flashLED ui event"); handleFlashLEDEvent(); break; case EventIdentifier.ChangeLEDStateRequest: ChangeLEDStateEvent changeLEDEvent = (ChangeLEDStateEvent)newEvent; bool ledIsHigh = changeLEDEvent._isHigh; log.Debug(string.Format("Handling changeLED (setting high: {0}) ui event", changeLEDEvent._isHigh)); handleChangeLEDStateEvent(ledIsHigh); break; case EventIdentifier.ToggleOutputRequest: ToggleOutputEvent toggleOutputEvent = (ToggleOutputEvent)newEvent; DIOPins pinToToggle = toggleOutputEvent._pinToToggle; log.Debug(string.Format("Handling toggleOutput (toggle pin: {0}) ui event", toggleOutputEvent._pinToToggle)); handleToggleOutputEvent(pinToToggle); break; case EventIdentifier.StartSequencerRequest: log.Debug("Handling startTestSequence ui event"); StartSequencerEvent sequencerEvent = (StartSequencerEvent)newEvent; handleStartSequencerEvent(sequencerEvent); break; case EventIdentifier.UpdateOutputRequest: log.Debug("Handling updateOutput UI Event"); UpdateOutputEvent updateOutput = (UpdateOutputEvent)newEvent; DIOPins pinToChange = updateOutput._pinToUpdate; bool shouldSetHigh = updateOutput._shouldBeHigh; handleUpdateOutputEvent(pinToChange, shouldSetHigh); break; default: break; } } }
/// <summary> /// Creates the event with the correct identifier and setting the /// pin to change and the sate to set /// </summary> /// <param name="inPinToChange">The pin to change</param> /// <param name="inSetPinHigh">The state to set</param> public UpdateOutputEvent(DIOPins inPinToChange, bool inSetPinHigh) { identifier = EventIdentifier.UpdateOutputRequest; _pinToUpdate = inPinToChange; _shouldBeHigh = inSetPinHigh; }
/// <summary> /// Creates a ToggleOutputEvent and sets its identifier to the correct value /// Also saves the pin id to toggle /// </summary> public ToggleOutputEvent(DIOPins inPinToToggle) { identifier = EventIdentifier.ToggleOutputRequest; _pinToToggle = inPinToToggle; }