id & gid applied/arranged for all.

This commit is contained in:
Dooho Yi 2021-02-22 19:41:46 +09:00
parent 37e5ad8562
commit 899948a71a
8 changed files with 314 additions and 233 deletions

View file

@ -126,7 +126,7 @@ void hello() {
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 < 20) hello_delay = 20; if (hello_delay < 100) hello_delay = 100;
hello_task.restartDelayed(hello_delay); hello_task.restartDelayed(hello_delay);
} }
} }

View file

@ -16,7 +16,7 @@ lib_ignore = Audio, SD
lib_deps = lib_deps =
721 ; TaskScheduler 721 ; TaskScheduler
SPI SPI
; 322@1.0.7 ; SdFat 322@1.0.7 ; SdFat
[env:teensy35] [env:teensy35]
platform = teensy@3.6.0 platform = teensy@3.6.0

View file

@ -16,7 +16,17 @@
// always broadcasting. everyone is 'talkative'. // always broadcasting. everyone is 'talkative'.
// //
//==========<configurations>=========== // then, let it save a value in EEPROM (object with memory=mind?)
//============<identities>============
//
#define MY_GROUP_ID (3000)
#define MY_ID (MY_GROUP_ID + 1)
#define MY_SIGN ("CRICKET")
//
//============</identities>============
//==========<list-of-configurations>===========
// //
// 'HAVE_CLIENT' // 'HAVE_CLIENT'
// --> i have a client. enable the client task. // --> i have a client. enable the client task.
@ -28,24 +38,12 @@
// 'DISABLE_AP' // 'DISABLE_AP'
// --> (questioning)... // --> (questioning)...
// //
//==========</configurations>========== // 'HAVE_CLIENT_I2C'
// --> i have a client w/ I2C i/f. enable the I2C client task.
//==========<preset>===========
// //
// (1) standalone //==========</list-of-configurations>==========
#if 1
// (2) osc client (the ROOT)
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
// //
#endif // (EMPTY)
//
//==========</preset>==========
//============<identity key>============
#define ID_KEY 126
//============</identity key>===========
//============<parameters>============ //============<parameters>============
// //
@ -117,10 +115,18 @@ extern Task hello_task;
static int hello_delay = 0; static int hello_delay = 0;
void hello() { void hello() {
// //
Hello hello = { byte mac[6];
ID_KEY, WiFi.macAddress(mac);
speed 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 = speed;
// hello.h3 = 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];
@ -128,17 +134,17 @@ void hello() {
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); // just broadcast. 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/BROADCAST)==> "); 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); 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;
@ -171,8 +177,9 @@ Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start
// on 'Note' // on 'Note'
void onNoteHandler(Note & n) { void onNoteHandler(Note & n) {
//is it for me? //is it for me?
if (n.pitch == ID_KEY) { if (n.id == MY_GROUP_ID || n.id == MY_ID) {
// //
if (n.pitch == 1) {
speed = n.velocity; speed = n.velocity;
// if (speed < 0) speed = 0; // if (speed < 0) speed = 0;
// //
@ -181,6 +188,7 @@ void onNoteHandler(Note & n) {
} else if (n.onoff == 0) { } else if (n.onoff == 0) {
rest_task.restartDelayed(10); rest_task.restartDelayed(10);
} }
}
// //
} }
} }
@ -188,16 +196,37 @@ void onNoteHandler(Note & n) {
// on 'receive' // on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) { void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
//
//MONITORING_SERIAL.write(incomingData, len);
//
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.write(incomingData, len); // we share it w/ the client. Serial.write(incomingData, len); // we pass it over to the client.
#endif #endif
// on 'Note' // open => identify => use.
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) { 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; Note note;
memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note)); memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note));
onNoteHandler(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()); MONITORING_SERIAL.println(note.to_string());
} }
} }
@ -222,14 +251,8 @@ void setup() {
Serial.println(); Serial.println();
Serial.println("\"hi, i m your postman.\""); Serial.println("\"hi, i m your postman.\"");
Serial.println("-"); Serial.println("-");
Serial.println("- * info >>>"); Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
#if defined(ID_KEY) Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
Serial.println("- identity (key): " + String(ID_KEY));
#endif
Serial.println("- mac address: " + WiFi.macAddress());
Serial.println("- wifi channel: " + String(WIFI_CHANNEL));
Serial.println("-");
Serial.println("- * conf >>>");
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.println("- ======== 'HAVE_CLIENT' ========"); Serial.println("- ======== 'HAVE_CLIENT' ========");
#endif #endif
@ -238,10 +261,11 @@ void setup() {
#endif #endif
#if defined(DISABLE_AP) #if defined(DISABLE_AP)
Serial.println("- ======== 'DISABLE_AP' ========"); Serial.println("- ======== 'DISABLE_AP' ========");
#endif
#if defined(HAVE_CLIENT_I2C)
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
#endif #endif
Serial.println("-"); Serial.println("-");
Serial.println("\".-.-.-. :)\"");
Serial.println();
//wifi //wifi
WiFiMode_t node_type = WIFI_AP_STA; WiFiMode_t node_type = WIFI_AP_STA;
@ -260,8 +284,7 @@ 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("-"); Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
Serial.println("- we will broadcast everything. ==> add only the '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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
@ -290,8 +313,6 @@ void setup() {
//tasks //tasks
runner.addTask(set_speed_task); runner.addTask(set_speed_task);
runner.addTask(rest_task); runner.addTask(rest_task);
runner.addTask(hello_task);
rest_task.restartDelayed(500); rest_task.restartDelayed(500);
} }

View file

@ -16,7 +16,17 @@
// always broadcasting. everyone is 'talkative'. // always broadcasting. everyone is 'talkative'.
// //
//==========<configurations>=========== // then, let it save a value in EEPROM (object with memory=mind?)
//============<identities>============
//
#define MY_GROUP_ID (4000)
#define MY_ID (MY_GROUP_ID + 1)
#define MY_SIGN ("GONGGONG")
//
//============</identities>============
//==========<list-of-configurations>===========
// //
// 'HAVE_CLIENT' // 'HAVE_CLIENT'
// --> i have a client. enable the client task. // --> i have a client. enable the client task.
@ -28,25 +38,12 @@
// 'DISABLE_AP' // 'DISABLE_AP'
// --> (questioning)... // --> (questioning)...
// //
//==========</configurations>========== // 'HAVE_CLIENT_I2C'
// --> i have a client w/ I2C i/f. enable the I2C client task.
//==========<preset>===========
// //
// (1) standalone //==========</list-of-configurations>==========
#if 1
// (2) osc client (the ROOT)
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
// (3) sampler client
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
#define DISABLE_AP
// //
#endif // (EMPTY)
//
//==========</preset>==========
//============<gonggong>============ //============<gonggong>============
#define GONG_SIDE_KEY 1000 // X1 = start angle, X2 = hit angle #define GONG_SIDE_KEY 1000 // X1 = start angle, X2 = hit angle
@ -54,10 +51,6 @@
#define GONG_HEAD_KEY 1002 // random (HEAD) #define GONG_HEAD_KEY 1002 // random (HEAD)
//============</gonggong>=========== //============</gonggong>===========
//============<identity key>============
#define ID_KEY GONG_SIDE_KEY
//============</identity key>===========
//============<parameters>============ //============<parameters>============
// //
#define LED_PERIOD (11111) #define LED_PERIOD (11111)
@ -217,9 +210,18 @@ extern Task hello_task;
static int hello_delay = 0; static int hello_delay = 0;
void hello() { void hello() {
// //
Hello hello = { byte mac[6];
ID_KEY 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 = 0;
// hello.h3 = 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];
@ -227,17 +229,17 @@ void hello() {
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); // just broadcast. 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/BROADCAST)==> "); 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); 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;
@ -270,6 +272,7 @@ Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start
// on 'Note' // on 'Note'
void onNoteHandler(Note & n) { void onNoteHandler(Note & n) {
// //
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
if (n.pitch == GONG_SIDE_KEY && n.onoff == 1) { if (n.pitch == GONG_SIDE_KEY && n.onoff == 1) {
side_start_angle = n.x1; side_start_angle = n.x1;
side_hit_angle = n.x2; side_hit_angle = n.x2;
@ -294,27 +297,46 @@ void onNoteHandler(Note & n) {
if (side_set_angle > 180) side_set_angle = 180; if (side_set_angle > 180) side_set_angle = 180;
// //
ring_side_move_task.restartDelayed(10); ring_side_move_task.restartDelayed(10);
}
// //
} }
}
}
// on 'receive' // on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) { void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
//
//MONITORING_SERIAL.write(incomingData, len);
// //
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.write(incomingData, len); // we share it w/ the client. Serial.write(incomingData, len); // we pass it over to the client.
#endif #endif
// on 'Note' // 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)) { if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
Note note; Note note;
memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note)); memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note));
//
MONITORING_SERIAL.println(note.to_string());
//
onNoteHandler(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());
} }
} }
@ -338,14 +360,8 @@ void setup() {
Serial.println(); Serial.println();
Serial.println("\"hi, i m your postman.\""); Serial.println("\"hi, i m your postman.\"");
Serial.println("-"); Serial.println("-");
Serial.println("- * info >>>"); Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
#if defined(ID_KEY) Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
Serial.println("- identity (key): " + String(ID_KEY));
#endif
Serial.println("- mac address: " + WiFi.macAddress());
Serial.println("- wifi channel: " + String(WIFI_CHANNEL));
Serial.println("-");
Serial.println("- * conf >>>");
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.println("- ======== 'HAVE_CLIENT' ========"); Serial.println("- ======== 'HAVE_CLIENT' ========");
#endif #endif
@ -354,10 +370,11 @@ void setup() {
#endif #endif
#if defined(DISABLE_AP) #if defined(DISABLE_AP)
Serial.println("- ======== 'DISABLE_AP' ========"); Serial.println("- ======== 'DISABLE_AP' ========");
#endif
#if defined(HAVE_CLIENT_I2C)
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
#endif #endif
Serial.println("-"); Serial.println("-");
Serial.println("\".-.-.-. :)\"");
Serial.println();
//wifi //wifi
WiFiMode_t node_type = WIFI_AP_STA; WiFiMode_t node_type = WIFI_AP_STA;
@ -376,8 +393,7 @@ 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("-"); Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
Serial.println("- we will broadcast everything. ==> add only the '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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
@ -404,7 +420,6 @@ void setup() {
randomSeed(analogRead(0)); randomSeed(analogRead(0));
//tasks //tasks
runner.addTask(hello_task);
runner.addTask(ring_side_task); runner.addTask(ring_side_task);
runner.addTask(ring_side_move_task); runner.addTask(ring_side_move_task);
runner.addTask(side_release_task); runner.addTask(side_release_task);

View file

@ -104,7 +104,9 @@ void hello() {
// //
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
// hello.h1 = 0; static int count = 0;
count++;
hello.h1 = (count % 1000);
// hello.h2 = 0; // hello.h2 = 0;
// hello.h3 = 0; // hello.h3 = 0;
// hello.h4 = 0; // hello.h4 = 0;
@ -220,11 +222,28 @@ void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
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.
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. // 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 *) &note, incomingData + 1, sizeof(Note)); memcpy((uint8_t *) &note, incomingData + 1, sizeof(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()); MONITORING_SERIAL.println(note.to_string());
//-*-*-*-*-*-*-*-*-*- //-*-*-*-*-*-*-*-*-*-

View file

@ -884,7 +884,7 @@
#X connect 369 0 82 0; #X connect 369 0 82 0;
#X connect 370 0 165 0; #X connect 370 0 165 0;
#X restore 57 368 pd crickets nanokontrol2; #X restore 57 368 pd crickets nanokontrol2;
#N canvas 133 398 1214 393 roundly 1; #N canvas 133 398 1214 393 roundly 0;
#X msg 354 139 \$1 5000; #X msg 354 139 \$1 5000;
#X obj 354 162 unpack f f; #X obj 354 162 unpack f f;
#X obj 354 185 s X1; #X obj 354 185 s X1;
@ -1071,7 +1071,7 @@
#X obj 79 64 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1 #X obj 79 64 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 1
; ;
#X obj 408 177 s OSC; #X obj 408 177 s OSC;
#N canvas 713 396 706 244 SAMPLER_NOTE-to-OSC 1; #N canvas 627 525 706 244 SAMPLER_NOTE-to-OSC 0;
#X obj 35 142 spigot; #X obj 35 142 spigot;
#X obj 84 127 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0 #X obj 84 127 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1; 1;

View file

@ -16,7 +16,17 @@
// always broadcasting. everyone is 'talkative'. // always broadcasting. everyone is 'talkative'.
// //
//==========<configurations>=========== // then, let it save a value in EEPROM (object with memory=mind?)
//============<identities>============
//
#define MY_GROUP_ID (20000)
#define MY_ID (MY_GROUP_ID + 1)
#define MY_SIGN ("ROUNDLY")
//
//============</identities>============
//==========<list-of-configurations>===========
// //
// 'HAVE_CLIENT' // 'HAVE_CLIENT'
// --> i have a client. enable the client task. // --> i have a client. enable the client task.
@ -28,24 +38,12 @@
// 'DISABLE_AP' // 'DISABLE_AP'
// --> (questioning)... // --> (questioning)...
// //
//==========</configurations>========== // 'HAVE_CLIENT_I2C'
// --> i have a client w/ I2C i/f. enable the I2C client task.
//==========<preset>===========
// //
// (1) standalone //==========</list-of-configurations>==========
#if 1
// (2) osc client (the ROOT)
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
// //
#endif // (EMPTY)
//
//==========</preset>==========
//============<identity key>============
#define ID_KEY 2000
//============</identity key>===========
//============<parameters>============ //============<parameters>============
// //
@ -166,11 +164,18 @@ extern Task hello_task;
static int hello_delay = 0; static int hello_delay = 0;
void hello() { void hello() {
// //
Hello hello = { byte mac[6];
ID_KEY, WiFi.macAddress(mac);
stepper.currentPosition(), uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
stepper.distanceToGo() //
}; 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 = stepper.currentPosition();
hello.h3 = stepper.distanceToGo();
// 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];
@ -178,17 +183,17 @@ void hello() {
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); // just broadcast. 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/BROADCAST)==> "); 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); 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;
@ -221,17 +226,12 @@ Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start
// on 'Note' // on 'Note'
void onNoteHandler(Note & n) { void onNoteHandler(Note & n) {
//is it for me? //is it for me?
if (n.pitch == ID_KEY) { if (n.id == MY_GROUP_ID || n.id == MY_ID) {
// //
step_target = n.x1; step_target = n.x1;
step_duration = n.x2; step_duration = n.x2;
if (step_duration < 1000) step_duration = 1000; if (step_duration < 1000) step_duration = 1000;
// //
hello_delay = n.ps;
if (hello_delay > 0 && hello_task.isEnabled() == false) {
hello_task.restart();
}
//
if (n.onoff == 1) { if (n.onoff == 1) {
stepping_task.restartDelayed(10); stepping_task.restartDelayed(10);
} else if (n.onoff == 0) { } else if (n.onoff == 0) {
@ -244,16 +244,37 @@ void onNoteHandler(Note & n) {
// on 'receive' // on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) { void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
//
//MONITORING_SERIAL.write(incomingData, len);
//
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.write(incomingData, len); // we share it w/ the client. Serial.write(incomingData, len); // we pass it over to the client.
#endif #endif
// on 'Note' // open => identify => use.
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) { 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; Note note;
memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note)); memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note));
onNoteHandler(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()); MONITORING_SERIAL.println(note.to_string());
} }
} }
@ -278,14 +299,8 @@ void setup() {
Serial.println(); Serial.println();
Serial.println("\"hi, i m your postman.\""); Serial.println("\"hi, i m your postman.\"");
Serial.println("-"); Serial.println("-");
Serial.println("- * info >>>"); Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
#if defined(ID_KEY) Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
Serial.println("- identity (key): " + String(ID_KEY));
#endif
Serial.println("- mac address: " + WiFi.macAddress());
Serial.println("- wifi channel: " + String(WIFI_CHANNEL));
Serial.println("-");
Serial.println("- * conf >>>");
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.println("- ======== 'HAVE_CLIENT' ========"); Serial.println("- ======== 'HAVE_CLIENT' ========");
#endif #endif
@ -294,10 +309,11 @@ void setup() {
#endif #endif
#if defined(DISABLE_AP) #if defined(DISABLE_AP)
Serial.println("- ======== 'DISABLE_AP' ========"); Serial.println("- ======== 'DISABLE_AP' ========");
#endif
#if defined(HAVE_CLIENT_I2C)
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
#endif #endif
Serial.println("-"); Serial.println("-");
Serial.println("\".-.-.-. :)\"");
Serial.println();
//wifi //wifi
WiFiMode_t node_type = WIFI_AP_STA; WiFiMode_t node_type = WIFI_AP_STA;
@ -316,8 +332,7 @@ 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("-"); Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
Serial.println("- we will broadcast everything. ==> add only the '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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
@ -353,10 +368,8 @@ void setup() {
#endif #endif
//tasks //tasks
runner.addTask(hello_task);
runner.addTask(stepping_task); runner.addTask(stepping_task);
runner.addTask(rest_task); runner.addTask(rest_task);
rest_task.restartDelayed(500); rest_task.restartDelayed(500);
} }

View file

@ -16,7 +16,17 @@
// always broadcasting. everyone is 'talkative'. // always broadcasting. everyone is 'talkative'.
// //
//==========<configurations>=========== // then, let it save a value in EEPROM (object with memory=mind?)
//============<identities>============
//
#define MY_GROUP_ID (1000)
#define MY_ID (MY_GROUP_ID + 1)
#define MY_SIGN ("TAAK")
//
//============</identities>============
//==========<list-of-configurations>===========
// //
// 'HAVE_CLIENT' // 'HAVE_CLIENT'
// --> i have a client. enable the client task. // --> i have a client. enable the client task.
@ -28,29 +38,12 @@
// 'DISABLE_AP' // 'DISABLE_AP'
// --> (questioning)... // --> (questioning)...
// //
//==========</configurations>========== // 'HAVE_CLIENT_I2C'
// --> i have a client w/ I2C i/f. enable the I2C client task.
//==========<preset>===========
// //
// (1) standalone //==========</list-of-configurations>==========
#if 1
// (2) osc client (the ROOT)
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
// (3) sampler client
#elif 0
#define SERIAL_SWAP
#define HAVE_CLIENT
#define DISABLE_AP
// //
#endif // (EMPTY)
//
//==========</preset>==========
//============<identity key>============
#define ID_KEY 151
//============</identity key>===========
//============<parameters>============ //============<parameters>============
// //
@ -116,9 +109,18 @@ extern Task hello_task;
static int hello_delay = 0; static int hello_delay = 0;
void hello() { void hello() {
// //
Hello hello = { byte mac[6];
ID_KEY 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 = 0;
// hello.h3 = 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];
@ -126,17 +128,17 @@ void hello() {
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); // just broadcast. 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/BROADCAST)==> "); 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); 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;
@ -169,7 +171,7 @@ Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start
// on 'Note' // on 'Note'
void onNoteHandler(Note & n) { void onNoteHandler(Note & n) {
//is it for me? //is it for me?
if (n.pitch == ID_KEY) { if (n.id == MY_GROUP_ID || n.id == MY_ID) {
// //
if (n.velocity < 0) n.velocity = 0; if (n.velocity < 0) n.velocity = 0;
//taak_on && taak_off //taak_on && taak_off
@ -191,20 +193,38 @@ void onNoteHandler(Note & n) {
// on 'receive' // on 'receive'
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) { void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
//
//MONITORING_SERIAL.write(incomingData, len);
// //
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.write(incomingData, len); // we share it w/ the client. Serial.write(incomingData, len); // we pass it over to the client.
#endif #endif
// on 'Note' // 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)) { if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
Note note; Note note;
memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note)); memcpy((uint8_t *) &note, incomingData + 1, sizeof(Note));
//
MONITORING_SERIAL.println(note.to_string());
//
onNoteHandler(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());
} }
} }
@ -228,14 +248,8 @@ void setup() {
Serial.println(); Serial.println();
Serial.println("\"hi, i m your postman.\""); Serial.println("\"hi, i m your postman.\"");
Serial.println("-"); Serial.println("-");
Serial.println("- * info >>>"); Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
#if defined(ID_KEY) Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
Serial.println("- identity (key): " + String(ID_KEY));
#endif
Serial.println("- mac address: " + WiFi.macAddress());
Serial.println("- wifi channel: " + String(WIFI_CHANNEL));
Serial.println("-");
Serial.println("- * conf >>>");
#if defined(HAVE_CLIENT) #if defined(HAVE_CLIENT)
Serial.println("- ======== 'HAVE_CLIENT' ========"); Serial.println("- ======== 'HAVE_CLIENT' ========");
#endif #endif
@ -244,10 +258,11 @@ void setup() {
#endif #endif
#if defined(DISABLE_AP) #if defined(DISABLE_AP)
Serial.println("- ======== 'DISABLE_AP' ========"); Serial.println("- ======== 'DISABLE_AP' ========");
#endif
#if defined(HAVE_CLIENT_I2C)
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
#endif #endif
Serial.println("-"); Serial.println("-");
Serial.println("\".-.-.-. :)\"");
Serial.println();
//wifi //wifi
WiFiMode_t node_type = WIFI_AP_STA; WiFiMode_t node_type = WIFI_AP_STA;
@ -266,8 +281,7 @@ 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("-"); Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
Serial.println("- we will broadcast everything. ==> add only the '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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
@ -294,7 +308,6 @@ void setup() {
pinMode(D6, OUTPUT); pinMode(D6, OUTPUT);
//tasks //tasks
runner.addTask(hello_task);
runner.addTask(taak_on_task); runner.addTask(taak_on_task);
runner.addTask(taak_off_task); runner.addTask(taak_off_task);
} }