wiegand_play.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "../wiegand.h"
  2. void single_vibro() {
  3. NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION);
  4. notification_message(notification, &sequence_single_vibro);
  5. furi_record_close(RECORD_NOTIFICATION);
  6. }
  7. void wiegand_play() {
  8. uint32_t* delays = malloc(sizeof(uint32_t) * bit_count * 2);
  9. for(int i = 0; i < bit_count - 1; i++) {
  10. delays[i * 2] = (data_rise[i] - data_fall[i]) / 64;
  11. delays[i * 2 + 1] = (data_fall[i + 1] - data_rise[i]) / 64;
  12. }
  13. delays[(bit_count - 1) * 2] = (data_rise[bit_count - 1] - data_fall[bit_count - 1]) / 64;
  14. delays[(bit_count - 1) * 2 + 1] = 1;
  15. for(int i = 0; i < bit_count; i++) {
  16. // Delays are always at least 1 tick.
  17. if(delays[i * 2] == 0) delays[i * 2] = 1;
  18. if(delays[i * 2 + 1] == 0) delays[i * 2 + 1] = 1;
  19. if(delays[i * 2 + 1] > 5) delays[i * 2 + 1] -= 1;
  20. }
  21. furi_hal_gpio_write(pinD0, true);
  22. furi_hal_gpio_init(pinD0, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  23. furi_hal_gpio_write(pinD1, true);
  24. furi_hal_gpio_init(pinD1, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
  25. single_vibro();
  26. furi_delay_ms(500);
  27. int j = 0;
  28. for(int i = 0; i < bit_count; i++) {
  29. if(data[i]) {
  30. furi_hal_gpio_write(pinD1, false);
  31. furi_delay_us(delays[j++]);
  32. furi_hal_gpio_write(pinD1, true);
  33. furi_delay_us(delays[j++]);
  34. } else {
  35. furi_hal_gpio_write(pinD0, false);
  36. furi_delay_us(delays[j++]);
  37. furi_hal_gpio_write(pinD0, true);
  38. furi_delay_us(delays[j++]);
  39. }
  40. }
  41. furi_hal_gpio_init_simple(pinD0, GpioModeAnalog);
  42. furi_hal_gpio_init_simple(pinD1, GpioModeAnalog);
  43. }