Пример #1
0
def run_example():
    sensor = SensorPub(DummyTempSensor('temp-1', input_sequence))
    sensor.output()  # let us see the raw values
    dispatcher = sensor.transduce(RunningAvg(4))\
                       .passthrough(lambda evt:
                                    print("Running avg temp: %s" %
                                          round(evt.val, 2))) \
                       .dispatch([(lambda v: v[2]>=T_high, 't_high'),
                                  (lambda v: v[2]<=T_low, 't_low')])
    controller = Controller()
    dispatcher.subscribe(controller, topic_mapping=('t_high', 't_high'))
    dispatcher.subscribe(controller, topic_mapping=('t_low', 't_low'))
    dispatcher.subscribe(controller, topic_mapping=('default', 'between'))
    controller.subscribe(BypassValveActuator())
    sensor.print_downstream()
    scheduler = Scheduler(asyncio.get_event_loop())
    scheduler.schedule_periodic(sensor, 0.5)
    scheduler.run_forever()
    print("got to the end")
Пример #2
0
        print("LED Completed")

    def __str__(self):
        return 'LED'


# instantiate an LED
led = LED()

# Now, build a pipeline to sample events returned from the sensor,
# convert to a boolean based on whether the value is greater than
# the mean, and output to the LED.
import antevents.linq.select
sensor.select(lambda evt: evt.val > MEAN).subscribe(led)

# If you want to see the raw value of each sensor, just add the output() element
import antevents.linq.output
sensor.output()

# Call a debug method on the base publisher class to see the element tree rooted
# at sensor.
sensor.print_downstream()

# Now, we need to schedule the sensor to be sampled
import asyncio
from antevents.base import Scheduler
scheduler = Scheduler(asyncio.get_event_loop())
scheduler.schedule_periodic(sensor, 1.0)  # sample once a second
scheduler.run_forever()  # run until all sensors complete
print("That's all folks!")