implement bell ringing using registries
This commit is contained in:
parent
18e0e6ad26
commit
7c1afa3b87
@ -1,7 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Protocol.h"
|
#include "Protocol.h"
|
||||||
|
#include "RC.h"
|
||||||
|
|
||||||
|
#define BIT_LENGTH 40
|
||||||
|
#define BIT_LENGTH_3 BIT_LENGTH*3
|
||||||
#define TX_DELAY 620
|
#define TX_DELAY 620
|
||||||
|
#define PORT_BIT PB3
|
||||||
|
|
||||||
class Protocol_Doorbell : public Protocol {
|
class Protocol_Doorbell : public Protocol {
|
||||||
|
|
||||||
@ -10,18 +14,63 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override {
|
void fromJson(JsonObjectConst& rcSwitch, RCSwitch& rcDevice) override {
|
||||||
// unsigned int protocol = rcSwitch["protocol"];
|
pinMode(SEND_PIN, OUTPUT);
|
||||||
// rcDevice.setProtocol(protocol);
|
|
||||||
preamble();
|
preamble();
|
||||||
delayMicroseconds(TX_DELAY);
|
_delay_us(TX_DELAY);
|
||||||
send();
|
for (int i = 0; i < 7; i++) {
|
||||||
|
code("00000000110100101000100");
|
||||||
|
_delay_us(TX_DELAY);
|
||||||
|
}
|
||||||
|
pinMode(SEND_PIN, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void preamble() {
|
void transmitBit(uint8_t value) {
|
||||||
digitalWrite(1, 1);
|
digitalWrite(SEND_PIN, value);
|
||||||
|
delayMicroseconds(BIT_LENGTH);
|
||||||
|
digitalWrite(SEND_PIN, LOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
void send() {
|
void transmitHigh() {
|
||||||
|
// digitalWrite(TX_PIN, HIGH);
|
||||||
|
// delayMicroseconds(BIT_LENGTH_3);
|
||||||
|
// digitalWrite(TX_PIN, LOW);
|
||||||
|
// delayMicroseconds(BIT_LENGTH);
|
||||||
|
// noInterrupts();
|
||||||
|
PORTB |= _BV(PORT_BIT); // HIGH
|
||||||
|
_delay_us(BIT_LENGTH_3);
|
||||||
|
PORTB &= ~_BV(PORT_BIT); // LOW
|
||||||
|
_delay_us(BIT_LENGTH);
|
||||||
|
// interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void transmitLow() {
|
||||||
|
// digitalWrite(TX_PIN, HIGH);
|
||||||
|
// delayMicroseconds(BIT_LENGTH);
|
||||||
|
// digitalWrite(TX_PIN, LOW);
|
||||||
|
// delayMicroseconds(BIT_LENGTH_3);
|
||||||
|
// noInterrupts();
|
||||||
|
PORTB |= _BV(PORT_BIT); // HIGH
|
||||||
|
_delay_us(BIT_LENGTH);
|
||||||
|
PORTB &= ~_BV(PORT_BIT); // LOW
|
||||||
|
_delay_us(BIT_LENGTH_3);
|
||||||
|
// interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void preamble() {
|
||||||
|
noInterrupts();
|
||||||
|
for (int i = 0; i < 370; i++) {
|
||||||
|
transmitBit(HIGH);
|
||||||
|
transmitBit(LOW);
|
||||||
|
}
|
||||||
|
interrupts();
|
||||||
|
}
|
||||||
|
|
||||||
|
void code(const char* value) {
|
||||||
|
noInterrupts();
|
||||||
|
for (const char* p = value; *p; p++) {
|
||||||
|
*p == '1' ? transmitHigh() : transmitLow();
|
||||||
|
}
|
||||||
|
interrupts();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user