jesserockz

Untitled

Jan 18th, 2021
847
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void ICACHE_RAM_ATTR CrowAlarmPanelStore::interrupt(CrowAlarmPanelStore *arg) {
  2.   bool data_bit = arg->data_pin_->digital_read();
  3.  
  4.   // Check for boundary
  5.   arg->boundary_buffer_ = (uint8_t)((arg->boundary_buffer_ << 1) | data_bit);
  6.  
  7.   uint8_t idx = arg->num_bits / 8;
  8.   if (arg->inside_) {
  9.     arg->buffer[idx] = (arg->buffer[idx] >> 1) | ((data_bit ? 1 : 0) << 7);
  10.     arg->num_bits++;
  11.     if (arg->boundary_buffer_ == BOUNDARY) {
  12.       arg->message.type = arg->buffer[0];
  13.       memcpy(arg->message.data_buffer, arg->buffer + 1, idx - 1);
  14.       arg->message.data_len = idx - 1;
  15.       arg->message_available = true;
  16.       arg->inside_ = false;
  17.       arg->num_bits = 0;
  18.     }
  19.     return;
  20.   }
  21.  
  22.   if (arg->boundary_buffer_ == BOUNDARY) {
  23.     arg->inside_ = true;
  24.   }
  25.  
  26.   if (arg->inside_ && arg->num_bits > 200) {
  27.     // Wrong side of boundary.
  28.     arg->inside_ = false;
  29.     arg->num_bits = 0;
  30.   }
  31. }
RAW Paste Data