
from time import sleep

from proto9x.usb import usb
from proto9x.tls import tls
from proto9x.flash import read_flash
from proto9x.init_flash import init_flash
from proto9x.upload_fwext import upload_fwext
from proto9x.calibrate import calibrate
from proto9x.init_db import init_db

#usb.trace_enabled=True
#tls.trace_enabled=True

def restart():
    print('Sleeping...')
    sleep(3)
    tls.reset()
    usb.open()
    usb.send_init()
    tls.parseTlsFlash(read_flash(1, 0, 0x1000))
    tls.open()

usb.open()
print('Initializing flash...')
init_flash()

restart()
print('Uploading firmware...')
upload_fwext()

restart()
print('Calibrating...')
calibrate()

print('Init database...')
init_db()

print('That\'s it, pairing\'s finished')

[(24, 'proto9x.usb.usb.open', 'usb.open', False, 'from proto9x.usb import usb\n'), (26, 'proto9x.init_flash.init_flash', 'init_flash', False, 'from proto9x.init_flash import init_flash\n'), (30, 'proto9x.upload_fwext.upload_fwext', 'upload_fwext', False, 'from proto9x.upload_fwext import upload_fwext\n'), (34, 'proto9x.calibrate.calibrate', 'calibrate', False, 'from proto9x.calibrate import calibrate\n'), (37, 'proto9x.init_db.init_db', 'init_db', False, 'from proto9x.init_db import init_db\n'), (17, 'time.sleep', 'sleep', False, 'from time import sleep\n'), (18, 'proto9x.tls.tls.reset', 'tls.reset', False, 'from proto9x.tls import tls\n'), (19, 'proto9x.usb.usb.open', 'usb.open', False, 'from proto9x.usb import usb\n'), (20, 'proto9x.usb.usb.send_init', 'usb.send_init', False, 'from proto9x.usb import usb\n'), (22, 'proto9x.tls.tls.open', 'tls.open', False, 'from proto9x.tls import tls\n'), (21, 'proto9x.flash.read_flash', 'read_flash', False, 'from proto9x.flash import read_flash\n')]