3 Copyright (C) Dean Camera, 2016.
5 dean [at] fourwalledcubicle [dot] com
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.
14 The logging interval should be specified in milliseconds and is rounded to
18 python temp_log_config.py <Log_Interval>
21 python temp_log_config.py 500
23 Requires the pywinusb library (https://pypi.python.org/pypi/pywinusb/).
27 from datetime
import datetime
28 import pywinusb
.hid
as hid
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)
37 def get_hid_device_handle():
38 hid_device_filter
= hid
.HidDeviceFilter(vendor_id
=device_vid
,
39 product_id
=device_pid
)
41 valid_hid_devices
= hid_device_filter
.get_devices()
43 if len(valid_hid_devices
) is 0:
46 return valid_hid_devices
[0]
49 def configure_temp_log_device(device
, time_date
, log_interval_500ms
):
50 # Report data for the demo is the report ID (always zero)
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])
58 # Lastly the log interval in 500ms units of time
59 report_data
.extend([log_interval_500ms
])
61 # Zero-extend the array to the length the report should be
62 report_data
.extend([0] * (report_length
- len(report_data
)))
64 # Send the generated report to the device
65 device
.send_output_report(report_data
)
68 def main(time_date
, log_interval_500ms
):
69 hid_device
= get_hid_device_handle()
71 if hid_device
is None:
72 print("No valid HID device found.")
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
))
82 configure_temp_log_device(hid_device
, time_date
, log_interval_500ms
)
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)))
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
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)
99 main(time_date
, log_interval_500ms
)