diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..8ab1e01 --- /dev/null +++ b/bot.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python +import time +import Tkinter as tk + +from ant.core import driver +from ant.core import node + +from PowerMeterTx import PowerMeterTx +from config import DEBUG, LOG, NETKEY, POWER_SENSOR_ID + +antnode = None +power_meter = None + +try: + stick = driver.USB2Driver(None, log=LOG, debug=DEBUG) + antnode = node.Node(stick) + print "Starting ANT node" + antnode.start() + key = node.NetworkKey('N:ANT+', NETKEY) + antnode.setNetworkKey(0, key) + + print "Starting power meter with ANT+ ID " + repr(POWER_SENSOR_ID) + try: + # Create the power meter object and open it + power_meter = PowerMeterTx(antnode, POWER_SENSOR_ID) + power_meter.open() + except Exception as e: + print "power_meter error: " + e.message + power_meter = None + + master = tk.Tk() + master.title("Bot") + master.geometry("200x50") + master.call('wm', 'attributes', '.', '-topmost', '1') + w = tk.Scale(master, from_=0, to=1000, length=200, orient=tk.HORIZONTAL) + w.pack() + + t = 0 + last = 0 + power = 0 + + print "Main wait loop" + while True: + power = w.get() + t = int(time.time()) + if power and t >= last + 1: + power_meter.update(power) + last = t + master.update_idletasks() + master.update() + +except: + pass +finally: + if power_meter: + print "Closing power meter" + power_meter.close() + power_meter.unassign() + if antnode: + print "Stopping ANT node" + antnode.stop() diff --git a/bot.spec b/bot.spec new file mode 100644 index 0000000..2c8e4d2 --- /dev/null +++ b/bot.spec @@ -0,0 +1,36 @@ +# -*- mode: python -*- + +block_cipher = None + +binaries = [ + ('C:\\Windows\\System32\\libusb0.dll', '.'), +] + +a = Analysis(['bot.py'], + pathex=[], + binaries=binaries, + datas=[], + hiddenimports=[], + hookspath=[], + runtime_hooks=[], + excludes=[], + win_no_prefer_redirects=False, + win_private_assemblies=False, + cipher=block_cipher, + noarchive=False) +pyz = PYZ(a.pure, a.zipped_data, + cipher=block_cipher) +exe = EXE(pyz, + a.scripts, + a.binaries, + a.zipfiles, + a.datas, + [], + name='bot', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + upx_exclude="vcruntime140.dll", + runtime_tmpdir=None, + console=True )