camera_suite_view_camera.h 3.5 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. *
  39. * @see https://github.com/RogueMaster/flipperzero-firmware-wPlugins
  40. */
  41. #include <cfw/cfw.h>
  42. #define UART_CH (cfw_settings.uart_esp_channel)
  43. #else
  44. #define UART_CH (FuriHalSerialIdUsart)
  45. #endif
  46. #define BITMAP_HEADER_LENGTH 62
  47. #define FRAME_BIT_DEPTH 1
  48. #define FRAME_BUFFER_LENGTH (2 * 1024)
  49. #define FRAME_HEIGHT 64
  50. #define FRAME_WIDTH 128
  51. #define HEADER_LENGTH 3 // 'Y', ':', and row identifier
  52. #define LAST_ROW_INDEX (2 * 1008)
  53. #define RING_BUFFER_LENGTH 19
  54. #define ROW_BUFFER_LENGTH 16
  55. static const unsigned char bitmap_header[BITMAP_HEADER_LENGTH] = {
  56. 0x42, 0x4D, 0x3E, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x28, 0x00,
  57. 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00};
  60. typedef enum {
  61. WorkerEventReserved = (1 << 0), // Reserved for StreamBuffer internal event
  62. WorkerEventStop = (1 << 1),
  63. WorkerEventRx = (1 << 2),
  64. } WorkerEventFlags;
  65. #define CAMERA_WORKER_EVENTS_MASK (WorkerEventStop | WorkerEventRx)
  66. // Forward declaration
  67. typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context);
  68. typedef struct CameraSuiteViewCamera {
  69. CameraSuiteViewCameraCallback callback;
  70. FuriStreamBuffer* camera_rx_stream;
  71. FuriHalSerialHandle* serial_handle;
  72. FuriThread* camera_worker_thread;
  73. NotificationApp* notification;
  74. View* view;
  75. void* context;
  76. } CameraSuiteViewCamera;
  77. typedef struct UartDumpModel {
  78. bool is_dithering_enabled;
  79. bool is_initialized;
  80. bool is_inverted;
  81. int rotation_angle;
  82. uint32_t orientation;
  83. uint8_t pixels[FRAME_BUFFER_LENGTH];
  84. uint8_t ringbuffer_index;
  85. uint8_t row_identifier;
  86. uint8_t row_ringbuffer[RING_BUFFER_LENGTH];
  87. } UartDumpModel;
  88. // Function Prototypes
  89. CameraSuiteViewCamera* camera_suite_view_camera_alloc();
  90. View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static);
  91. void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static);
  92. void camera_suite_view_camera_set_callback(
  93. CameraSuiteViewCamera* camera_suite_view_camera,
  94. CameraSuiteViewCameraCallback callback,
  95. void* context);