def test(duration = 0): objSched = Sched() objSched.add_thread(robin("Thread 1")) objSched.add_thread(robin("Thread 2")) objSched.add_thread(robin("Thread 3")) if duration: objSched.add_thread(stop(duration, objSched)) # Kill after a period objSched.run()
def test(duration = 0): if duration: print("Test LCD display for {:3d} seconds".format(duration)) objSched = Sched() lcd0 = LCD(PINLIST, objSched, cols = 16) objSched.add_thread(lcd_thread(lcd0)) if duration: objSched.add_thread(stop(duration, objSched)) objSched.run()
def test(duration = 0): if duration: print("Output accelerometer values for {:3d} seconds".format(duration)) else: print("Output accelerometer values") objSched = Sched() objSched.add_thread(accelthread()) if duration: objSched.add_thread(stop(duration, objSched)) # Run for a period then stop objSched.run()
def test(duration = 0): if duration: print("Flash LED's for {:3d} seconds".format(duration)) leds = [pyb.LED(x) for x in range(1,5)] # Initialise all four on board LED's objSched = Sched() # Instantiate the scheduler for x in range(4): # Create a thread instance for each LED objSched.add_thread(toggle(leds[x], 0.2 + x/2)) if duration: objSched.add_thread(stop(duration, objSched)) # Commit suicide after specified no. of seconds objSched.run() # Run it!
def test(): mtx = Pin(14, Pin.OUT) # Define passive pins mckout = Pin(15, Pin.OUT, value = 0) # clocks must be initialised to zero. Pin 15 has pulldown mrx = Pin(13, Pin.IN) mckin = Pin(12, Pin.IN) # add 10K pulldown objsched = Sched() with SynCom(objsched, True, mckin, mckout, mrx, mtx) as channel: objsched.add_thread(passive_thread(channel)) objsched.run()
def test(duration = 0): # Runs oscillator, counts interrupts, responds to switches if duration: print("Test interrupt on pin X8 for {:3d} seconds".format(duration)) objSched = Sched() # Requires jumper between pins X7 and X8 objSched.add_thread(oscillator(1)) # 1Hz objSched.add_thread(irqtest_thread()) Switch(objSched, 'X5', open_func = x5print, open_func_args = ("Red",)) # X5 triggers on open Switch(objSched, 'X6', x6print, ("Yellow",)) # X6 triggers on close if duration: objSched.add_thread(stop(duration, objSched)) objSched.run()
def test(): stx = Pin(Pin.board.Y5, Pin.OUT_PP) # Define pins sckout = Pin(Pin.board.Y6, Pin.OUT_PP) sckout.value(0) # Don't assert clock until data is set srx = Pin(Pin.board.Y7, Pin.IN) sckin = Pin(Pin.board.Y8, Pin.IN) objsched = Sched(heartbeat = 1) with SynCom(objsched, False, sckin, sckout, srx, stx) as channel: objsched.add_thread(initiator_thread(channel)) objsched.run()
def test(duration = 0): # responds to switches if duration: print("Tests pushbuttons for {:5d} seconds".format(duration)) else: print("Tests pushbuttons") objSched = Sched() Pushbutton(objSched, 'X5', descriptor, false_func = x5print, false_func_args = ("Red",)) # X5 triggers on open Pushbutton(objSched, 'X6', descriptor, true_func = x6print, true_func_args = ("Yellow",), long_func = yellowlong, long_func_args = ("Long press",), double_func = yellowdbl, double_func_args = ("Double click",)) # X6 triggers on close if duration: objSched.add_thread(stop(duration, objSched)) objSched.run()
def test(duration): assert duration >= 1, 'Duration must be at least one second' print('Running test for {} seconds'.format(duration)) objSched = Sched() leds = [pyb.LED(x) for x in range(1,5)] # Initialise all four on board LED's for x in range(4): # Create a thread instance for each LED objSched.add_thread(toggle(leds[x], 0.2 + x/2)) # objSched.add_thread(robin("Thread 1")) # Instantiate a few threads # objSched.add_thread(robin("Thread 2")) # objSched.add_thread(robin("Thread 3")) lstResult = [0, 0] objSched.add_thread(thr_instrument(objSched, lstResult)) objSched.add_thread(instrument(objSched, 0.1, duration)) objSched.run() print("Maximum roundrobin yield delay was {:6.1f}mS".format(lstResult[0]/1000.0)) print("Thread thr_instrument was executed {:3d} times in {:3d} seconds {:5d}Hz".format(lstResult[1], duration, lstResult[1]//duration))
def test(): # setup uart object to pass # output = pyb.UART(1, 4800) # generate objects OB = output_buffer() compassthread = compass.cthread(OB) # mpu_i2c = compass.i2c_object pyb.delay(100) othread = outputthread(OB)#, test=True) objSched=Sched() # objSched.add_thread(seatalkthread(OB)) objSched.add_thread(compassthread) # objSched.add_thread(NASAWindThread(OB)) # objSched.add_thread(NASADepthThread(OB)) # pyb.delay(100) # objSched.add_thread(barometerthread(OB))#i2c_object=mpu_i2c)) objSched.add_thread(othread) objSched.run()
def test(): objSched = Sched() lcd0 = LCD(PINLIST, objSched, cols=24) objSched.add_thread(slave(lcd=lcd0)) objSched.run()
def test(): print("Demonstration of subthreads") objSched = Sched() objSched.add_thread(waitforit(objSched)) # Test of one thread waiting on another objSched.run()
imu = MPU9150('X') # Attached to 'X' bus, 1 device, disable interruots fuse = Fusion() def waitfunc(): yield from wait(0.1) def lcd_thread(mylcd, imu, sw): if sw.value() == 1: mylcd[0] = "Calibrate. Push switch" mylcd[1] = "when done" yield from wait(0.1) fuse.calibrate(imu.mag.xyz, lambda : not sw.value(), waitfunc) print(fuse.magbias) mylcd[0] = "{:5s}{:5s} {:5s}".format("Yaw","Pitch","Roll") count = 0 while True: yield from wait(0.02) # imu updates at 50Hz count += 1 if count % 25 == 0: mylcd[1] = "{:4.0f} {:4.0f} {:4.0f}".format(fuse.heading, fuse.pitch, fuse.roll) fuse.update(imu.accel.xyz, imu.gyro.xyz, imu.mag.xyz) # For 6DOF sensors # fuse.update_nomag(imu.get_accel(), imu.get_gyro()) objSched = Sched() lcd0 = LCD(PINLIST, objSched, cols = 24) # Should work with 16 column LCD objSched.add_thread(lcd_thread(lcd0, imu, switch)) objSched.run()
def test(): print("Demonstration of subthreads") objSched = Sched() objSched.add_thread( waitforit(objSched)) # Test of one thread waiting on another objSched.run()
gpio23.value(not gpio23.value()) yield 1 def connected(): global client client = MQTTClient(CLIENT_ID, 'q.emqtt.com', port=1883, keepalive=20) will_msg = {'id': CLIENT_ID, 'status': False, 'msg': 'The connection from this device is lost:('} client.set_last_will('/device/will/status', json.dumps(will_msg)) client.set_callback(on_message) client.connect() client.subscribe('/device/12345/switch', 0) client.subscribe('/device/4567/switch', 0) def run(): wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect('HUAWEI', '0000000000') while not wlan.isconnected(): print('.') time.sleep(.5) print(wlan.ifconfig()) connected() print('WIFI config...') run() objSched = Sched() objSched.add_thread(mqtt_loop()) objSched.add_thread(display()) objSched.add_thread(blink()) objSched.run()