Example #1
0
 //This is the constructor for a WorkItem - the only required parameter is the threadstart itself, but you can optionally add additional parameters if you need.
 //If you don't provide an eventType or eventData, the workItem assumes it does not trigger an event.
 //If you don't tell the work item it is persistent when you create it, it will assume it only needs to be run once.
 public WorkItem(ThreadStart action, bool isPersistent = false, FlightEventType type = FlightEventType.None, IEventData eventData = null)
 {
     Action       = action;
     EventType    = type;
     EventData    = eventData;
     IsPersistent = isPersistent;
 }
Example #2
0
 //This is the constructor for a WorkItem - the only required parameter is the threadstart itself, but you can optionally add additional parameters if you need.
 //If you don't provide an eventType or eventData, the workItem assumes it does not trigger an event.
 //If you don't tell the work item it is persistent when you create it, it will assume it only needs to be run once.
 public WorkItem(ThreadStart action, bool isPersistent = false, FlightEventType type = FlightEventType.None, IEventData eventData = null)
 {
     Action = action;
     EventType = type;
     EventData = eventData;
     IsPersistent = isPersistent;
 }
        //this is the code that runs when all events trigger!!!
        private void TestGyro(FlightEventType eventType, IEventData eventData) {

            //since this runs when ALL events trigger, we want to stop running it if the 
            //event was NOT a gyro event.
            if (eventType != FlightEventType.Gyro) return;

            //if we got here, the event was a Gyro event, and we can trust that the eventData
            // will be GyroData rather than some other kind.
            var data = eventData as GyroData;

            //if for some reason we didn't get any data, something went wrong - just get out of 
            //here so we don't crash. 
            if (data == null) return;

            //the data was gyro data, and it isn't null! Print it to the debug window.
            Debug.Print("Gyro X: " + data.X + "  Y: " + data.Y + " Z:" + data.Z);
        }
Example #4
0
        //this is the code that runs when all events trigger!!!
        private void TestGyro(FlightEventType eventType, IEventData eventData)
        {
            //since this runs when ALL events trigger, we want to stop running it if the
            //event was NOT a gyro event.
            if (eventType != FlightEventType.Gyro)
            {
                return;
            }

            //if we got here, the event was a Gyro event, and we can trust that the eventData
            // will be GyroData rather than some other kind.
            var data = eventData as GyroData;

            //if for some reason we didn't get any data, something went wrong - just get out of
            //here so we don't crash.
            if (data == null)
            {
                return;
            }

            //the data was gyro data, and it isn't null! Print it to the debug window.
            Debug.Print("Gyro X: " + data.X + "  Y: " + data.Y + " Z:" + data.Z);
        }
 //Manages responses to events - when an event is triggered, if anyone has subscribed to it, it will let them know so they can execute code
 //Keep in mind - I personify other classes and objects in code(anyone, them, they, he, she, etc) as it makes it a litte easier to talk about.
 public void TriggerEvent(FlightEventType eventType, IEventData eventData)
 {
     OnEventTriggered?.Invoke(eventType, eventData);
 }
 //Manages responses to events - when an event is triggered, if anyone has subscribed to it, it will let them know so they can execute code
 //Keep in mind - I personify other classes and objects in code(anyone, them, they, he, she, etc) as it makes it a litte easier to talk about.
 public void TriggerEvent(FlightEventType eventType, IEventData eventData)
 {
     OnEventTriggered?.Invoke(eventType, eventData);
 }