audioooo update. added. replication support. + address book explicited.

This commit is contained in:
Dooho Yi 2021-06-12 22:22:18 +09:00
parent ecbcbbeb50
commit 2536e090ad
4 changed files with 129 additions and 15 deletions

View file

@ -29,9 +29,16 @@
// 'DISABLE_AP' // 'DISABLE_AP'
// --> (questioning)... // --> (questioning)...
// //
// 'REPLICATE_NOTE_REQ' (+ N_SEC_BLOCKING_NOTE_REQ)
// --> for supporting wider area with simple esp_now protocol,
// all receipents will replicate NOTE msg. when they are newly appeared.
// + then, network would be flooded by infinite duplicating msg.,
// unless they stop reacting to 'known' req. for some seconds. (e.g. 3 seconds)
//
//==========</list-of-configurations>========== //==========</list-of-configurations>==========
// //
#define DISABLE_AP #define DISABLE_AP
#define REPLICATE_NOTE_REQ
//============<parameters>============ //============<parameters>============
// //
@ -77,6 +84,7 @@
//espnow //espnow
#include <esp_now.h> #include <esp_now.h>
#include <WiFi.h> #include <WiFi.h>
AddressLibrary lib;
//task //task
#include <TaskScheduler.h> #include <TaskScheduler.h>
@ -215,6 +223,37 @@ void sample_player_stop() {
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);
//
#if defined(REPLICATE_NOTE_REQ)
Note note_now = {
-1, // int32_t id;
-1, // float pitch;
-1, // float velocity;
-1, // float onoff;
-1, // float x1;
-1, // float x2;
-1, // float x3;
-1, // float x4;
-1 // float ps;
};
#define NEW_NOTE_TIMEOUT (3000)
static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT);
void repeat() {
//
uint8_t frm_size = sizeof(Note) + 2;
uint8_t frm[frm_size];
frm[0] = '[';
memcpy(frm + 1, (uint8_t *) &note_now, sizeof(Note));
frm[frm_size - 1] = ']';
//
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
//
MONITORING_SERIAL.print("repeat! ==> ");
MONITORING_SERIAL.println(note_now.to_string());
}
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
#endif
//*-*-*-*-*-*-*-*-*-*-*-*-* //*-*-*-*-*-*-*-*-*-*-*-*-*
// //
@ -250,6 +289,21 @@ void hello() {
if (hello_delay < 100) hello_delay = 100; if (hello_delay < 100) hello_delay = 100;
hello_task.restartDelayed(hello_delay); hello_task.restartDelayed(hello_delay);
} }
// //TEST
// Note n = {
// 10001, // int32_t id;
// 1, // float pitch;
// 127, // float velocity;
// 1, // float onoff;
// 0, // float x1;
// 0, // float x2;
// 0, // float x3;
// 0, // float x4;
// 5000 // float ps;
// };
// note_now = n;
// repeat_task.restart();
} }
Task hello_task(0, TASK_ONCE, &hello, &runner, false); Task hello_task(0, TASK_ONCE, &hello, &runner, false);
@ -335,6 +389,15 @@ void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int32_t len
} }
MONITORING_SERIAL.println(note.to_string()); MONITORING_SERIAL.println(note.to_string());
#if defined(REPLICATE_NOTE_REQ)
if (millis() - new_note_time > NEW_NOTE_TIMEOUT) {
note_now = note;
repeat_task.restart();
new_note_time = millis();
}
#endif
} }
} }
@ -430,6 +493,9 @@ void setup() {
#endif #endif
#if defined(HAVE_CLIENT_I2C) #if defined(HAVE_CLIENT_I2C)
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========"); Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
#endif
#if defined(REPLICATE_NOTE_REQ)
Serial.println("- ======== 'REPLICATE_NOTE_REQ' ========");
#endif #endif
Serial.println("-"); Serial.println("-");
@ -450,16 +516,25 @@ void setup() {
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;
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
// peerInfo.channel = 0;
// peerInfo.encrypt = false;
// esp_now_add_peer(&peerInfo);
AddressBook * book = lib.getBookByTitle("audioooo");
for (int idx = 0; idx < book->list.size(); idx++) {
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, broadcastmac, 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);
}
// //
Serial.println("-"); Serial.println("-");
Serial.println("\".-.-.-. :)\""); Serial.println("\".-.-.-. :)\"");

12
post.h
View file

@ -107,6 +107,18 @@ struct AddressLibrary {
// //
lib.push_back(book); lib.push_back(book);
} }
// book #4
{
AddressBook book = AddressBook("audioooo");
//
// samplers don't have ID_KEY, they will just get all messages,
// then open the content to get **midi** 'key' in the 'note' message.
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAE, 0x0C, "audioooo #1")); //WROOM
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAD, 0xB0, "audioooo #2")); //WROOM
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x78, "audioooo #3")); //WROVER
//
lib.push_back(book);
}
} }
// //
AddressBook* getBookByTitle(String title_) { AddressBook* getBookByTitle(String title_) {

27
puredata/audioooo-test.pd Normal file
View file

@ -0,0 +1,27 @@
#N canvas 678 548 450 300 12;
#X obj 73 204 s NOTE;
#X obj 73 142 pack f f;
#X floatatom 73 112 5 0 0 0 - - -;
#X obj 94 81 t b a;
#X obj 94 55 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
;
#X obj 202 50 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 232 141 r HELLO;
#X obj 232 166 print HELLO;
#X msg 202 75 5002 1 127 \$1;
#X msg 73 173 10001 \$1 127 \$2;
#X obj 220 9 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
;
#X obj 115 6 metro 5000;
#X connect 1 0 9 0;
#X connect 2 0 1 0;
#X connect 3 0 2 0;
#X connect 3 1 1 1;
#X connect 4 0 3 0;
#X connect 5 0 8 0;
#X connect 6 0 7 0;
#X connect 8 0 0 0;
#X connect 9 0 0 0;
#X connect 10 0 11 0;
#X connect 11 0 4 0;

View file

@ -1,4 +1,4 @@
#N canvas 503 95 623 400 10; #N canvas 503 89 623 400 10;
#X obj 322 198 spigot; #X obj 322 198 spigot;
#X obj 371 183 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 #X obj 371 183 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1; 1;
@ -76,18 +76,18 @@
#X obj 34 190 print HELLO; #X obj 34 190 print HELLO;
#X text 103 24 * a wireless "field synth" - based on 'esp now' protocol #X text 103 24 * a wireless "field synth" - based on 'esp now' protocol
; ;
#X msg 243 98 devicename /dev/ttyACM0 \, baud 57600 \, pollintervall
1 \, verbose 1;
#X msg 204 58 devicename /dev/tty.usbmodem4871051 \, baud 57600 \, #X msg 204 58 devicename /dev/tty.usbmodem4871051 \, baud 57600 \,
pollintervall 1 \, verbose 1; pollintervall 1 \, verbose 1;
#X msg 494 315 2000; #X msg 494 315 2000;
#X obj 230 203 tgl 15 0 empty empty connected? 17 7 0 10 -262144 -1 #X obj 230 203 tgl 15 0 empty empty connected? 17 7 0 10 -262144 -1
-1 1 1; -1 1 1;
#X msg 243 98 devicename /dev/ttyACM0 \, baud 57600 \, pollintervall
1 \, verbose 1;
#X connect 0 0 16 0; #X connect 0 0 16 0;
#X connect 1 0 0 1; #X connect 1 0 0 1;
#X connect 2 0 14 0; #X connect 2 0 14 0;
#X connect 3 0 8 0; #X connect 3 0 8 0;
#X connect 3 1 31 0; #X connect 3 1 30 0;
#X connect 4 0 3 1; #X connect 4 0 3 1;
#X connect 5 0 3 1; #X connect 5 0 3 1;
#X connect 6 0 3 0; #X connect 6 0 3 0;
@ -104,10 +104,10 @@ pollintervall 1 \, verbose 1;
#X connect 20 0 23 0; #X connect 20 0 23 0;
#X connect 21 0 22 0; #X connect 21 0 22 0;
#X connect 22 0 20 0; #X connect 22 0 20 0;
#X connect 23 0 30 0; #X connect 23 0 29 0;
#X connect 23 1 18 0; #X connect 23 1 18 0;
#X connect 24 0 26 0; #X connect 24 0 26 0;
#X connect 25 0 24 1; #X connect 25 0 24 1;
#X connect 28 0 3 1; #X connect 28 0 3 1;
#X connect 29 0 3 1; #X connect 29 0 18 0;
#X connect 30 0 18 0; #X connect 31 0 3 1;