Add support for multiple light bars/remotes (#3), bump to version 0.2

This commit is contained in:
Erik Borowski
2024-12-01 02:47:01 +01:00
parent a0b246aae1
commit 8901d409ca
12 changed files with 658 additions and 243 deletions

27
radio.h
View File

@ -4,13 +4,15 @@
#include <RF24.h>
#include <CRC16.h>
#define MAX_REMOTES 10
#include "constants.h"
#include "remote.h"
struct Remote
class Remote;
struct PackageIdForSerial
{
uint32_t serial;
uint8_t last_received_package_id;
std::function<void(uint32_t, byte command, byte options)> callback;
uint8_t package_id;
};
class Radio
@ -19,19 +21,18 @@ public:
Radio(uint8_t ce, uint8_t csn);
~Radio();
void setup();
void sendCommand(byte command, byte options);
void sendCommand(byte command);
void sendCommand(uint32_t serial, byte command, byte options);
void sendCommand(uint32_t serial, byte command);
void loop();
void setOutgoingSerial(uint32_t serial);
bool addIncomingSerial(uint32_t serial, std::function<void(uint32_t, byte, byte)> callback);
bool removeIncomingSerial(uint32_t serial);
bool addRemote(Remote *remote);
bool removeRemote(Remote *remote);
private:
RF24 radio;
uint8_t last_sent_package_id = 0;
uint32_t outgoing_serial;
PackageIdForSerial package_ids[constants::MAX_SERIALS];
uint8_t num_package_ids = 0;
Remote remotes[MAX_REMOTES];
Remote *remotes[constants::MAX_REMOTES];
uint8_t num_remotes = 0;
static const uint64_t address = 0xAAAAAAAAAAAA;
@ -40,6 +41,8 @@ private:
// For details on how these parameters were chosen, see
// https://github.com/lamperez/xiaomi-lightbar-nrf24?tab=readme-ov-file#crc-checksum
CRC16 crc = CRC16(0x1021, 0xfffe, 0x0000, false, false);
void handlePackage();
};
#endif