272 lines
6.8 KiB
C++
272 lines
6.8 KiB
C++
#pragma once
|
|
|
|
//obsolete (@postman|@sampler still ues this)
|
|
#define I2C_ADDR 3
|
|
#define POST_LENGTH 32
|
|
#define POST_BUFF_LEN (POST_LENGTH + 1)
|
|
|
|
//esp-now
|
|
#include <vector>
|
|
|
|
// (DEBUG) fetch full peer list
|
|
#if defined(ARDUINO_ARCH_ESP32) // for esp32 API
|
|
#include <esp_now.h>
|
|
struct PeerLister {
|
|
void print() {
|
|
Serial.printf("\n# (DEBUG) peer list (NOTE: a broadcast peer won't be listed properly)\n");
|
|
esp_now_peer_num_t num;
|
|
esp_now_get_peer_num(&num);
|
|
esp_now_peer_info_t peer_info = {};
|
|
bool first = true;
|
|
for (uint8_t ii = 0; ii < num.total_num; ii++) {
|
|
esp_now_fetch_peer(first, &peer_info);
|
|
if (first) first = false;
|
|
Serial.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
|
peer_info.peer_addr[0],
|
|
peer_info.peer_addr[1],
|
|
peer_info.peer_addr[2],
|
|
peer_info.peer_addr[3],
|
|
peer_info.peer_addr[4],
|
|
peer_info.peer_addr[5]);
|
|
}
|
|
}
|
|
};
|
|
#elif defined(ARDUINO_ARCH_ESP8266) // for esp8266 API
|
|
#include <espnow.h>
|
|
struct PeerLister {
|
|
void print() {
|
|
Serial.printf("\n# (DEBUG) peer list\n");
|
|
bool first = true;
|
|
uint8_t * peer_addr = NULL;
|
|
while((peer_addr = esp_now_fetch_peer(first)) != NULL) {
|
|
first = false;
|
|
Serial.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
|
peer_addr[0],
|
|
peer_addr[1],
|
|
peer_addr[2],
|
|
peer_addr[3],
|
|
peer_addr[4],
|
|
peer_addr[5]);
|
|
}
|
|
}
|
|
};
|
|
#endif
|
|
|
|
|
|
// 'address'
|
|
struct Address {
|
|
String name;
|
|
uint8_t mac[6];
|
|
Address() {
|
|
mac[0] = 0;
|
|
mac[1] = 0;
|
|
mac[2] = 0;
|
|
mac[3] = 0;
|
|
mac[4] = 0;
|
|
mac[5] = 0;
|
|
name = "";
|
|
};
|
|
Address(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f, String n) {
|
|
mac[0] = a;
|
|
mac[1] = b;
|
|
mac[2] = c;
|
|
mac[3] = d;
|
|
mac[4] = e;
|
|
mac[5] = f;
|
|
name = n;
|
|
}
|
|
//
|
|
String to_string() {
|
|
char mac_cstr[18]; // "AA:BB:CC:AA:BB:CC"
|
|
snprintf(mac_cstr, 18, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
return (String(mac_cstr) + " ==> " + name);
|
|
}
|
|
};
|
|
|
|
struct AddressBook {
|
|
String title;
|
|
std::vector<Address> list;
|
|
|
|
//
|
|
AddressBook (String title_ = "") {
|
|
title = title_;
|
|
}
|
|
//
|
|
void add(Address addr) {
|
|
list.push_back(addr);
|
|
}
|
|
};
|
|
|
|
//
|
|
struct AddressLibrary {
|
|
//
|
|
std::vector<AddressBook> lib;
|
|
//
|
|
AddressLibrary() {
|
|
|
|
// book #0 - broadcast only
|
|
{
|
|
AddressBook book = AddressBook("broadcast only");
|
|
//
|
|
// [broadcast only]
|
|
book.add(Address(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, "BROADCAST")); //a broadcast
|
|
//
|
|
lib.push_back(book);
|
|
}
|
|
|
|
// 0set프로젝트 <어서오세요>
|
|
|
|
// book #1 - welcome
|
|
{
|
|
AddressBook book = AddressBook("welcome");
|
|
//
|
|
// [pd]
|
|
book.add(Address(0x24, 0xA1, 0x60, 0x25, 0xB9, 0x48, "[pd]"));
|
|
//
|
|
// [voices]
|
|
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x5C, "voices 1 "));//10001 A8:03:2A:6C:88:5C
|
|
book.add(Address(0xA8, 0x03, 0x2A, 0x75, 0xD0, 0x68, "voices 2 "));//10002 A8:03:2A:75:D0:68
|
|
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x78, "voices 3 "));//10003 A8:03:2A:6C:88:78
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x73, 0x08, "voices 8 "));//10008 08:3A:F2:48:73:08
|
|
book.add(Address(0xE0, 0xE2, 0xE6, 0xCD, 0x0A, 0xCC, "voices 9 "));//10009 E0:E2:E6:CD:0A:CC
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x72, 0xD8, "voices 10"));//10010 08:3A:F2:48:72:D8
|
|
//
|
|
// [environmental]
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x72, 0xAC, "environmental 14"));//20014 08:3A:F2:48:72:AC
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x72, 0xD4, "environmental 15"));//20015 08:3A:F2:48:72:D4
|
|
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAD, 0xB0, "environmental 16"));//20016 AC:67:B2:0B:AD:B0
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x72, 0xA8, "environmental 17"));//20017 08:3A:F2:48:72:A8
|
|
//
|
|
// [backstage]
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x48, 0x72, 0xB0, "backstage 11 "));//20011 08:3A:F2:48:72:B0
|
|
//
|
|
// [onstage radio]
|
|
book.add(Address(0x08, 0x3A, 0xF2, 0x4E, 0x5B, 0x38, "onstage 6 "));//10006 08:3A:F2:4E:5B:38
|
|
//+
|
|
book.add(Address(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, "BROADCAST")); //a broadcast
|
|
//
|
|
lib.push_back(book);
|
|
}
|
|
}
|
|
//
|
|
AddressBook* getBookByTitle(String title_) {
|
|
for (uint32_t i = 0; i < lib.size(); i++) {
|
|
if (lib[i].title == title_) {
|
|
return &(lib[i]);
|
|
}
|
|
}
|
|
//
|
|
return NULL;
|
|
}
|
|
};
|
|
|
|
//message type Note : '[' + Note + ']'
|
|
struct Note {
|
|
//
|
|
int32_t id;
|
|
float pitch;
|
|
float velocity;
|
|
float onoff;
|
|
float x1;
|
|
float x2;
|
|
float x3;
|
|
float x4;
|
|
float ps;
|
|
//
|
|
Note() {
|
|
id = 0;
|
|
pitch = 0;
|
|
velocity = 0;
|
|
onoff = 0;
|
|
x1 = 0;
|
|
x2 = 0;
|
|
x3 = 0;
|
|
x4 = 0;
|
|
ps = 0;
|
|
}
|
|
Note(int32_t id_, float pitch_, float velocity_, float onoff_, float x1_, float x2_, float x3_, float x4_, float ps_)
|
|
{
|
|
id = id_;
|
|
pitch = pitch_;
|
|
velocity = velocity_;
|
|
onoff = onoff_;
|
|
x1 = x1_;
|
|
x2 = x2_;
|
|
x3 = x3_;
|
|
x4 = x4_;
|
|
ps = ps_;
|
|
}
|
|
//
|
|
void clear() {
|
|
id = 0;
|
|
pitch = 0;
|
|
velocity = 0;
|
|
onoff = 0;
|
|
x1 = 0;
|
|
x2 = 0;
|
|
x3 = 0;
|
|
x4 = 0;
|
|
ps = 0;
|
|
}
|
|
//
|
|
String to_string() {
|
|
String str = "";
|
|
str += "( id=" + String(id);
|
|
str += ", pitch=" + String(pitch);
|
|
str += ", velocity=" + String(velocity);
|
|
str += ", onoff=" + String(onoff);
|
|
str += ", x1=" + String(x1);
|
|
str += ", x2=" + String(x2);
|
|
str += ", x3=" + String(x3);
|
|
str += ", x4=" + String(x4);
|
|
str += ", ps=" + String(ps);
|
|
str += " )";
|
|
return str;
|
|
}
|
|
};
|
|
|
|
//message type Hello : '{' + Hello + '}'
|
|
#define SIGNATURE_LENGTH (20)
|
|
#define SIGNATURE_BUFF_LEN (SIGNATURE_LENGTH + 1)
|
|
struct Hello {
|
|
char sign[SIGNATURE_BUFF_LEN];
|
|
int32_t id;
|
|
uint32_t mac32;
|
|
float h1;
|
|
float h2;
|
|
float h3;
|
|
float h4;
|
|
//
|
|
Hello(String sign_, int32_t id_ = 0, uint32_t mac32_ = 0, float h1_ = 0, float h2_ = 0, float h3_ = 0, float h4_ = 0) {
|
|
id = id_;
|
|
mac32 = mac32_;
|
|
h1 = h1_;
|
|
h2 = h2_;
|
|
h3 = h3_;
|
|
h4 = h4_;
|
|
sign_.toCharArray(sign, SIGNATURE_BUFF_LEN);
|
|
}
|
|
void clear() {
|
|
id = 0;
|
|
mac32 = 0;
|
|
h1 = 0;
|
|
h2 = 0;
|
|
h3 = 0;
|
|
h4 = 0;
|
|
sign[0] = '\0';
|
|
}
|
|
//
|
|
String to_string() {
|
|
String str = "";
|
|
str += "( id=" + String(id);
|
|
str += ", mac32=0x" + String(mac32, HEX);
|
|
str += ", sign=\"" + String(sign) + "\"";
|
|
str += ", h1=" + String(h1);
|
|
str += ", h2=" + String(h2);
|
|
str += ", h3=" + String(h3);
|
|
str += ", h4=" + String(h4);
|
|
str += " )";
|
|
return str;
|
|
}
|
|
};
|