__init__.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. from typing import Callable
  2. LIGHT_RED: int
  3. '''
  4. Constant value for the red LED light.
  5. '''
  6. LIGHT_GREEN: int
  7. '''
  8. Constant value for the green LED light.
  9. '''
  10. LIGHT_BLUE: int
  11. '''
  12. Constant value for the blue LED light.
  13. '''
  14. LIGHT_BACKLIGHT: int
  15. '''
  16. Constant value for the display backlight.
  17. '''
  18. def light_set(light: int, brightness: int) -> None:
  19. '''
  20. Control the RGB LED on your Flipper. You can also set the brightness of multiple channels at once using bitwise operations.
  21. The ``brightness`` parameter accepts values from 0 (light off) to 255 (very bright).
  22. :param light: The RGB channels to set.
  23. :param brightness: The brightness to use.
  24. :Example:
  25. .. code-block::
  26. import flipperzero as f0
  27. f0.light_set(f0.LIGHT_RED | f0.LIGHT_GREEN, 250)
  28. .. tip::
  29. You can use up to seven colors using `additive mixing <https://en.wikipedia.org/wiki/Additive_color>`_.
  30. '''
  31. pass
  32. def light_blink_start(light: int, brightness: int, on_time: int, period: int) -> None:
  33. '''
  34. Let the RGB LED blink. You can define the total duration of a blink period and the duration, the LED is active during a blink period.
  35. Hence, ``on_time`` must be smaller than ``period``. This is a non-blocking operation. The LED will continue to blink until you call :func:`light_blink_stop`.
  36. :param light: The RGB channels to set.
  37. :param brightness: The brightness to use.
  38. :param on_time: The LED's active duration in milliseconds.
  39. :param period: Total duration of a blink period in milliseconds.
  40. :Example:
  41. .. code-block::
  42. import flipperzero as f0
  43. f0.light_blink_start(f0.LIGHT_RED, 150, 100, 200)
  44. '''
  45. pass
  46. def light_blink_set_color(light: int) -> None:
  47. '''
  48. Change the RGB LED's color while blinking. This is a non-blocking operation.
  49. Be aware, that you must start the blinking procedure first by using the :func:`light_blink_start` function.
  50. Call the :func:`light_blink_stop` function to stop the blinking LED.
  51. :param light: The RGB channels to set.
  52. '''
  53. pass
  54. def light_blink_stop() -> None:
  55. '''
  56. Stop the blinking LED.
  57. '''
  58. pass
  59. def vibro_set(state: bool) -> bool:
  60. '''
  61. Turn vibration on or off. This is a non-blocking operation. The vibration motor will continue to run until you stop it.
  62. :param state: :const:`True` to turn on vibration.
  63. :returns: :const:`True` if vibration is on.
  64. '''
  65. pass
  66. def speaker_start(frequency: float, volume: float) -> bool:
  67. '''
  68. Output a steady tone of a defined frequency and volume on the Flipper's speaker.
  69. This is a non-blocking operation. The tone will continue until you call :func:`speaker_stop`.
  70. The ``volume`` parameter accepts values from 0.0 (silent) up to 1.0 (very loud).
  71. :param frequency: The frequency to play in `hertz <https://en.wikipedia.org/wiki/Hertz>`_.
  72. :param volume: The volume to use.
  73. :returns: :const:`True` if the speaker was acquired.
  74. :Example:
  75. .. code-block::
  76. import flipperzero as f0
  77. f0.speaker_start(50.0, 0.8)
  78. '''
  79. pass
  80. def speaker_set_volume(volume: float) -> bool:
  81. '''
  82. Set the speaker's volume while playing a tone. This is a non-blocking operation.
  83. The tone will continue until you call :func:`speaker_stop`.
  84. The ``volume`` parameter accepts values from 0.0 (silent) up to 1.0 (very loud).
  85. :param volume: The volume to use.
  86. :returns: :const:`True` if the speaker was acquired.
  87. :Example:
  88. This function can be used to play `nice` sounds:
  89. .. code-block::
  90. import time
  91. import flipperzero as f0
  92. volume = 0.8
  93. f0.speaker_start(100.0, volume)
  94. for _ in range(0, 150):
  95. volume *= 0.9945679
  96. f0.speaker_set_volume(volume)
  97. time.sleep_ms(1)
  98. f0.speaker_stop()
  99. '''
  100. pass
  101. def speaker_stop() -> bool:
  102. '''
  103. Stop the speaker output.
  104. :returns: :const:`True` if the speaker was successfully released.
  105. '''
  106. pass
  107. INPUT_BUTTON_UP: int
  108. '''
  109. Constant value for the `up` button.
  110. '''
  111. INPUT_BUTTON_DOWN: int
  112. '''
  113. Constant value for the `down` button.
  114. '''
  115. INPUT_BUTTON_RIGHT: int
  116. '''
  117. Constant value for the `right` button.
  118. '''
  119. INPUT_BUTTON_LEFT: int
  120. '''
  121. Constant value for the `left` button.
  122. '''
  123. INPUT_BUTTON_OK: int
  124. '''
  125. Constant value for the `ok` button.
  126. '''
  127. INPUT_BUTTON_BACK: int
  128. '''
  129. Constant value for the `back` button.
  130. '''
  131. INPUT_TYPE_PRESS: int
  132. '''
  133. Constant value for the `press` event of a button.
  134. '''
  135. INPUT_TYPE_RELEASE: int
  136. '''
  137. Constant value for the `release` event of a button.
  138. '''
  139. INPUT_TYPE_SHORT: int
  140. '''
  141. Constant value for the `short` press event of a button.
  142. '''
  143. INPUT_TYPE_LONG: int
  144. '''
  145. Constant value for the `long` press event of a button.
  146. '''
  147. INPUT_TYPE_REPEAT: int
  148. '''
  149. Constant value for the `repeat` press event of a button.
  150. '''
  151. def on_input() -> Callable[[int, int], None]:
  152. '''
  153. Decorate a function to be used as input handler. The decorated function will be invoked upon interaction with one of the buttons on the Flipper.
  154. :Example:
  155. .. code-block::
  156. import flipperzero as f0
  157. @f0.on_input
  158. def input_handler(button, type):
  159. if button == f0.INPUT_BUTTON_BACK:
  160. if type == f0.INPUT_TYPE_LONG:
  161. ...
  162. .. warning::
  163. You can only decorate one function per application.
  164. '''
  165. pass