camera_suite_view_camera.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <furi.h>
  3. #include <furi_hal.h>
  4. #include <furi_hal_serial_control.h>
  5. #include <furi_hal_serial.h>
  6. #include <gui/elements.h>
  7. #include <gui/gui.h>
  8. #include <gui/icon_i.h>
  9. #include <gui/modules/dialog_ex.h>
  10. #include <gui/view.h>
  11. #include <gui/view_dispatcher.h>
  12. #include <notification/notification.h>
  13. #include <notification/notification_messages.h>
  14. #include <storage/filesystem_api_defines.h>
  15. #include <storage/storage.h>
  16. #include "../helpers/camera_suite_custom_event.h"
  17. #ifdef FW_ORIGIN_Xtreme
  18. /**
  19. * Enable the following line for "Xtreme Firmware" & "Xtreme Apps" (Flipper-XFW).
  20. *
  21. * @see https://github.com/Flipper-XFW/Xtreme-Firmware
  22. * @see https://github.com/Flipper-XFW/Xtreme-Apps
  23. */
  24. #include <xtreme/xtreme.h>
  25. #define UART_CH (xtreme_settings.uart_esp_channel)
  26. #elif defined FW_ORIGIN_Momentum
  27. /**
  28. * Enable the following line for "Momentum Firmware" & "Momentum Apps".
  29. *
  30. * @see https://github.com/Next-Flip/Momentum-Firmware
  31. * @see https://github.com/Next-Flip/Momentum-Apps
  32. */
  33. #include <momentum/momentum.h>
  34. #define UART_CH (momentum_settings.uart_esp_channel)
  35. #elif defined FW_ORIGIN_RM
  36. /**
  37. Enable the following line for "RogueMaster Firmware"
  38. @see https://github.com/RogueMaster/flipperzero-firmware-wPlugins
  39. */
  40. #include <cfw/cfw.h>
  41. #define UART_CH (cfw_settings.uart_esp_channel)
  42. #else
  43. #define UART_CH (FuriHalSerialIdUsart)
  44. #endif
  45. #define BITMAP_HEADER_LENGTH 62
  46. #define FRAME_BIT_DEPTH 1
  47. #define FRAME_BUFFER_LENGTH 1024
  48. #define FRAME_HEIGHT 64
  49. #define FRAME_WIDTH 128
  50. #define HEADER_LENGTH 3 // 'Y', ':', and row identifier
  51. #define LAST_ROW_INDEX 1008
  52. #define RING_BUFFER_LENGTH 19
  53. #define ROW_BUFFER_LENGTH 16
  54. static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
  55. 0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
  56. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
  57. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
  59. typedef enum {
  60. WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
  61. WorkerEventStop = (1 << 1),
  62. WorkerEventRx = (1 << 2),
  63. } WorkerEventFlags;
  64. #define CAMERA_WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
  65. // Forward declaration
  66. typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context);
  67. typedef struct CameraSuiteViewCamera {
  68. CameraSuiteViewCameraCallback callback;
  69. FuriStreamBuffer* camera_rx_stream;
  70. FuriHalSerialHandle* serial_handle;
  71. FuriThread* camera_worker_thread;
  72. NotificationApp* notification;
  73. View* view;
  74. void* context;
  75. } CameraSuiteViewCamera;
  76. typedef struct UartDumpModel {
  77. bool is_dithering_enabled;
  78. bool is_initialized;
  79. bool is_inverted;
  80. int rotation_angle;
  81. uint32_t orientation;
  82. uint8_t pixels[FRAME_BUFFER_LENGTH];
  83. uint8_t ringbuffer_index;
  84. uint8_t row_identifier;
  85. uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
  86. } UartDumpModel;
  87. // Function Prototypes
  88. CameraSuiteViewCamera* camera_suite_view_camera_alloc();
  89. View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static);
  90. void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static);
  91. void camera_suite_view_camera_set_callback(
  92. CameraSuiteViewCamera* camera_suite_view_camera,
  93. CameraSuiteViewCameraCallback callback,
  94. void* context);