view_direct_sampling.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
  2. * See the LICENSE file for information about the license. */
  3. #include "app.h"
  4. #include <cc1101.h>
  5. /* Read directly from the G0 CC1101 pin, and draw a black or white
  6. * dot depending on the level. */
  7. void render_view_direct_sampling(Canvas *const canvas, ProtoViewApp *app) {
  8. if (!app->direct_sampling_enabled) {
  9. canvas_set_font(canvas, FontSecondary);
  10. canvas_draw_str(canvas,2,9,"Direct sampling is a special");
  11. canvas_draw_str(canvas,2,18,"mode that displays the signal");
  12. canvas_draw_str(canvas,2,27,"captured in real time. Like in");
  13. canvas_draw_str(canvas,2,36,"a old CRT TV. It's very slow.");
  14. canvas_draw_str(canvas,2,45,"Can crash your Flipper.");
  15. canvas_set_font(canvas, FontPrimary);
  16. canvas_draw_str(canvas,14,60,"To enable press OK");
  17. return;
  18. }
  19. for (int y = 0; y < 64; y++) {
  20. for (int x = 0; x < 128; x++) {
  21. bool level = furi_hal_gpio_read(&gpio_cc1101_g0);
  22. if (level) canvas_draw_dot(canvas,x,y);
  23. /* Busy loop: this is a terrible approach as it blocks
  24. * everything else, but for now it's the best we can do
  25. * to obtain direct data with some spacing. */
  26. uint32_t x = 250; while(x--);
  27. }
  28. }
  29. canvas_set_font(canvas, FontSecondary);
  30. canvas_draw_str_with_border(canvas,36,60,"Direct sampling",
  31. ColorWhite,ColorBlack);
  32. }
  33. /* Handle input */
  34. void process_input_direct_sampling(ProtoViewApp *app, InputEvent input) {
  35. if (input.type == InputTypePress && input.key == InputKeyOk) {
  36. app->direct_sampling_enabled = !app->direct_sampling_enabled;
  37. }
  38. }
  39. /* Enter view. Stop the subghz thread to prevent access as we read
  40. * the CC1101 data directly. */
  41. void view_enter_direct_sampling(ProtoViewApp *app) {
  42. if (app->txrx->txrx_state == TxRxStateRx &&
  43. !app->txrx->debug_timer_sampling)
  44. {
  45. furi_hal_subghz_stop_async_rx();
  46. } else {
  47. raw_sampling_worker_stop(app);
  48. }
  49. }
  50. /* Exit view. Restore the subghz thread. */
  51. void view_exit_direct_sampling(ProtoViewApp *app) {
  52. if (app->txrx->txrx_state == TxRxStateRx &&
  53. !app->txrx->debug_timer_sampling)
  54. {
  55. furi_hal_subghz_start_async_rx(protoview_rx_callback, NULL);
  56. } else {
  57. raw_sampling_worker_start(app);
  58. }
  59. app->direct_sampling_enabled = false;
  60. }