modflipperzero_impl.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <furi_hal.h>
  2. #include "modflipperzero.h"
  3. static Light decode_light(uint8_t value) {
  4. Light light = 0;
  5. light += value & MP_FLIPPER_LED_RED ? LightRed : 0;
  6. light += value & MP_FLIPPER_LED_GREEN ? LightGreen : 0;
  7. light += value & MP_FLIPPER_LED_BLUE ? LightBlue : 0;
  8. light += value & MP_FLIPPER_LED_BACKLIGHT ? LightBacklight : 0;
  9. return light;
  10. }
  11. inline void mp_flipper_light_set(uint8_t raw_light, uint8_t brightness) {
  12. Light light = decode_light(raw_light);
  13. furi_hal_light_set(light, brightness);
  14. }
  15. inline void mp_flipper_light_blink_start(uint8_t raw_light, uint8_t brightness, uint16_t on_time, uint16_t period) {
  16. Light light = decode_light(raw_light);
  17. furi_hal_light_blink_start(light, brightness, on_time, period);
  18. }
  19. inline void mp_flipper_light_blink_set_color(uint8_t raw_light) {
  20. Light light = decode_light(raw_light);
  21. furi_hal_light_blink_set_color(light);
  22. }
  23. inline void mp_flipper_light_blink_stop() {
  24. furi_hal_light_blink_stop();
  25. }
  26. inline void mp_flipper_vibro(bool state) {
  27. furi_hal_vibro_on(state);
  28. }
  29. inline bool mp_flipper_speaker_start(float frequency, float volume) {
  30. if(furi_hal_speaker_acquire(100)) {
  31. furi_hal_speaker_start(frequency, volume);
  32. return true;
  33. }
  34. return false;
  35. }
  36. inline bool mp_flipper_speaker_set_volume(float volume) {
  37. if(furi_hal_speaker_is_mine()) {
  38. furi_hal_speaker_set_volume(volume);
  39. return true;
  40. }
  41. return false;
  42. }
  43. inline bool mp_flipper_speaker_stop() {
  44. if(furi_hal_speaker_is_mine()) {
  45. furi_hal_speaker_stop();
  46. furi_hal_speaker_release();
  47. return true;
  48. }
  49. return false;
  50. }