Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

temp_log_config.py 2.9KB

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