|
@@ -3,8 +3,18 @@
|
|
#include <SPI.h>
|
|
#include <SPI.h>
|
|
#include <SD.h>
|
|
#include <SD.h>
|
|
#include <SerialFlash.h>
|
|
#include <SerialFlash.h>
|
|
|
|
+#include <Metro.h>
|
|
|
|
|
|
|
|
+/* ESP commands
|
|
|
|
+ * AT+MODE=1
|
|
|
|
+ * AT+CWLAP lists wifi AP
|
|
|
|
+ * AT+CWJAP="IM_AP","raspberry" connect to IM ap
|
|
|
|
+ * AT+CIFSR get IP
|
|
|
|
+ * AT+CIPSTART="UDP","192.168.3.1",8000 connect to **
|
|
|
|
+ *
|
|
|
|
+ */
|
|
|
|
|
|
|
|
+
|
|
/* SdWav1 : sample voix |
|
|
/* SdWav1 : sample voix |
|
|
* SdWav2 : sample attente |-> mix1 -> Lout & RMS1
|
|
* SdWav2 : sample attente |-> mix1 -> Lout & RMS1
|
|
*
|
|
*
|
|
@@ -23,17 +33,23 @@ AudioConnection patchCord1(LoopPlayer, 0, mixer2, 0);
|
|
AudioConnection patchCord2(PresencePlayer, 0, mixer1, 0);
|
|
AudioConnection patchCord2(PresencePlayer, 0, mixer1, 0);
|
|
AudioConnection patchCord3(WaitPlayer, 0, mixer1, 1);
|
|
AudioConnection patchCord3(WaitPlayer, 0, mixer1, 1);
|
|
AudioConnection patchCord4(mixer1, 0, i2s1, 0);
|
|
AudioConnection patchCord4(mixer1, 0, i2s1, 0);
|
|
-AudioConnection patchCord5(mixer1, rms1);
|
|
|
|
|
|
+AudioConnection patchCord5(PresencePlayer, rms1);
|
|
AudioConnection patchCord6(mixer2, 0, i2s1, 1);
|
|
AudioConnection patchCord6(mixer2, 0, i2s1, 1);
|
|
AudioConnection patchCord7(mixer2, rms2);
|
|
AudioConnection patchCord7(mixer2, rms2);
|
|
AudioControlSGTL5000 sgtl5000_1; //xy=573,537
|
|
AudioControlSGTL5000 sgtl5000_1; //xy=573,537
|
|
// GUItool: end automatically generated code
|
|
// GUItool: end automatically generated code
|
|
|
|
|
|
|
|
+bool UDPalive ;
|
|
|
|
+
|
|
|
|
+Metro checkUDP = Metro(1000);
|
|
|
|
+Metro checkESPserial = Metro(50);
|
|
|
|
+Metro sendRMS = Metro(50);
|
|
|
|
+
|
|
#define LOOP_WAV "LOOP.WAV"
|
|
#define LOOP_WAV "LOOP.WAV"
|
|
#define PRESENCE_WAV "PRESENCE.WAV"
|
|
#define PRESENCE_WAV "PRESENCE.WAV"
|
|
-#define WAIT_WAV "PRESENCE.WAV"
|
|
|
|
|
|
+#define WAIT_WAV "WAIT.WAV"
|
|
|
|
|
|
-int WAIT_TIME=30000 ;
|
|
|
|
|
|
+int WAIT_TIME=10000 ;
|
|
|
|
|
|
bool presence ;
|
|
bool presence ;
|
|
uint32_t LastPresence ;
|
|
uint32_t LastPresence ;
|
|
@@ -47,7 +63,10 @@ void ESPSerial(){
|
|
// Send bytes from ESP8266 -> Teensy to Computer
|
|
// Send bytes from ESP8266 -> Teensy to Computer
|
|
bool printLine ;
|
|
bool printLine ;
|
|
while ( Serial1.available() ) {
|
|
while ( Serial1.available() ) {
|
|
|
|
+ //String buf = Serial1.read();
|
|
|
|
+ //Serial.write(F(buf));
|
|
Serial.write( Serial1.read() );
|
|
Serial.write( Serial1.read() );
|
|
|
|
+ // if(buf.readStringUntil("\n")=="OK") {Serial.println("trouvé");}
|
|
printLine = 1 ;
|
|
printLine = 1 ;
|
|
}
|
|
}
|
|
// if (printLine) {Serial.println("");}
|
|
// if (printLine) {Serial.println("");}
|
|
@@ -58,6 +77,10 @@ void ESPSerial(){
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+/////////////////////////////// SETUP /////////////////////////
|
|
|
|
+
|
|
|
|
+
|
|
void setup() {
|
|
void setup() {
|
|
|
|
|
|
Serial.begin(115200);
|
|
Serial.begin(115200);
|
|
@@ -80,18 +103,31 @@ void setup() {
|
|
delay(500);
|
|
delay(500);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ LoopPlayer.play(LOOP_WAV);
|
|
|
|
+ // A brief delay for the library read WAV info
|
|
|
|
+ delay(10);
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //ESP8266
|
|
Serial1.println("AT+GMR");
|
|
Serial1.println("AT+GMR");
|
|
- delay(2000);
|
|
|
|
//while (!Serial1.available()) {};
|
|
//while (!Serial1.available()) {};
|
|
- ESPSerial();
|
|
|
|
|
|
+ delay(200);
|
|
|
|
+ ESPSerial();
|
|
Serial.println("");
|
|
Serial.println("");
|
|
Serial.println("");
|
|
Serial.println("");
|
|
- delay(00);
|
|
|
|
-
|
|
|
|
|
|
+ while(millis()<10000){}
|
|
|
|
|
|
|
|
+ Serial1.println("AT+CIFSR");
|
|
|
|
+ ESPSerial();
|
|
|
|
+ delay(200);
|
|
|
|
+ Serial.println ("");
|
|
|
|
+ Serial1.println("AT+CIPSTART=\"UDP\",\"192.168.3.1\",8002");
|
|
|
|
+ ESPSerial();
|
|
}
|
|
}
|
|
-//
|
|
|
|
|
|
+
|
|
|
|
+///////////////////////////////////////////////////////////////////
|
|
|
|
+
|
|
|
|
+
|
|
void playFile(const char *filename)
|
|
void playFile(const char *filename)
|
|
{
|
|
{
|
|
Serial.print("Playing file: ");
|
|
Serial.print("Playing file: ");
|
|
@@ -114,10 +150,43 @@ void printLDR(){
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
bool checkPresence(int Pin1, int Pin2) {
|
|
bool checkPresence(int Pin1, int Pin2) {
|
|
- bool isPresent = digitalRead(Pin2); //|| digitalRead(Pin2);
|
|
|
|
|
|
+ bool isPresent = analogRead(A7)>1010;
|
|
|
|
+ //digitalRead(Pin2); //|| digitalRead(Pin2);
|
|
|
|
+ Serial.println(isPresent);
|
|
return isPresent ;
|
|
return isPresent ;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+bool checkUDPconnected() {
|
|
|
|
+ Serial1.println("AT+CIPSTATUS");
|
|
|
|
+ delay(50);
|
|
|
|
+ while ( Serial1.available() ) {
|
|
|
|
+ String buf = Serial1.readStringUntil('\n'); //StringUntil('\n') ;
|
|
|
|
+ if(buf.startsWith("STATUS:2")){
|
|
|
|
+ Serial.println("connected");
|
|
|
|
+ return true ;
|
|
|
|
+ }
|
|
|
|
+ else return false;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+void sendUDP() {
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if(rms1.available() ) { //&& UDPalive
|
|
|
|
+ Serial1.println("AT+CIPSEND=3");
|
|
|
|
+ delay(20);
|
|
|
|
+ Serial1.write(byte(rms1.read()*255));
|
|
|
|
+ Serial1.println("");
|
|
|
|
+ //Serial.println("udp");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+/////////////////////////////// LOOP ////////////////////////////////////
|
|
|
|
+
|
|
void loop() {
|
|
void loop() {
|
|
|
|
|
|
// LOOP FILE
|
|
// LOOP FILE
|
|
@@ -161,6 +230,9 @@ void loop() {
|
|
|
|
|
|
if (PresencePlayer.isPlaying()) {
|
|
if (PresencePlayer.isPlaying()) {
|
|
//what if presence gone while playing ?
|
|
//what if presence gone while playing ?
|
|
|
|
+ while(rms1.read() > 0) { }
|
|
|
|
+ PresencePlayer.stop();
|
|
|
|
+
|
|
}
|
|
}
|
|
if ( (millis() - LastPresence > WAIT_TIME) && !WaitPlayer.isPlaying() && !PresencePlayer.isPlaying()) {
|
|
if ( (millis() - LastPresence > WAIT_TIME) && !WaitPlayer.isPlaying() && !PresencePlayer.isPlaying()) {
|
|
WaitPlayer.play(WAIT_WAV);
|
|
WaitPlayer.play(WAIT_WAV);
|
|
@@ -169,7 +241,17 @@ void loop() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- ESPSerial();
|
|
|
|
- delay(100);
|
|
|
|
|
|
+// if (checkUDP.check() ==1) {
|
|
|
|
+// UDPalive = checkUDPconnected();
|
|
|
|
+// }
|
|
|
|
+// if (checkESPserial.check() == 1) {
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
+// ESPSerial();
|
|
|
|
+//
|
|
|
|
+// if (sendRMS.check() == 1) {
|
|
|
|
+// sendUDP();
|
|
|
|
+// }
|
|
|
|
+//
|
|
}
|
|
}
|
|
|
|
|