modflipperzero_impl.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include <stdint.h>
  2. #include <furi_hal.h>
  3. #include <mp_flipper_app.h>
  4. #include "modflipperzero.h"
  5. static Light decode_light(uint8_t value) {
  6. Light light = 0;
  7. light += value & MP_FLIPPER_LED_RED ? LightRed : 0;
  8. light += value & MP_FLIPPER_LED_GREEN ? LightGreen : 0;
  9. light += value & MP_FLIPPER_LED_BLUE ? LightBlue : 0;
  10. light += value & MP_FLIPPER_LED_BACKLIGHT ? LightBacklight : 0;
  11. return light;
  12. }
  13. inline void mp_flipper_light_set(uint8_t raw_light, uint8_t brightness) {
  14. Light light = decode_light(raw_light);
  15. furi_hal_light_set(light, brightness);
  16. }
  17. inline void mp_flipper_light_blink_start(uint8_t raw_light, uint8_t brightness, uint16_t on_time, uint16_t period) {
  18. Light light = decode_light(raw_light);
  19. furi_hal_light_blink_start(light, brightness, on_time, period);
  20. }
  21. inline void mp_flipper_light_blink_set_color(uint8_t raw_light) {
  22. Light light = decode_light(raw_light);
  23. furi_hal_light_blink_set_color(light);
  24. }
  25. inline void mp_flipper_light_blink_stop() {
  26. furi_hal_light_blink_stop();
  27. }
  28. inline void mp_flipper_vibro(bool state) {
  29. furi_hal_vibro_on(state);
  30. }
  31. inline bool mp_flipper_speaker_start(float frequency, float volume) {
  32. if(furi_hal_speaker_acquire(100)) {
  33. furi_hal_speaker_start(frequency, volume);
  34. return true;
  35. }
  36. return false;
  37. }
  38. inline bool mp_flipper_speaker_set_volume(float volume) {
  39. if(furi_hal_speaker_is_mine()) {
  40. furi_hal_speaker_set_volume(volume);
  41. return true;
  42. }
  43. return false;
  44. }
  45. inline bool mp_flipper_speaker_stop() {
  46. if(furi_hal_speaker_is_mine()) {
  47. furi_hal_speaker_stop();
  48. furi_hal_speaker_release();
  49. return true;
  50. }
  51. return false;
  52. }
  53. inline void mp_flipper_canvas_draw_dot(uint8_t x, uint8_t y, bool color) {
  54. size_t index = (x + 1) / SCREEN_PIXEL_PER_ITEM + y * (SCREEN_WIDTH / SCREEN_PIXEL_PER_ITEM);
  55. const uint32_t mask = 1 << (x % SCREEN_PIXEL_PER_ITEM);
  56. mp_flipper_canvas[index] |= color ? (UINT32_MAX & mask) : 0;
  57. }
  58. inline void mp_flipper_canvas_update() {
  59. view_port_update(mp_flipper_view_port);
  60. }