5 Copyright (C) Dean Camera, 2018.
7 dean [at] fourwalledcubicle [dot] com
12 Front-end configuration app for the TempDataLogger project. This script
13 configures the logger to the current system time and date, with a user
14 defined logging interval.
16 The logging interval should be specified in milliseconds and is rounded to
20 python temp_log_config.py <Log_Interval>
23 python temp_log_config.py 500
25 Requires the pywinusb library (https://pypi.python.org/pypi/pywinusb/).
29 from datetime
import datetime
33 def get_hid_device_handle():
34 all_hid_devices
= hid
.enumerate()
36 lufa_hid_devices
= [d
for d
in all_hid_devices
if d
['vendor_id'] == 0x03EB and d
['product_id'] == 0x2063]
38 if len(lufa_hid_devices
) is 0:
41 device_handle
= hid
.device()
42 device_handle
.open_path(lufa_hid_devices
[0]['path'])
46 def configure_temp_log_device(device
, time_date
, log_interval_500ms
):
47 report_data
= bytearray(8)
49 # Report data for the demo is the report ID (always zero)
52 # Followed by the time/date data
53 report_data
[1] = time_date
.hour
54 report_data
[2] = time_date
.minute
,
55 report_data
[3] = time_date
.second
56 report_data
[4] = time_date
.day
,
57 report_data
[5] = time_date
.month
58 report_data
[6] = time_date
.year
- 2000
60 # Lastly the log interval in 500ms units of time
61 report_data
[7] = log_interval_500ms
63 # Send the generated report to the device
64 device
.write(report_data
)
67 def main(time_date
, log_interval_500ms
):
68 hid_device
= get_hid_device_handle()
70 if hid_device
is None:
71 print("No valid HID device found.")
75 print("Connected to device.", flush
=True)
77 configure_temp_log_device(hid_device
, time_date
, log_interval_500ms
)
79 print("Time/Date is now set to %s" % time_date
)
80 print("Log interval is now set to every %0.1fs" %
(log_interval_500ms
* (500.0 / 1000.0)))
86 if __name__
== '__main__':
87 time_date
= datetime
.now()
88 log_interval_500ms
= (int(sys
.argv
[1]) / 500) if len(sys
.argv
) > 1 else 2
90 # Clamp the log interval to the allowable range
91 log_interval_500ms
= max(log_interval_500ms
, 0x01)
92 log_interval_500ms
= min(log_interval_500ms
, 0xFF)
94 main(time_date
, log_interval_500ms
)