S&B Volcano vaporizer remote control with Pi Pico W
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python
  2. import sys
  3. import time
  4. import os
  5. from poll import (
  6. ble_conn,
  7. get_current_temp,
  8. get_target_temp, set_target_temp,
  9. get_unit_is_fahrenheit,
  10. get_state, set_state
  11. )
  12. terminal_width = os.get_terminal_size().columns - 15
  13. def print_bar(value, start, end, unit):
  14. width = terminal_width
  15. s = "\r"
  16. s += "#" * int((value - start) / (end - start) * width)
  17. s += "-" * (width - int((value - start) / (end - start) * width))
  18. s += " {}{}".format(value, unit)
  19. print(s, end="", flush=True)
  20. def sleep(t):
  21. w = terminal_width
  22. if t < w:
  23. w = int(t)
  24. print_bar(0, 0, w, "s")
  25. for i in range(0, w):
  26. time.sleep(t / w)
  27. print_bar(i + 1, 0, w, "s")
  28. print()
  29. def wait_for_temp(client, temp):
  30. print("Setting temperature {}".format(temp))
  31. set_target_temp(client, temp)
  32. print("Waiting for temperature to rise...")
  33. start = get_current_temp(client)
  34. curr = start
  35. print_bar(curr, start, temp, " degC")
  36. while curr < temp:
  37. time.sleep(1.0)
  38. curr = get_current_temp(client)
  39. print_bar(curr, start, temp, " degC")
  40. print()
  41. print("Reached temperature {}".format(temp))
  42. def flow_step(client, temp, t_wait, t_pump):
  43. wait_for_temp(client, temp)
  44. print("Waiting {}s for heat to settle...".format(t_wait))
  45. sleep(t_wait)
  46. print("Pumping for {}s".format(t_pump))
  47. set_state(client, (True, True)) # turn on pump
  48. sleep(t_pump)
  49. set_state(client, (True, False)) # turn off pump
  50. def flow(client):
  51. print("Turning on heater")
  52. set_state(client, (True, False))
  53. flow_step(client, 190.0, 20.0, 5.0)
  54. flow_step(client, 205.0, 10.0, 20.0)
  55. flow_step(client, 220.0, 10.0, 20.0)
  56. print("Notification by pumping three times...")
  57. for i in range(0, 3):
  58. time.sleep(1.0)
  59. set_state(client, (True, True)) # turn on pump
  60. time.sleep(1.0)
  61. set_state(client, (True, False)) # turn off pump
  62. print("Turning heater off")
  63. set_state(client, (False, False)) # turn off heater and pump
  64. if __name__ == "__main__":
  65. def main(address, adapter):
  66. client = ble_conn(address, adapter)
  67. try:
  68. if get_unit_is_fahrenheit(client):
  69. raise RuntimeError("Imperial American scum is currently not supported :P")
  70. print("Starting Workflow")
  71. flow(client)
  72. except:
  73. print("\nTurning heater off")
  74. set_state(client, (False, False)) # turn off heater and pump
  75. print("Disconnecting")
  76. client.disconnect()
  77. raise
  78. print("Disconnecting")
  79. client.disconnect()
  80. adapter = None
  81. mac = None
  82. if len(sys.argv) > 1:
  83. adapter = int(sys.argv[1])
  84. if len(sys.argv) > 2:
  85. mac = sys.argv[2]
  86. main(mac, adapter)