def init_movehub(): mh = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) mh.start() mh.subscribe_all() mh.listen_hubtilt(MODE_HUBTILT_BASIC) mh.listen_colordist_sensor(PORT_D) mh.listen_angle_sensor(PORT_C) if mh.is_connected(): print(('Is connected: ', mh.is_connected())) return mh
#!/usr/bin/env python3 from pyb00st.movehub import MoveHub from pyb00st.constants import * from time import sleep import os MY_MOVEHUB_ADD = os.environ.get('MYMOVEHUB') MY_BTCTRLR_HCI = 'hci0' mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) try: mymovehub.start() mymovehub.subscribe_all() mymovehub.listen_angle_sensor(PORT_D) mymovehub.listen_colordist_sensor(PORT_C) while True: sleep(0.2) print('Motor D: {} Color: {}'.format(mymovehub.last_angle_D, mymovehub.last_color_C)) finally: mymovehub.stop()
if __name__ == "__main__": print('Snap! BOOST extension by JorgePe') PORT = 8001 Handler = CORSHTTPRequestHandler httpd = socketserver.TCPServer(("", PORT), Handler, bind_and_activate=False) httpd.allow_reuse_address = True try: httpd.server_bind() httpd.server_activate() except: httpd.server_close() raise print('Serving at port', PORT) print('Go ahead and launch Snap!') print('<a>http://snap.berkeley.edu/snapsource/snap.html</a>') print('Then import the 'snap-boost-blocks-v#.xml' containing block definitions for motor and sensors.') mymovehub = MoveHub(MY_MOVEHUB_ADD, 'BlueZ', MY_BTCTRLR_HCI) try: mymovehub.start() mymovehub.subscribe_all() mymovehub.listen_hubtilt(MODE_HUBTILT_BASIC) mymovehub.listen_colordist_sensor(colordist_port) httpd.serve_forever() finally: mymovehub.stop()