aboutsummaryrefslogtreecommitdiff
path: root/lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-07-07 11:55:23 -0400
committerJack Humbert <jack.humb@gmail.com>2017-07-07 11:55:23 -0400
commit8655d4f4948b2deef7844503c8d690f23ac1a062 (patch)
treeb2c6effc9d6cd5b5b43933a1e53b8bf17e9e82cf /lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python
parent1896c76a2928c96f9ab7947bec2ef8dd37623cff (diff)
parent60b30c036397cb5627fa374bb930794b225daa29 (diff)
downloadqmk_firmware-8655d4f4948b2deef7844503c8d690f23ac1a062.tar.gz
qmk_firmware-8655d4f4948b2deef7844503c8d690f23ac1a062.zip
Merge commit '60b30c036397cb5627fa374bb930794b225daa29' as 'lib/lufa'
Diffstat (limited to 'lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python')
-rw-r--r--lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python/temp_log_config.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python/temp_log_config.py b/lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python/temp_log_config.py
new file mode 100644
index 000000000..fdb4ad9b6
--- /dev/null
+++ b/lib/lufa/Projects/TempDataLogger/TempLogHostApp_Python/temp_log_config.py
@@ -0,0 +1,99 @@
1"""
2 LUFA Library
3 Copyright (C) Dean Camera, 2017.
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
26import sys
27from datetime import datetime
28import 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)
32device_vid = 0x03EB
33device_pid = 0x2063
34report_length = 1 + 7
35
36
37def 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
49def 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
68def 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
91if __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)