]> git.gir.st - tmk_keyboard.git/blob - protocol/lufa/LUFA-git/Projects/TempDataLogger/TempLogHostApp_Python/temp_log_config.py
Squashed 'tmk_core/' changes from caca2c0..dc0e46e
[tmk_keyboard.git] / protocol / lufa / LUFA-git / Projects / TempDataLogger / TempLogHostApp_Python / temp_log_config.py
1 """
2 LUFA Library
3 Copyright (C) Dean Camera, 2014.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.lufa-lib.org
7 """
8
9 """
10 Front-end configuration app for the TempDataLogger project. This script
11 configures the logger to the current system time and date, with a user
12 defined logging interval.
13
14 The logging interval should be specified in milliseconds and is rounded to
15 a multiple of 500ms.
16
17 Usage:
18 python temp_log_config.py <Log_Interval>
19
20 Example:
21 python temp_log_config.py 500
22
23 Requires the pywinusb library (https://pypi.python.org/pypi/pywinusb/).
24 """
25
26 import sys
27 from datetime import datetime
28 import pywinusb.hid as hid
29
30 # Generic HID device VID, PID and report payload length (length is increased
31 # by one to account for the Report ID byte that must be pre-pended)
32 device_vid = 0x03EB
33 device_pid = 0x2063
34 report_length = 1 + 7
35
36
37 def get_hid_device_handle():
38 hid_device_filter = hid.HidDeviceFilter(vendor_id=device_vid,
39 product_id=device_pid)
40
41 valid_hid_devices = hid_device_filter.get_devices()
42
43 if len(valid_hid_devices) is 0:
44 return None
45 else:
46 return valid_hid_devices[0]
47
48
49 def configure_temp_log_device(device, time_date, log_interval_500ms):
50 # Report data for the demo is the report ID (always zero)
51 report_data = [0]
52
53 # Followed by the time/date data
54 report_data.extend([time_date.hour, time_date.minute,
55 time_date.second, time_date.day,
56 time_date.month, time_date.year - 2000])
57
58 # Lastly the log interval in 500ms units of time
59 report_data.extend([log_interval_500ms])
60
61 # Zero-extend the array to the length the report should be
62 report_data.extend([0] * (report_length - len(report_data)))
63
64 # Send the generated report to the device
65 device.send_output_report(report_data)
66
67
68 def main(time_date, log_interval_500ms):
69 hid_device = get_hid_device_handle()
70
71 if hid_device is None:
72 print("No valid HID device found.")
73 sys.exit(1)
74
75 try:
76 hid_device.open()
77
78 print("Connected to device 0x%04X/0x%04X - %s [%s]" %
79 (hid_device.vendor_id, hid_device.product_id,
80 hid_device.product_name, hid_device.vendor_name))
81
82 configure_temp_log_device(hid_device, time_date, log_interval_500ms)
83
84 print("Time/Date is now set to %s" % time_date)
85 print("Log interval is now set to every %0.1fs" % (log_interval_500ms * (500.0 / 1000.0)))
86
87 finally:
88 hid_device.close()
89
90
91 if __name__ == '__main__':
92 time_date = datetime.now()
93 log_interval_500ms = (int(sys.argv[1]) / 500) if len(sys.argv) > 1 else 2
94
95 # Clamp the log interval to the allowable range
96 log_interval_500ms = max(log_interval_500ms, 0x01)
97 log_interval_500ms = min(log_interval_500ms, 0xFF)
98
99 main(time_date, log_interval_500ms)
Imprint / Impressum