Compare commits
No commits in common. "fe4b1f120b2e8075bb5d6dbfc43558af783722f8" and "dcf62905a2ec811b914904af4a03eb0a4e96bb12" have entirely different histories.
fe4b1f120b
...
dcf62905a2
4 changed files with 590 additions and 975 deletions
|
|
@ -16,7 +16,7 @@
|
||||||
//============<identities>============
|
//============<identities>============
|
||||||
//
|
//
|
||||||
#define MY_GROUP_ID (10000)
|
#define MY_GROUP_ID (10000)
|
||||||
#define MY_ID (MY_GROUP_ID + 2)
|
#define MY_ID (MY_GROUP_ID + 7)
|
||||||
#define MY_SIGN ("AUDIOOOO")
|
#define MY_SIGN ("AUDIOOOO")
|
||||||
#define ADDRESSBOOK_TITLE ("broadcast only")
|
#define ADDRESSBOOK_TITLE ("broadcast only")
|
||||||
//
|
//
|
||||||
|
|
@ -135,44 +135,44 @@ String screen_filename = "/___.mp3";
|
||||||
extern Task screen_cmd_notify_task;
|
extern Task screen_cmd_notify_task;
|
||||||
bool cmd_notify = false;
|
bool cmd_notify = false;
|
||||||
void screen_cmd_notify() {
|
void screen_cmd_notify() {
|
||||||
if (screen_cmd_notify_task.isFirstIteration()) cmd_notify = true;
|
if (screen_cmd_notify_task.isFirstIteration()) cmd_notify = true;
|
||||||
else if (screen_cmd_notify_task.isLastIteration()) cmd_notify = false;
|
else if (screen_cmd_notify_task.isLastIteration()) cmd_notify = false;
|
||||||
else cmd_notify = !cmd_notify;
|
else cmd_notify = !cmd_notify;
|
||||||
}
|
}
|
||||||
Task screen_cmd_notify_task(500, 10, &screen_cmd_notify, &runner, false);
|
Task screen_cmd_notify_task(500, 10, &screen_cmd_notify, &runner, false);
|
||||||
|
|
||||||
//
|
//
|
||||||
extern Task screen_task;
|
extern Task screen_task;
|
||||||
void screen() {
|
void screen() {
|
||||||
//clear screen + a
|
//clear screen + a
|
||||||
int line_step = 12;
|
int line_step = 12;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
|
|
||||||
//line1 - mode line (playing / stopped) + notify mark
|
//line1 - mode line (playing / stopped) + notify mark
|
||||||
display.setCursor(0, line);
|
display.setCursor(0, line);
|
||||||
if (audio.isRunning()) display.println("= playing ===");
|
if (audio.isRunning()) display.println("= playing ===");
|
||||||
else display.println("* stopped !:.");
|
else display.println("* stopped !:.");
|
||||||
if (cmd_notify) {
|
if (cmd_notify) {
|
||||||
display.setCursor(120, line);
|
display.setCursor(120, line);
|
||||||
display.println("*");
|
display.println("*");
|
||||||
}
|
}
|
||||||
line += line_step;
|
line += line_step;
|
||||||
|
|
||||||
//line2 - filename
|
//line2 - filename
|
||||||
display.setCursor(0, line);
|
display.setCursor(0, line);
|
||||||
display.println(screen_filename.c_str());
|
display.println(screen_filename.c_str());
|
||||||
line += line_step;
|
line += line_step;
|
||||||
|
|
||||||
//line3 - rf. last msg.
|
//line3 - rf. last msg.
|
||||||
display.setCursor(0, line);
|
display.setCursor(0, line);
|
||||||
display.println(screen_cmd.c_str());
|
display.println(screen_cmd.c_str());
|
||||||
line += line_step;
|
line += line_step;
|
||||||
//
|
//
|
||||||
display.display();
|
display.display();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
Task screen_task(SCREEN_PERIOD, TASK_FOREVER, &screen, &runner, true);
|
Task screen_task(SCREEN_PERIOD, TASK_FOREVER, &screen, &runner, true);
|
||||||
|
|
||||||
|
|
@ -182,104 +182,93 @@ int sample_now = 0; //0~999
|
||||||
//on 'start'
|
//on 'start'
|
||||||
void sample_player_start()
|
void sample_player_start()
|
||||||
{
|
{
|
||||||
//filename buffer - 8.3 naming convension! 8+1+3+1 = 13
|
//filename buffer - 8.3 naming convension! 8+1+3+1 = 13
|
||||||
// + '/' root symbol 13+1 = 14 (ESP32 specific?)
|
// + '/' root symbol 13+1 = 14 (ESP32 specific?)
|
||||||
char filename[14] = "/NNN.mp3";
|
char filename[14] = "/NNN.mp3";
|
||||||
//search for the sound file
|
//search for the sound file
|
||||||
int note = sample_now;
|
int note = sample_now;
|
||||||
int nnn = (note % 1000); // 0~999
|
int nnn = (note % 1000); // 0~999
|
||||||
int nn = (note % 100); // 0~99
|
int nn = (note % 100); // 0~99
|
||||||
filename[1] = '0' + (nnn / 100); // N__.MP3
|
filename[1] = '0' + (nnn / 100); // N__.MP3
|
||||||
filename[2] = '0' + (nn / 10); // _N_.MP3
|
filename[2] = '0' + (nn / 10); // _N_.MP3
|
||||||
filename[3] = '0' + (nn % 10); // __N.MP3
|
filename[3] = '0' + (nn % 10); // __N.MP3
|
||||||
//TEST
|
//TEST
|
||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
screen_filename = String(filename);
|
screen_filename = String(filename);
|
||||||
bool test = SD.exists(filename);
|
bool test = SD.exists(filename);
|
||||||
if (!test) {
|
if (!test) {
|
||||||
Serial.println("... does not exist.");
|
Serial.println("... does not exist.");
|
||||||
screen_filename = screen_filename + "_!NEXIST!";
|
screen_filename = screen_filename + "_!NEXIST!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//start the player!
|
//start the player!
|
||||||
audio.connecttoSD(filename);
|
audio.connecttoSD(filename);
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
Task sample_player_start_task(0, TASK_ONCE, &sample_player_start, &runner, false);
|
Task sample_player_start_task(0, TASK_ONCE, &sample_player_start, &runner, false);
|
||||||
|
|
||||||
//on 'stop'
|
//on 'stop'
|
||||||
void sample_player_stop() {
|
void sample_player_stop() {
|
||||||
//filename buffer - 8.3 naming convension! 8+1+3+1 = 13
|
//filename buffer - 8.3 naming convension! 8+1+3+1 = 13
|
||||||
// + '/' root symbol 13+1 = 14 (ESP32 specific?)
|
// + '/' root symbol 13+1 = 14 (ESP32 specific?)
|
||||||
char filename[14] = "/NNN.mp3";
|
char filename[14] = "/NNN.mp3";
|
||||||
//search for the sound file
|
//search for the sound file
|
||||||
int note = sample_now;
|
int note = sample_now;
|
||||||
int nnn = (note % 1000); // 0~999
|
int nnn = (note % 1000); // 0~999
|
||||||
int nn = (note % 100); // 0~99
|
int nn = (note % 100); // 0~99
|
||||||
filename[1] = '0' + (nnn / 100); // N__.MP3
|
filename[1] = '0' + (nnn / 100); // N__.MP3
|
||||||
filename[2] = '0' + (nn / 10); // _N_.MP3
|
filename[2] = '0' + (nn / 10); // _N_.MP3
|
||||||
filename[3] = '0' + (nn % 10); // __N.MP3
|
filename[3] = '0' + (nn % 10); // __N.MP3
|
||||||
//TEST
|
//TEST
|
||||||
Serial.println(filename);
|
Serial.println(filename);
|
||||||
screen_filename = String(filename);
|
screen_filename = String(filename);
|
||||||
bool test = SD.exists(filename);
|
bool test = SD.exists(filename);
|
||||||
if (!test) {
|
if (!test) {
|
||||||
Serial.println("... does not exist.");
|
Serial.println("... does not exist.");
|
||||||
screen_filename = screen_filename + "_!NEXIST!";
|
screen_filename = screen_filename + "_!NEXIST!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//stop the player.
|
//stop the player.
|
||||||
audio.stopSong();
|
audio.stopSong();
|
||||||
}
|
}
|
||||||
Task sample_player_stop_task(0, TASK_ONCE, &sample_player_stop, &runner, false);
|
Task sample_player_stop_task(0, TASK_ONCE, &sample_player_stop, &runner, false);
|
||||||
|
|
||||||
//looping
|
|
||||||
void looping()
|
|
||||||
{
|
|
||||||
if (!audio.isRunning()) {
|
|
||||||
//keep sample_now as it is.
|
|
||||||
sample_player_start_task.restartDelayed(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task looping_task(5000, TASK_FOREVER, &looping, &runner, false);
|
|
||||||
// Task looping_task(5000, TASK_FOREVER, &looping, &runner, true); // < with looping task .. audio will always keep playing. (non stop.)
|
|
||||||
|
|
||||||
//
|
//
|
||||||
#if defined(REPLICATE_NOTE_REQ)
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
Note note_now = {
|
Note note_now = {
|
||||||
-1, // int32_t id;
|
-1, // int32_t id;
|
||||||
-1, // float pitch;
|
-1, // float pitch;
|
||||||
-1, // float velocity;
|
-1, // float velocity;
|
||||||
-1, // float onoff;
|
-1, // float onoff;
|
||||||
-1, // float x1;
|
-1, // float x1;
|
||||||
-1, // float x2;
|
-1, // float x2;
|
||||||
-1, // float x3;
|
-1, // float x3;
|
||||||
-1, // float x4;
|
-1, // float x4;
|
||||||
-1 // float ps;
|
-1 // float ps;
|
||||||
};
|
};
|
||||||
#define NEW_NOTE_TIMEOUT (3000)
|
#define NEW_NOTE_TIMEOUT (3000)
|
||||||
static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT);
|
static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT);
|
||||||
void repeat() {
|
void repeat() {
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Note) + 2;
|
uint8_t frm_size = sizeof(Note) + 2;
|
||||||
uint8_t frm[frm_size];
|
uint8_t frm[frm_size];
|
||||||
frm[0] = '[';
|
frm[0] = '[';
|
||||||
memcpy(frm + 1, (uint8_t *) ¬e_now, sizeof(Note));
|
memcpy(frm + 1, (uint8_t *) ¬e_now, sizeof(Note));
|
||||||
frm[frm_size - 1] = ']';
|
frm[frm_size - 1] = ']';
|
||||||
//
|
//
|
||||||
// strange but following didn't work as expected. (instead, i have to send one-by-one.)
|
// strange but following didn't work as expected. (instead, i have to send one-by-one.)
|
||||||
// esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
// esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
|
|
||||||
// so, forget about peer list -> just pick a broadcast peer to be sent.
|
// so, forget about peer list -> just pick a broadcast peer to be sent.
|
||||||
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
esp_now_send(broadcastmac, frm, frm_size);
|
esp_now_send(broadcastmac, frm, frm_size);
|
||||||
|
|
||||||
// (DEBUG) fetch full peer list
|
// (DEBUG) fetch full peer list
|
||||||
{ PeerLister a; a.print(); }
|
{ PeerLister a; a.print(); }
|
||||||
|
|
||||||
//
|
//
|
||||||
MONITORING_SERIAL.print("\nrepeat! ==> ");
|
MONITORING_SERIAL.print("\nrepeat! ==> ");
|
||||||
MONITORING_SERIAL.println(note_now.to_string());
|
MONITORING_SERIAL.println(note_now.to_string());
|
||||||
}
|
}
|
||||||
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -289,304 +278,304 @@ Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
||||||
extern Task hello_task;
|
extern Task hello_task;
|
||||||
static int hello_delay = 0;
|
static int hello_delay = 0;
|
||||||
void hello() {
|
void hello() {
|
||||||
//
|
//
|
||||||
byte mac[6];
|
byte mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
||||||
//
|
//
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
||||||
// and you can append some floats
|
// and you can append some floats
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
hello.h1 = (count % 1000);
|
hello.h1 = (count % 1000);
|
||||||
hello.h2 = sample_now;
|
hello.h2 = sample_now;
|
||||||
// hello.h3 = 0;
|
// hello.h3 = 0;
|
||||||
// hello.h4 = 0;
|
// hello.h4 = 0;
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
uint8_t frm[frm_size];
|
uint8_t frm[frm_size];
|
||||||
frm[0] = '{';
|
frm[0] = '{';
|
||||||
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
||||||
frm[frm_size - 1] = '}';
|
frm[frm_size - 1] = '}';
|
||||||
//
|
//
|
||||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
//
|
//
|
||||||
// MONITORING_SERIAL.write(frm, frm_size);
|
// MONITORING_SERIAL.write(frm, frm_size);
|
||||||
// MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
// MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
||||||
//
|
//
|
||||||
if (hello_delay > 0) {
|
if (hello_delay > 0) {
|
||||||
if (hello_delay < 100) hello_delay = 100;
|
if (hello_delay < 100) hello_delay = 100;
|
||||||
hello_task.restartDelayed(hello_delay);
|
hello_task.restartDelayed(hello_delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task hello_task(0, TASK_ONCE, &hello, &runner, false);
|
Task hello_task(0, TASK_ONCE, &hello, &runner, false);
|
||||||
|
|
||||||
//task #0 : blink led
|
//task #0 : blink led
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, false); // makepython esp32 has NO led => disabled.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, false); // makepython esp32 has NO led => disabled.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
screen_cmd = n.to_string();
|
screen_cmd = n.to_string();
|
||||||
screen_cmd_notify_task.restart();
|
screen_cmd_notify_task.restart();
|
||||||
//
|
//
|
||||||
if (n.velocity != 0 || n.onoff == 2) {
|
if (n.velocity != 0 || n.onoff == 2) {
|
||||||
audio.setVolume(n.velocity * 21 / 127 * GAIN_MAX); // 0...127 ==> 0...21
|
audio.setVolume(n.velocity * 21 / 127 * GAIN_MAX); // 0...127 ==> 0...21
|
||||||
}
|
|
||||||
//
|
|
||||||
if (n.onoff == 1) {
|
|
||||||
// filter out re-triggering same note while it is playing.
|
|
||||||
if (!audio.isRunning() || sample_now != n.pitch) {
|
|
||||||
sample_now = n.pitch;
|
|
||||||
sample_player_start_task.restartDelayed(10);
|
|
||||||
}
|
|
||||||
} else if (n.onoff == 0) {
|
|
||||||
sample_now = n.pitch;
|
|
||||||
sample_player_stop_task.restartDelayed(10);
|
|
||||||
}
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
if (n.onoff == 1) {
|
||||||
|
// filter out re-triggering same note while it is playing.
|
||||||
|
if (!audio.isRunning() || sample_now != n.pitch) {
|
||||||
|
sample_now = n.pitch;
|
||||||
|
sample_player_start_task.restartDelayed(10);
|
||||||
|
}
|
||||||
|
} else if (n.onoff == 0) {
|
||||||
|
sample_now = n.pitch;
|
||||||
|
sample_player_stop_task.restartDelayed(10);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len) {
|
void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len) {
|
||||||
|
|
||||||
//
|
//
|
||||||
// MONITORING_SERIAL.write(incomingData, len);
|
// MONITORING_SERIAL.write(incomingData, len);
|
||||||
|
|
||||||
//
|
//
|
||||||
#if defined(HAVE_CLIENT)
|
#if defined(HAVE_CLIENT)
|
||||||
Serial.write(incomingData, len); // we pass it over to the client.
|
Serial.write(incomingData, len); // we pass it over to the client.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Hello hello("");
|
Hello hello("");
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
//
|
//
|
||||||
MONITORING_SERIAL.println(hello.to_string());
|
MONITORING_SERIAL.println(hello.to_string());
|
||||||
//
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
|
||||||
|
//is it for me?
|
||||||
|
if (note.id == MY_GROUP_ID || note.id == MY_ID) {
|
||||||
|
hello_delay = note.ps;
|
||||||
|
if (hello_delay > 0 && hello_task.isEnabled() == false) {
|
||||||
|
hello_task.restart();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// open => identify => use.
|
MONITORING_SERIAL.println(note.to_string());
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
|
||||||
Note note;
|
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
|
||||||
onNoteHandler(note);
|
|
||||||
|
|
||||||
//is it for me?
|
|
||||||
if (note.id == MY_GROUP_ID || note.id == MY_ID) {
|
|
||||||
hello_delay = note.ps;
|
|
||||||
if (hello_delay > 0 && hello_task.isEnabled() == false) {
|
|
||||||
hello_task.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MONITORING_SERIAL.println(note.to_string());
|
|
||||||
|
|
||||||
#if defined(REPLICATE_NOTE_REQ)
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
if (millis() - new_note_time > NEW_NOTE_TIMEOUT) {
|
if (millis() - new_note_time > NEW_NOTE_TIMEOUT) {
|
||||||
note_now = note;
|
note_now = note;
|
||||||
repeat_task.restart();
|
repeat_task.restart();
|
||||||
new_note_time = millis();
|
new_note_time = millis();
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t sendStatus) {
|
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t sendStatus) {
|
||||||
// well, i think this cb should be called once for EVERY single TX attempts,
|
// well, i think this cb should be called once for EVERY single TX attempts,
|
||||||
// but in reality, it doesn't get called that often.
|
// but in reality, it doesn't get called that often.
|
||||||
// i think this is sorta bug. but have no clear clue.
|
// i think this is sorta bug. but have no clear clue.
|
||||||
MONITORING_SERIAL.printf("* delivery attempt! ~~~>>> %02X:%02X:%02X:%02X:%02X:%02X\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
MONITORING_SERIAL.printf("* delivery attempt! ~~~>>> %02X:%02X:%02X:%02X:%02X:%02X\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||||
if (sendStatus != 0) MONITORING_SERIAL.printf("* ==>> FAILED :(\n\n");
|
if (sendStatus != 0) MONITORING_SERIAL.printf("* ==>> FAILED :(\n\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
// SD TEST
|
// SD TEST
|
||||||
void printDirectory(File dir, int numTabs) {
|
void printDirectory(File dir, int numTabs) {
|
||||||
// char filename[256] = "";
|
// char filename[256] = "";
|
||||||
while(true) {
|
while(true) {
|
||||||
File entry = dir.openNextFile();
|
File entry = dir.openNextFile();
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
// no more files
|
// no more files
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
for (uint8_t i=0; i<numTabs; i++) {
|
|
||||||
Serial.print('\t');
|
|
||||||
}
|
|
||||||
// entry.getName(filename, 256);
|
|
||||||
// Serial.print(filename);
|
|
||||||
Serial.print(entry.name());
|
|
||||||
if (entry.isDirectory()) {
|
|
||||||
Serial.println("/");
|
|
||||||
//non-recursive listing...
|
|
||||||
// printDirectory(entry, numTabs+1);
|
|
||||||
} else {
|
|
||||||
// files have sizes, directories do not
|
|
||||||
Serial.print("\t\t");
|
|
||||||
Serial.println(entry.size(), DEC);
|
|
||||||
}
|
|
||||||
entry.close();
|
|
||||||
}
|
}
|
||||||
|
for (uint8_t i=0; i<numTabs; i++) {
|
||||||
|
Serial.print('\t');
|
||||||
|
}
|
||||||
|
// entry.getName(filename, 256);
|
||||||
|
// Serial.print(filename);
|
||||||
|
Serial.print(entry.name());
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
Serial.println("/");
|
||||||
|
//non-recursive listing...
|
||||||
|
// printDirectory(entry, numTabs+1);
|
||||||
|
} else {
|
||||||
|
// files have sizes, directories do not
|
||||||
|
Serial.print("\t\t");
|
||||||
|
Serial.println(entry.size(), DEC);
|
||||||
|
}
|
||||||
|
entry.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_text(String str) {
|
void lcd_text(String str) {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println(str.c_str());
|
display.println(str.c_str());
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
File root;
|
File root;
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//screen
|
//screen
|
||||||
Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
|
Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
|
||||||
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
for (;;)
|
for (;;)
|
||||||
; // Don't proceed, loop forever
|
; // Don't proceed, loop forever
|
||||||
}
|
}
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
||||||
//SD(SPI)
|
//SD(SPI)
|
||||||
pinMode(SD_CS, OUTPUT);
|
pinMode(SD_CS, OUTPUT);
|
||||||
digitalWrite(SD_CS, HIGH);
|
digitalWrite(SD_CS, HIGH);
|
||||||
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
SPI.begin(SPI_SCK, SPI_MISO, SPI_MOSI);
|
||||||
SPI.setFrequency(1000000);
|
SPI.setFrequency(1000000);
|
||||||
if (!SD.begin(SD_CS, SPI)) {
|
if (!SD.begin(SD_CS, SPI)) {
|
||||||
Serial.println("Card Mount Failed");
|
Serial.println("Card Mount Failed");
|
||||||
lcd_text("SD ERR!\nCard Mount Failed!");
|
lcd_text("SD ERR!\nCard Mount Failed!");
|
||||||
while (1)
|
while (1)
|
||||||
;
|
;
|
||||||
} else {
|
} else {
|
||||||
// lcd_text("SD OK");
|
// lcd_text("SD OK");
|
||||||
}
|
}
|
||||||
root = SD.open("/");
|
root = SD.open("/");
|
||||||
printDirectory(root, 0);
|
printDirectory(root, 0);
|
||||||
|
|
||||||
//audio(I2S)
|
//audio(I2S)
|
||||||
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
|
||||||
// audio.setVolume(21); // 0...21
|
// audio.setVolume(21); // 0...21
|
||||||
audio.setVolume(14.88); // 90 * 21 / 127 == 14.88
|
audio.setVolume(14.88); // 90 * 21 / 127 == 14.88
|
||||||
|
|
||||||
// audio.connecttoFS(SD, filename.c_str());
|
// audio.connecttoFS(SD, filename.c_str());
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("- my peer book ==> \"" + String(ADDRESSBOOK_TITLE) + "\"");
|
Serial.println("- my peer book ==> \"" + String(ADDRESSBOOK_TITLE) + "\"");
|
||||||
#if defined(HAVE_CLIENT)
|
#if defined(HAVE_CLIENT)
|
||||||
Serial.println("- ======== 'HAVE_CLIENT' ========");
|
Serial.println("- ======== 'HAVE_CLIENT' ========");
|
||||||
#endif
|
#endif
|
||||||
#if defined(SERIAL_SWAP)
|
#if defined(SERIAL_SWAP)
|
||||||
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
||||||
#endif
|
#endif
|
||||||
#if defined(DISABLE_AP)
|
#if defined(DISABLE_AP)
|
||||||
Serial.println("- ======== 'DISABLE_AP' ========");
|
Serial.println("- ======== 'DISABLE_AP' ========");
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_CLIENT_I2C)
|
#if defined(HAVE_CLIENT_I2C)
|
||||||
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
||||||
#endif
|
#endif
|
||||||
#if defined(REPLICATE_NOTE_REQ)
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
Serial.println("- ======== 'REPLICATE_NOTE_REQ' ========");
|
Serial.println("- ======== 'REPLICATE_NOTE_REQ' ========");
|
||||||
#endif
|
#endif
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi
|
//wifi
|
||||||
WiFiMode_t node_type = WIFI_AP_STA;
|
WiFiMode_t node_type = WIFI_AP_STA;
|
||||||
#if defined(DISABLE_AP)
|
#if defined(DISABLE_AP)
|
||||||
// system_phy_set_max_tpw(0);
|
// system_phy_set_max_tpw(0);
|
||||||
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); // Set WiFi RF power output to lowest level
|
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); // Set WiFi RF power output to lowest level
|
||||||
node_type = WIFI_STA;
|
node_type = WIFI_STA;
|
||||||
#endif
|
#endif
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_register_send_cb(onDataSent);
|
esp_now_register_send_cb(onDataSent);
|
||||||
esp_now_register_recv_cb(onDataReceive);
|
esp_now_register_recv_cb(onDataReceive);
|
||||||
//
|
//
|
||||||
// Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
// Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
||||||
// uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
// uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
//
|
//
|
||||||
// //
|
// //
|
||||||
// esp_now_peer_info_t peerInfo = {};
|
// esp_now_peer_info_t peerInfo = {};
|
||||||
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
|
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
|
||||||
// peerInfo.channel = 0;
|
// peerInfo.channel = 0;
|
||||||
// peerInfo.encrypt = false;
|
// peerInfo.encrypt = false;
|
||||||
// esp_now_add_peer(&peerInfo);
|
// esp_now_add_peer(&peerInfo);
|
||||||
|
|
||||||
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
||||||
if (book == NULL) {
|
if (book == NULL) {
|
||||||
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
||||||
}
|
}
|
||||||
for (int idx = 0; idx < book->list.size(); idx++) {
|
for (int idx = 0; idx < book->list.size(); idx++) {
|
||||||
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
||||||
esp_now_peer_info_t peerInfo = {};
|
esp_now_peer_info_t peerInfo = {};
|
||||||
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
||||||
peerInfo.channel = 0;
|
peerInfo.channel = 0;
|
||||||
peerInfo.encrypt = false;
|
peerInfo.encrypt = false;
|
||||||
esp_now_add_peer(&peerInfo);
|
esp_now_add_peer(&peerInfo);
|
||||||
}
|
}
|
||||||
// (DEBUG) fetch full peer list
|
// (DEBUG) fetch full peer list
|
||||||
{ PeerLister a; a.print(); }
|
{ PeerLister a; a.print(); }
|
||||||
//
|
//
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
audio.loop();
|
audio.loop();
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
; < NOTE >
|
|
||||||
|
|
||||||
; to enable verbose output add option -->
|
|
||||||
; $ platformio run --verbose
|
|
||||||
|
|
||||||
; to make this permanent for the proj. -->
|
|
||||||
; $ platformio settings set force_verbose Yes
|
|
||||||
|
|
||||||
; then confirm the change -->
|
|
||||||
; $ platformio settings get
|
|
||||||
|
|
||||||
|
|
||||||
; // pio v 4.0 'Build options'
|
|
||||||
; - build_type
|
|
||||||
; - build_flags
|
|
||||||
; - src_build_flags
|
|
||||||
; - build_unflags
|
|
||||||
; - src_filter
|
|
||||||
; - targets
|
|
||||||
|
|
||||||
|
|
||||||
[platformio]
|
|
||||||
default_envs = nodemcuv2
|
|
||||||
|
|
||||||
[env]
|
|
||||||
framework = arduino
|
|
||||||
upload_port = /dev/ttyUSB0
|
|
||||||
lib_deps =
|
|
||||||
721 ; TaskScheduler
|
|
||||||
|
|
||||||
[env:nodemcuv2]
|
|
||||||
platform = espressif8266
|
|
||||||
board = nodemcuv2
|
|
||||||
lib_deps =
|
|
||||||
${env.lib_deps}
|
|
||||||
upload_speed = 921600 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
|
||||||
|
|
||||||
[env:d1_mini_pro]
|
|
||||||
platform = espressif8266
|
|
||||||
board = d1_mini_pro
|
|
||||||
lib_deps =
|
|
||||||
${env.lib_deps}
|
|
||||||
upload_speed = 460800 ; 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
|
|
||||||
|
|
@ -1,326 +0,0 @@
|
||||||
//
|
|
||||||
// wirelessly connected cloud (based on ESP-NOW, a kind of LPWAN?)
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Conversation about the ROOT @ SEMA storage, Seoul
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// 2021 02 15
|
|
||||||
//
|
|
||||||
// this module will be an esp-now node in a group.
|
|
||||||
// like, a bird in a group of birds.
|
|
||||||
//
|
|
||||||
// esp-now @ esp8266 w/ broadcast address (FF:FF:FF:FF:FF:FF)
|
|
||||||
// always broadcasting. everyone is 'talkative'.
|
|
||||||
//
|
|
||||||
|
|
||||||
// then, let it save a value in EEPROM (object with memory=mind?)
|
|
||||||
|
|
||||||
//============<identities>============
|
|
||||||
//
|
|
||||||
#define MY_GROUP_ID (9000)
|
|
||||||
#define MY_ID (MY_GROUP_ID + 5)
|
|
||||||
#define MY_SIGN ("BUZZ")
|
|
||||||
//
|
|
||||||
//============</identities>============
|
|
||||||
|
|
||||||
//==========<list-of-configurations>===========
|
|
||||||
//
|
|
||||||
// 'HAVE_CLIENT'
|
|
||||||
// --> i have a client. enable the client task.
|
|
||||||
//
|
|
||||||
// 'SERIAL_SWAP'
|
|
||||||
// --> UART pin swapped.
|
|
||||||
// you want this, when you want a bi-directional comm. to external client boards (e.g. teensy).
|
|
||||||
//
|
|
||||||
// 'DISABLE_AP'
|
|
||||||
// --> (questioning)...
|
|
||||||
//
|
|
||||||
// 'HAVE_CLIENT_I2C'
|
|
||||||
// --> i have a client w/ I2C i/f. enable the I2C client task.
|
|
||||||
//
|
|
||||||
//==========</list-of-configurations>==========
|
|
||||||
//
|
|
||||||
// (EMPTY)
|
|
||||||
|
|
||||||
//============<parameters>============
|
|
||||||
//
|
|
||||||
#define LED_PERIOD (11111)
|
|
||||||
#define LED_ONTIME (1)
|
|
||||||
#define LED_GAPTIME (222)
|
|
||||||
//
|
|
||||||
#define WIFI_CHANNEL 1
|
|
||||||
//
|
|
||||||
// 'MONITORING_SERIAL'
|
|
||||||
//
|
|
||||||
// --> sometimes, the 'Serial' is in use (for example, 'osc' node)
|
|
||||||
// then, use 'Serial1' - D4/GPIO2/TDX1 @ nodemcu (this is TX only.)
|
|
||||||
//
|
|
||||||
// --> otherwise, MONITORING_SERIAL == Serial.
|
|
||||||
//
|
|
||||||
#if defined(SERIAL_SWAP)
|
|
||||||
#define MONITORING_SERIAL (Serial1)
|
|
||||||
#else
|
|
||||||
#define MONITORING_SERIAL (Serial)
|
|
||||||
#endif
|
|
||||||
//
|
|
||||||
//============</parameters>===========
|
|
||||||
|
|
||||||
//============<board-specifics>============
|
|
||||||
#if defined(ARDUINO_FEATHER_ESP32) // featheresp32
|
|
||||||
#define LED_PIN 13
|
|
||||||
#else
|
|
||||||
#define LED_PIN 2
|
|
||||||
#endif
|
|
||||||
//============</board-specifics>===========
|
|
||||||
|
|
||||||
//arduino
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
//post & addresses
|
|
||||||
#include "../../post.h"
|
|
||||||
|
|
||||||
//espnow
|
|
||||||
#include <ESP8266WiFi.h>
|
|
||||||
#include <espnow.h>
|
|
||||||
|
|
||||||
//task
|
|
||||||
#include <TaskScheduler.h>
|
|
||||||
Scheduler runner;
|
|
||||||
|
|
||||||
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
|
||||||
// buzzer
|
|
||||||
// my tasks
|
|
||||||
int tonepin = D6;
|
|
||||||
int tonefreq = 0;
|
|
||||||
void set_tone() {
|
|
||||||
tone(tonepin, tonefreq);
|
|
||||||
MONITORING_SERIAL.print("set_tone:");
|
|
||||||
MONITORING_SERIAL.println(tonefreq);
|
|
||||||
}
|
|
||||||
Task set_tone_task(0, TASK_ONCE, &set_tone, &runner, false);
|
|
||||||
//
|
|
||||||
uint8_t watch_counter = 0;
|
|
||||||
void watcher() {
|
|
||||||
if (watch_counter > 3) {
|
|
||||||
tonefreq = 0;
|
|
||||||
set_tone_task.restartDelayed(10);
|
|
||||||
watch_counter = 0;
|
|
||||||
} else {
|
|
||||||
watch_counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task watcher_task(1000, TASK_FOREVER, &watcher, &runner, true);
|
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
|
||||||
|
|
||||||
//
|
|
||||||
extern Task hello_task;
|
|
||||||
static int hello_delay = 2000;
|
|
||||||
void hello() {
|
|
||||||
//
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
|
||||||
//
|
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
|
||||||
// and you can append some floats
|
|
||||||
static int count = 0;
|
|
||||||
count++;
|
|
||||||
hello.h1 = (count % 1000);
|
|
||||||
hello.h2 = tonefreq;
|
|
||||||
// hello.h3 = 0;
|
|
||||||
// hello.h4 = 0;
|
|
||||||
//
|
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
|
||||||
uint8_t frm[frm_size];
|
|
||||||
frm[0] = '{';
|
|
||||||
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
|
||||||
frm[frm_size - 1] = '}';
|
|
||||||
//
|
|
||||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
|
||||||
//
|
|
||||||
MONITORING_SERIAL.write(frm, frm_size);
|
|
||||||
MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
|
||||||
//
|
|
||||||
if (hello_delay > 0) {
|
|
||||||
if (hello_delay < 100) hello_delay = 100;
|
|
||||||
hello_task.restartDelayed(hello_delay);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task hello_task(0, TASK_ONCE, &hello, &runner, false);
|
|
||||||
|
|
||||||
//task #0 : blink led
|
|
||||||
extern Task blink_task;
|
|
||||||
void blink() {
|
|
||||||
//
|
|
||||||
static int count = 0;
|
|
||||||
count++;
|
|
||||||
//
|
|
||||||
switch (count % 4) {
|
|
||||||
case 0:
|
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
|
||||||
blink_task.delay(LED_ONTIME);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
|
||||||
blink_task.delay(LED_GAPTIME);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
|
||||||
blink_task.delay(LED_ONTIME);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
|
||||||
|
|
||||||
// on 'Note'
|
|
||||||
void onNoteHandler(Note & n) {
|
|
||||||
//is it for me?
|
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
|
||||||
//
|
|
||||||
tonepin = n.pitch;
|
|
||||||
if (tonepin == 0) tonepin = D6;
|
|
||||||
//
|
|
||||||
tonefreq = n.velocity;
|
|
||||||
//
|
|
||||||
set_tone_task.restartDelayed(10);
|
|
||||||
watch_counter = 0;
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// on 'receive'
|
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
|
||||||
|
|
||||||
//
|
|
||||||
//MONITORING_SERIAL.write(incomingData, len);
|
|
||||||
|
|
||||||
//
|
|
||||||
#if defined(HAVE_CLIENT)
|
|
||||||
Serial.write(incomingData, len); // we pass it over to the client.
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
|
||||||
MONITORING_SERIAL.println(hello.to_string());
|
|
||||||
//
|
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
|
||||||
Note note;
|
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
|
||||||
onNoteHandler(note);
|
|
||||||
|
|
||||||
//is it for me?
|
|
||||||
if (note.id == MY_GROUP_ID || note.id == MY_ID) {
|
|
||||||
hello_delay = note.ps;
|
|
||||||
if (hello_delay > 0 && hello_task.isEnabled() == false) {
|
|
||||||
hello_task.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
MONITORING_SERIAL.println(note.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// on 'sent'
|
|
||||||
void onDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
|
||||||
if (sendStatus != 0) MONITORING_SERIAL.println("Delivery failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
//led
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
|
|
||||||
//
|
|
||||||
// tone(D6, 1000, 1000);
|
|
||||||
|
|
||||||
//pwm freq.
|
|
||||||
analogWriteFreq(40000);
|
|
||||||
|
|
||||||
//serial
|
|
||||||
Serial.begin(115200);
|
|
||||||
delay(100);
|
|
||||||
|
|
||||||
//info
|
|
||||||
Serial.println();
|
|
||||||
Serial.println();
|
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
|
||||||
Serial.println("-");
|
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
|
||||||
#if defined(HAVE_CLIENT)
|
|
||||||
Serial.println("- ======== 'HAVE_CLIENT' ========");
|
|
||||||
#endif
|
|
||||||
#if defined(SERIAL_SWAP)
|
|
||||||
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
|
||||||
#endif
|
|
||||||
#if defined(DISABLE_AP)
|
|
||||||
Serial.println("- ======== 'DISABLE_AP' ========");
|
|
||||||
#endif
|
|
||||||
#if defined(HAVE_CLIENT_I2C)
|
|
||||||
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
|
||||||
#endif
|
|
||||||
Serial.println("-");
|
|
||||||
|
|
||||||
//wifi
|
|
||||||
WiFiMode_t node_type = WIFI_AP_STA;
|
|
||||||
#if defined(DISABLE_AP)
|
|
||||||
system_phy_set_max_tpw(0);
|
|
||||||
node_type = WIFI_STA;
|
|
||||||
#endif
|
|
||||||
WiFi.mode(node_type);
|
|
||||||
|
|
||||||
//esp-now
|
|
||||||
if (esp_now_init() != 0) {
|
|
||||||
Serial.println("Error initializing ESP-NOW");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
|
||||||
esp_now_register_send_cb(onDataSent);
|
|
||||||
esp_now_register_recv_cb(onDataReceive);
|
|
||||||
//
|
|
||||||
Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
|
||||||
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
||||||
esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
|
||||||
|
|
||||||
//
|
|
||||||
Serial.println("-");
|
|
||||||
Serial.println("\".-.-.-. :)\"");
|
|
||||||
Serial.println();
|
|
||||||
|
|
||||||
#if defined(SERIAL_SWAP)
|
|
||||||
Serial.println("- ======== 'SERIAL_SWAP' ========");
|
|
||||||
// a proper say goodbye.
|
|
||||||
Serial.println("\"bye, i will do 'swap' in 1 second. find me on alternative pins!\"");
|
|
||||||
Serial.println("\" hint: osc wiring ==> esp8266(serial.swap) <-> teensy(serial3)\"");
|
|
||||||
Serial.println("-");
|
|
||||||
Serial.println("\".-.-.-. :)\"");
|
|
||||||
delay(1000); // flush out unsent serial messages.
|
|
||||||
|
|
||||||
// moving...
|
|
||||||
Serial.swap(); // use RXD2/TXD2 pins, afterwards.
|
|
||||||
delay(100); // wait re-initialization of the 'Serial'
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//random seed
|
|
||||||
randomSeed(analogRead(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
//
|
|
||||||
runner.execute();
|
|
||||||
//
|
|
||||||
}
|
|
||||||
523
p/src/main.cpp
523
p/src/main.cpp
|
|
@ -90,10 +90,8 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||||
// q list
|
// q list
|
||||||
std::vector<Note> qlist;
|
std::vector<Note> qlist;
|
||||||
void init_qlist() {
|
void init_qlist() {
|
||||||
qlist.push_back(Note(1444, 12, 0, 1, 0, 0, 0, 0, 0));
|
qlist.push_back(Note(10000, 1, 0, 1, 0, 0, 0, 0, 0));
|
||||||
qlist.push_back(Note(1444, 12, 0, 0, 0, 0, 0, 0, 0));
|
qlist.push_back(Note(10000, 1, 0, 0, 0, 0, 0, 0, 0));
|
||||||
qlist.push_back(Note(1444, 14, 0, 1, 0, 0, 0, 0, 0));
|
|
||||||
qlist.push_back(Note(1444, 14, 0, 0, 0, 0, 0, 0, 0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
|
|
@ -111,9 +109,9 @@ String screen_cmd = ":Q: ----- --- --- -";
|
||||||
extern Task screen_req_notify_task;
|
extern Task screen_req_notify_task;
|
||||||
bool req_notify = false;
|
bool req_notify = false;
|
||||||
void screen_req_notify() {
|
void screen_req_notify() {
|
||||||
if (screen_req_notify_task.isFirstIteration()) req_notify = true;
|
if (screen_req_notify_task.isFirstIteration()) req_notify = true;
|
||||||
else if (screen_req_notify_task.isLastIteration()) req_notify = false;
|
else if (screen_req_notify_task.isLastIteration()) req_notify = false;
|
||||||
else req_notify = !req_notify;
|
else req_notify = !req_notify;
|
||||||
}
|
}
|
||||||
Task screen_req_notify_task(500, 8, &screen_req_notify, &runner, false);
|
Task screen_req_notify_task(500, 8, &screen_req_notify, &runner, false);
|
||||||
|
|
||||||
|
|
@ -121,180 +119,177 @@ Task screen_req_notify_task(500, 8, &screen_req_notify, &runner, false);
|
||||||
extern Task screen_task;
|
extern Task screen_task;
|
||||||
void screen() {
|
void screen() {
|
||||||
|
|
||||||
//
|
//
|
||||||
if (screen_task.isFirstIteration()) {
|
if (screen_task.isFirstIteration()) {
|
||||||
init_qlist();
|
init_qlist();
|
||||||
|
}
|
||||||
|
|
||||||
|
// button job!
|
||||||
|
static int btn_vol_up = 0;
|
||||||
|
static int btn_vol_down = 0;
|
||||||
|
static int btn_mute = 0;
|
||||||
|
static int btn_previous = 0;
|
||||||
|
static int btn_pause = 0;
|
||||||
|
static int btn_next = 0;
|
||||||
|
//
|
||||||
|
int a;
|
||||||
|
static int qselect = 0;
|
||||||
|
bool nowsend = false;
|
||||||
|
//
|
||||||
|
a = digitalRead(pin_vol_up);
|
||||||
|
if(btn_vol_up != a) {
|
||||||
|
btn_vol_up = a;
|
||||||
|
if(a == 0) {
|
||||||
|
// 'vol_up' button pressed.
|
||||||
|
|
||||||
|
qselect = qselect + 1;
|
||||||
|
if (qselect > (qlist.size() - 1)) qselect = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
a = digitalRead(pin_vol_down);
|
||||||
|
if(btn_vol_down != a) {
|
||||||
|
btn_vol_down = a;
|
||||||
|
if(a == 0) {
|
||||||
|
// 'vol_down' button pressed.
|
||||||
|
|
||||||
// button job!
|
qselect = qselect - 1;
|
||||||
static int btn_vol_up = 0;
|
if (qselect < 0) qselect = (qlist.size() - 1);
|
||||||
static int btn_vol_down = 0;
|
|
||||||
static int btn_mute = 0;
|
|
||||||
static int btn_previous = 0;
|
|
||||||
static int btn_pause = 0;
|
|
||||||
static int btn_next = 0;
|
|
||||||
//
|
|
||||||
int a;
|
|
||||||
static int qselect = 0;
|
|
||||||
bool nowsend = false;
|
|
||||||
//
|
|
||||||
a = digitalRead(pin_vol_up);
|
|
||||||
if(btn_vol_up != a) {
|
|
||||||
btn_vol_up = a;
|
|
||||||
if(a == 0) {
|
|
||||||
// 'vol_up' button pressed.
|
|
||||||
|
|
||||||
qselect = qselect + 1;
|
|
||||||
if (qselect > (qlist.size() - 1)) qselect = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//
|
}
|
||||||
a = digitalRead(pin_vol_down);
|
//
|
||||||
if(btn_vol_down != a) {
|
a = digitalRead(pin_mute);
|
||||||
btn_vol_down = a;
|
if(btn_mute != a) {
|
||||||
if(a == 0) {
|
btn_mute = a;
|
||||||
// 'vol_down' button pressed.
|
if(a == 0) {
|
||||||
|
// 'mute' button pressed.
|
||||||
|
|
||||||
qselect = qselect - 1;
|
nowsend = true;
|
||||||
if (qselect < 0) qselect = (qlist.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//
|
}
|
||||||
a = digitalRead(pin_mute);
|
//
|
||||||
if(btn_mute != a) {
|
a = digitalRead(pin_previous);
|
||||||
btn_mute = a;
|
if(btn_previous != a) {
|
||||||
if(a == 0) {
|
btn_previous = a;
|
||||||
// 'mute' button pressed.
|
if(a == 0) {
|
||||||
|
// 'previous' button pressed.
|
||||||
|
|
||||||
nowsend = true;
|
qselect = qselect - 1;
|
||||||
}
|
if (qselect < 0) qselect = (qlist.size() - 1);
|
||||||
}
|
}
|
||||||
//
|
}
|
||||||
a = digitalRead(pin_previous);
|
//
|
||||||
if(btn_previous != a) {
|
a = digitalRead(pin_pause);
|
||||||
btn_previous = a;
|
if(btn_pause != a) {
|
||||||
if(a == 0) {
|
btn_pause = a;
|
||||||
// 'previous' button pressed.
|
if(a == 0) {
|
||||||
|
// 'pause' button pressed.
|
||||||
|
|
||||||
qselect = qselect - 1;
|
nowsend = true;
|
||||||
if (qselect < 0) qselect = (qlist.size() - 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//
|
}
|
||||||
a = digitalRead(pin_pause);
|
//
|
||||||
if(btn_pause != a) {
|
a = digitalRead(pin_next);
|
||||||
btn_pause = a;
|
if(btn_next != a) {
|
||||||
if(a == 0) {
|
btn_next = a;
|
||||||
// 'pause' button pressed.
|
if(a == 0) {
|
||||||
|
// 'next' button pressed.
|
||||||
|
|
||||||
nowsend = true;
|
qselect = qselect + 1;
|
||||||
}
|
if (qselect > (qlist.size() - 1)) qselect = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nowsend == true) {
|
||||||
|
nowsend = false;
|
||||||
|
// create a NOTE req. and send it out.
|
||||||
//
|
//
|
||||||
a = digitalRead(pin_next);
|
MONITORING_SERIAL.print("# posting a req.# ==> ");
|
||||||
if(btn_next != a) {
|
MONITORING_SERIAL.println(qlist[qselect].to_string());
|
||||||
btn_next = a;
|
|
||||||
if(a == 0) {
|
|
||||||
// 'next' button pressed.
|
|
||||||
|
|
||||||
qselect = qselect + 1;
|
|
||||||
if (qselect > (qlist.size() - 1)) qselect = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nowsend == true) {
|
|
||||||
nowsend = false;
|
|
||||||
// create a NOTE req. and send it out.
|
|
||||||
//
|
|
||||||
MONITORING_SERIAL.print("# posting a req.# ==> ");
|
|
||||||
MONITORING_SERIAL.println(qlist[qselect].to_string());
|
|
||||||
//
|
|
||||||
uint8_t frm_size = sizeof(Note) + 2;
|
|
||||||
uint8_t frm[frm_size];
|
|
||||||
frm[0] = '[';
|
|
||||||
memcpy(frm + 1, (uint8_t *) &qlist[qselect], sizeof(Note));
|
|
||||||
frm[frm_size - 1] = ']';
|
|
||||||
//
|
|
||||||
// strange but following didn't work as expected. (instead, i have to send one-by-one.)
|
|
||||||
// esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
|
||||||
|
|
||||||
// so, forget about peer list -> just pick a broadcast peer to be sent.
|
|
||||||
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
|
||||||
esp_now_send(broadcastmac, frm, frm_size);
|
|
||||||
|
|
||||||
|
|
||||||
//+ fancy stuff
|
|
||||||
screen_req_notify_task.restart();
|
|
||||||
|
|
||||||
// //+ automatically increase 'song_request'
|
|
||||||
// qselect = qselect + 1;
|
|
||||||
// if (qselect > (qlist.size() - 1)) qselect = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//clear screen + a
|
|
||||||
int line_step = 12;
|
|
||||||
int line = 0;
|
|
||||||
display.clearDisplay();
|
|
||||||
display.setTextColor(SSD1306_WHITE);
|
|
||||||
display.setTextSize(1);
|
|
||||||
|
|
||||||
//button status (DEBUG)
|
|
||||||
// int b = digitalRead(pin_vol_up);
|
|
||||||
// b = b*10 + digitalRead(pin_vol_down);
|
|
||||||
// b = b*10 + digitalRead(pin_mute);
|
|
||||||
// b = b*10 + digitalRead(pin_previous);
|
|
||||||
// b = b*10 + digitalRead(pin_pause);
|
|
||||||
// b = b*10 + digitalRead(pin_next);
|
|
||||||
|
|
||||||
//line1 - mode line (playing / stopped) + notify mark
|
|
||||||
display.setCursor(0, line);
|
|
||||||
display.printf("= transmitting ))) ==");
|
|
||||||
line += line_step;
|
|
||||||
|
|
||||||
//line3 - msg. ready to be sent now.
|
|
||||||
display.setCursor(0, line);
|
|
||||||
display.setTextSize(2);
|
|
||||||
display.printf(":Q: %05d %03d %03d %01d", (int)qlist[qselect].id, (int)qlist[qselect].pitch, (int)qlist[qselect].velocity, (int)qlist[qselect].onoff);
|
|
||||||
line += line_step;
|
|
||||||
|
|
||||||
// //line4 - big file name display
|
|
||||||
// display.setCursor(0, line);
|
|
||||||
// display.setTextSize(2);
|
|
||||||
// //
|
|
||||||
// char filename[14] = "/NNN.mp3 >";
|
|
||||||
// int note = qlist[qselect].pitch;
|
|
||||||
// int nnn = (note % 1000); // 0~999
|
|
||||||
// int nn = (note % 100); // 0~99
|
|
||||||
// filename[1] = '0' + (nnn / 100); // N__.MP3
|
|
||||||
// filename[2] = '0' + (nn / 10); // _N_.MP3
|
|
||||||
// filename[3] = '0' + (nn % 10); // __N.MP3
|
|
||||||
// //
|
|
||||||
// if (qlist[qselect].onoff == 0) {
|
|
||||||
// filename[9] = 'x';
|
|
||||||
// }
|
|
||||||
// display.println(filename);
|
|
||||||
// line += line_step;
|
|
||||||
// display.setTextSize(1);
|
|
||||||
// line += 8;
|
|
||||||
|
|
||||||
// //alternative line3+4 - full msg. dump (DEBUG/MONITORING)
|
|
||||||
// display.setCursor(0, line);
|
|
||||||
// display.println(":Q: " + qlist[qselect].to_string());
|
|
||||||
line += line_step;
|
|
||||||
line += line_step;
|
|
||||||
|
|
||||||
//line5 - song req. tx. notify. (GEN_NOTE_REQ)
|
|
||||||
display.setCursor(0, line);
|
|
||||||
display.setTextSize(1);
|
|
||||||
if (req_notify) {
|
|
||||||
display.setCursor(25, line);
|
|
||||||
display.println("~~ d[+=+]b ~~ >>>");
|
|
||||||
}
|
|
||||||
line += line_step;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
display.display();
|
uint8_t frm_size = sizeof(Note) + 2;
|
||||||
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '[';
|
||||||
|
memcpy(frm + 1, (uint8_t *) &qlist[qselect], sizeof(Note));
|
||||||
|
frm[frm_size - 1] = ']';
|
||||||
//
|
//
|
||||||
|
// strange but following didn't work as expected. (instead, i have to send one-by-one.)
|
||||||
|
// esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
|
|
||||||
|
// so, forget about peer list -> just pick a broadcast peer to be sent.
|
||||||
|
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
|
esp_now_send(broadcastmac, frm, frm_size);
|
||||||
|
|
||||||
|
|
||||||
|
//+ fancy stuff
|
||||||
|
screen_req_notify_task.restart();
|
||||||
|
|
||||||
|
//+ automatically increase 'song_request'
|
||||||
|
qselect = qselect + 1;
|
||||||
|
if (qselect > (qlist.size() - 1)) qselect = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//clear screen + a
|
||||||
|
int line_step = 12;
|
||||||
|
int line = 0;
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setTextSize(1);
|
||||||
|
|
||||||
|
//button status (DEBUG)
|
||||||
|
// int b = digitalRead(pin_vol_up);
|
||||||
|
// b = b*10 + digitalRead(pin_vol_down);
|
||||||
|
// b = b*10 + digitalRead(pin_mute);
|
||||||
|
// b = b*10 + digitalRead(pin_previous);
|
||||||
|
// b = b*10 + digitalRead(pin_pause);
|
||||||
|
// b = b*10 + digitalRead(pin_next);
|
||||||
|
|
||||||
|
//line1 - mode line (playing / stopped) + notify mark
|
||||||
|
display.setCursor(0, line);
|
||||||
|
display.printf("= transmitting ))) ==");
|
||||||
|
line += line_step;
|
||||||
|
|
||||||
|
//line3 - msg. ready to be sent now.
|
||||||
|
display.setCursor(0, line);
|
||||||
|
display.printf(":Q: %05d %03d %03d %01d", (int)qlist[qselect].id, (int)qlist[qselect].pitch, (int)qlist[qselect].velocity, (int)qlist[qselect].onoff);
|
||||||
|
line += line_step;
|
||||||
|
|
||||||
|
//line4 - big file name display
|
||||||
|
display.setCursor(0, line);
|
||||||
|
display.setTextSize(2);
|
||||||
|
//
|
||||||
|
char filename[14] = "/NNN.mp3 >";
|
||||||
|
int note = qlist[qselect].pitch;
|
||||||
|
int nnn = (note % 1000); // 0~999
|
||||||
|
int nn = (note % 100); // 0~99
|
||||||
|
filename[1] = '0' + (nnn / 100); // N__.MP3
|
||||||
|
filename[2] = '0' + (nn / 10); // _N_.MP3
|
||||||
|
filename[3] = '0' + (nn % 10); // __N.MP3
|
||||||
|
//
|
||||||
|
if (qlist[qselect].onoff == 0) {
|
||||||
|
filename[9] = 'x';
|
||||||
|
}
|
||||||
|
display.println(filename);
|
||||||
|
line += line_step;
|
||||||
|
display.setTextSize(1);
|
||||||
|
line += 8;
|
||||||
|
|
||||||
|
// //alternative line3+4 - full msg. dump (DEBUG/MONITORING)
|
||||||
|
// display.setCursor(0, line);
|
||||||
|
// display.println(":Q: " + qlist[qselect].to_string());
|
||||||
|
// line += line_step;
|
||||||
|
|
||||||
|
//line5 - song req. tx. notify. (GEN_NOTE_REQ)
|
||||||
|
display.setCursor(0, line);
|
||||||
|
if (req_notify) {
|
||||||
|
display.setCursor(25, line);
|
||||||
|
display.println("~~ d[+=+]b ~~ >>>");
|
||||||
|
}
|
||||||
|
line += line_step;
|
||||||
|
|
||||||
|
//
|
||||||
|
display.display();
|
||||||
|
//
|
||||||
}
|
}
|
||||||
Task screen_task(SCREEN_PERIOD, TASK_FOREVER, &screen, &runner, true);
|
Task screen_task(SCREEN_PERIOD, TASK_FOREVER, &screen, &runner, true);
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
@ -302,129 +297,129 @@ Task screen_task(SCREEN_PERIOD, TASK_FOREVER, &screen, &runner, true);
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len) {
|
void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len) {
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Hello hello("");
|
Hello hello("");
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
//
|
//
|
||||||
MONITORING_SERIAL.println(hello.to_string());
|
MONITORING_SERIAL.println(hello.to_string());
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
Note note;
|
Note note;
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
//
|
//
|
||||||
MONITORING_SERIAL.println(note.to_string());
|
MONITORING_SERIAL.println(note.to_string());
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t sendStatus) {
|
void onDataSent(const uint8_t *mac_addr, esp_now_send_status_t sendStatus) {
|
||||||
if (sendStatus != 0) MONITORING_SERIAL.println("Delivery failed!");
|
if (sendStatus != 0) MONITORING_SERIAL.println("Delivery failed!");
|
||||||
}
|
}
|
||||||
|
|
||||||
void lcd_text(String str) {
|
void lcd_text(String str) {
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
display.setTextColor(SSD1306_WHITE);
|
display.setTextColor(SSD1306_WHITE);
|
||||||
display.setTextSize(1);
|
display.setTextSize(1);
|
||||||
display.setCursor(0, 0);
|
display.setCursor(0, 0);
|
||||||
display.println(str.c_str());
|
display.println(str.c_str());
|
||||||
display.display();
|
display.display();
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
pinMode(pin_vol_up, INPUT_PULLUP);
|
pinMode(pin_vol_up, INPUT_PULLUP);
|
||||||
pinMode(pin_vol_down, INPUT_PULLUP);
|
pinMode(pin_vol_down, INPUT_PULLUP);
|
||||||
pinMode(pin_mute, INPUT_PULLUP);
|
pinMode(pin_mute, INPUT_PULLUP);
|
||||||
pinMode(pin_previous, INPUT_PULLUP);
|
pinMode(pin_previous, INPUT_PULLUP);
|
||||||
pinMode(pin_pause, INPUT_PULLUP);
|
pinMode(pin_pause, INPUT_PULLUP);
|
||||||
pinMode(pin_next, INPUT_PULLUP);
|
pinMode(pin_next, INPUT_PULLUP);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//screen
|
//screen
|
||||||
Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
|
Wire.begin(MAKEPYTHON_ESP32_SDA, MAKEPYTHON_ESP32_SCL);
|
||||||
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x32
|
||||||
Serial.println(F("SSD1306 allocation failed"));
|
Serial.println(F("SSD1306 allocation failed"));
|
||||||
for (;;)
|
for (;;)
|
||||||
; // Don't proceed, loop forever
|
; // Don't proceed, loop forever
|
||||||
}
|
}
|
||||||
display.clearDisplay();
|
display.clearDisplay();
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("- my peer book ==> \"" + String(ADDRESSBOOK_TITLE) + "\"");
|
Serial.println("- my peer book ==> \"" + String(ADDRESSBOOK_TITLE) + "\"");
|
||||||
#if defined(DISABLE_AP)
|
#if defined(DISABLE_AP)
|
||||||
Serial.println("- ======== 'DISABLE_AP' ========");
|
Serial.println("- ======== 'DISABLE_AP' ========");
|
||||||
#endif
|
#endif
|
||||||
#if defined(GEN_NOTE_REQ)
|
#if defined(GEN_NOTE_REQ)
|
||||||
Serial.println("- ======== 'GEN_NOTE_REQ' ========");
|
Serial.println("- ======== 'GEN_NOTE_REQ' ========");
|
||||||
#endif
|
#endif
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi
|
//wifi
|
||||||
WiFiMode_t node_type = WIFI_AP_STA;
|
WiFiMode_t node_type = WIFI_AP_STA;
|
||||||
#if defined(DISABLE_AP)
|
#if defined(DISABLE_AP)
|
||||||
// system_phy_set_max_tpw(0);
|
// system_phy_set_max_tpw(0);
|
||||||
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); // Set WiFi RF power output to lowest level
|
WiFi.setTxPower(WIFI_POWER_MINUS_1dBm); // Set WiFi RF power output to lowest level
|
||||||
node_type = WIFI_STA;
|
node_type = WIFI_STA;
|
||||||
#endif
|
#endif
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_register_send_cb(onDataSent);
|
esp_now_register_send_cb(onDataSent);
|
||||||
esp_now_register_recv_cb(onDataReceive);
|
esp_now_register_recv_cb(onDataReceive);
|
||||||
//
|
//
|
||||||
// Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
// Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
||||||
// uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
// uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
//
|
//
|
||||||
// //
|
// //
|
||||||
// esp_now_peer_info_t peerInfo = {};
|
// esp_now_peer_info_t peerInfo = {};
|
||||||
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
|
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
|
||||||
// peerInfo.channel = 0;
|
// peerInfo.channel = 0;
|
||||||
// peerInfo.encrypt = false;
|
// peerInfo.encrypt = false;
|
||||||
// esp_now_add_peer(&peerInfo);
|
// esp_now_add_peer(&peerInfo);
|
||||||
|
|
||||||
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
||||||
if (book == NULL) {
|
if (book == NULL) {
|
||||||
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
||||||
}
|
}
|
||||||
for (int idx = 0; idx < book->list.size(); idx++) {
|
for (int idx = 0; idx < book->list.size(); idx++) {
|
||||||
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
||||||
esp_now_peer_info_t peerInfo = {};
|
esp_now_peer_info_t peerInfo = {};
|
||||||
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
||||||
peerInfo.channel = 0;
|
peerInfo.channel = 0;
|
||||||
peerInfo.encrypt = false;
|
peerInfo.encrypt = false;
|
||||||
esp_now_add_peer(&peerInfo);
|
esp_now_add_peer(&peerInfo);
|
||||||
}
|
}
|
||||||
// (DEBUG) fetch full peer list
|
// (DEBUG) fetch full peer list
|
||||||
{ PeerLister a; a.print(); }
|
{ PeerLister a; a.print(); }
|
||||||
//
|
//
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue