#include "SdReader.h"
#include "FatReader.h"
#include "WaveHC.h"
#include <avr/pgmspace.h>
#include "WaveUtil.h"
SdReader card;
FatVolume vol;
FatReader root;
FatReader f;
WaveHC wave;
#define redled 9
int incomingByte = 0;
byte header[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int NOMBRE = 0; // COMPTEUR
int SIZE = 0;
int *DATA;
int val;
int REMnombre = 0;
unsigned long digit = 0;
#define redled 10
void setup() {
Serial.begin(38400); // ouverture du port serial du ZEO, regle le debit donnees à 38400 bps
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(redled, OUTPUT);
if (!card.init()) {
putstring_nl("initialisation SD : erreur !"); return;
}
if (!vol.init(card)) {
putstring_nl("Pas de partition !"); return;
}
if (!root.openRoot(vol)) {
putstring_nl("Impossible de trouver le fichier !"); return;
}
putstring_nl("Indice audio de lucidite :");
ls();
}
void loop() {
// attend les informations
if (Serial.available() > 0) {
// lecture des donnees :
incomingByte = Serial.read();
if ( incomingByte == 65 ) { holeHeader(); } // nouvelles informations arrivent
digitalWrite(redled, LOW);
}
}
void holeHeader() {
NOMBRE = 0;
while ( NOMBRE < 10 ) {
if (Serial.available() > 0) {
header[NOMBRE] = Serial.read();
NOMBRE++;
}
}
SIZE = (( header[3] * 256 ) + header[2]);
if ( SIZE > 20 ) { SIZE = 1; } // dont read long raw waveform packages
if ( header[3] + header[5] == 255 & header[2] + header[4] == 255 ) { holeDaten(SIZE); }
else { Serial.println(" CAPTEURS = AUCUNES INFORMATIONS DETECTEES ");}
}
void holeDaten(int SIZE) {
DATA = (int*)calloc(1, SIZE * sizeof(int));
NOMBRE = 0;
while ( NOMBRE < SIZE ) {
if (Serial.available() > 0) {
DATA[NOMBRE] = Serial.read();
NOMBRE++;
}
}
if ( DATA[0] == 157 ) { Serial.print("Phase de sommeil ");
if (DATA[1] == 0) { Serial.println(": INCONNUE //phase cible// "); REMnombre++; }
if (DATA[1] == 1) { Serial.println(": EVEIL"); REMnombre = 0 ; }
if (DATA[1] == 2) { Serial.println(": REM"); REMnombre = 0 ; }
if (DATA[1] == 3) { Serial.println(": LEGER"); REMnombre = 0; }
if (DATA[1] == 4) { Serial.println(": PROFOND"); REMnombre = 0; }
Serial.print("numero = "); Serial.println(REMnombre);
}
if ( REMnombre > 1 ) { playcomplete("vib.WAV"); REMnombre = 0; } // si la phase cible est superieure à 2 lectures (1 min) jouer vib WAV. repeter toutes les 1 mn jusqu au changement de phase.
free(DATA);
}
void printName(dir_t &dir)
{
for (uint8_t i = 0; i < 11; i++) {
if (dir.name[i] == ' ')continue;
if (i == 8) Serial.print('.');
Serial.print(dir.name[i]);
}
if (DIR_IS_SUBDIR(dir)) Serial.print('/');
}
void ls() {
dir_t d;
root.rewind();
while (root.readDir(d) > 0) {
printName(d);
Serial.println();
}
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying) {
digitalWrite(redled, HIGH);
delay(1000);
digitalWrite(redled, LOW);
delay(1000);
}
}
void playfile(char *name) {
if (wave.isplaying) {// deja en train de jouer quelque chose, donc stop !
wave.stop(); // stop
}
if (!f.open(root, name)) {
putstring("Impossible d ouvrir le fichier "); Serial.print(name); return;
}
if (!wave.create(f)) {
putstring_nl("WAV non valide"); return;
}
// lecture !
wave.play();
}
//LED stuff
long interval = 1000;
int ledPin = 9; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0; // will store last time LED was updated
pinMode(ledPin, OUTPUT);
void makeLEDsblink() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW){
ledState = HIGH; }
else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying) {
makeLEDsblink();
}
}
/*Projet ZEO-reves lucides
*
*Merci à EOK des forums ZEO pour son partage de code
*
*Merci à Lionel de SNOOTLAB pour son aide
*
*UTILISATION DES DONNEES TRANSMISES DEPUIS ZEO
*AFIN DE PRODUIRE DES INDICES LUMINEUX / SONORES
*A x MN DE y PHASE
*/
#include <VirtualWire.h>
#include <LiquidCrystal.h>
#include <Wire.h> //
#include <Deuligne.h> //
#include "SdReader.h"
#include "FatReader.h"
#include "WaveHC.h"
#include <avr/pgmspace.h>
#include "WaveUtil.h"
SdReader card;
FatVolume vol;
FatReader root;
FatReader f;
WaveHC wave;
//LED
long interval = 1000;
int ledPin = 9; //
int ledState = LOW; //
long previousMillis = 0; //
int incomingByte = 0;
byte header[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int NOMBRE = 0; // COMPTEUR
int SIZE = 0;
int *DATA;
int val;
int REMnombre = 0;
unsigned long digit = 0;
Deuligne lcd; //
//Key message
char msgs[5][15] = {
"MENU DROITE ",
"TEST INFO ZEO",
"Test EMETTEUR",
"MENU GAUCHE ",
"ZEO ANALYSEUR" };
int key=-1;
int oldkey=-1;
//Barre de chargement
byte smiley1[8] = {
B00011,
B00100,
B01000,
B01000,
B01000,
B01000,
B00100,
B00011,
};
byte smiley2[8] = {
B11000,
B00100,
B00010,
B00010,
B00010,
B00010,
B00100,
B11000,
};
byte smiley3[8] = {
B00011,
B00100,
B01100,
B01100,
B01100,
B01100,
B00100,
B00011,
};
byte smiley4[8] = {
B00011,
B00110,
B01110,
B01110,
B01110,
B01110,
B00110,
B00011,
};
byte smiley5[8] = {
B00011,
B00111,
B01111,
B01111,
B01111,
B01111,
B00111,
B00011,
};
byte smiley6[8] = {
B11000,
B10100,
B10010,
B10010,
B10010,
B10010,
B10100,
B11000,
};
byte smiley7[8] = {
B11000,
B11100,
B11010,
B11010,
B11010,
B11010,
B11100,
B11000,
};
byte smiley8[8] = {
B11000,
B11100,
B11110,
B11110,
B11110,
B11110,
B11100,
B11000,
};
void setup()
{
lcd.clear();
pinMode(13, OUTPUT);
Wire.begin(); //
lcd.init(); //
Serial.begin(9600);
// Initialisation IO et ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bps
lcd.setCursor(2,0); lcd.print("REM DETECTOR");
lcd.createChar(1,smiley1);
lcd.createChar(2,smiley2);
lcd.createChar(3,smiley3);
lcd.createChar(4,smiley4);
lcd.createChar(5,smiley5);
lcd.createChar(6,smiley6);
lcd.createChar(7,smiley7);
lcd.createChar(8,smiley8);
lcd.setCursor(0,1);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
lcd.write(1);lcd.write(2);
delay(2000);
lcd.setCursor(0,1); lcd.write(3);delay(100);lcd.setCursor(0,1); lcd.write(4);delay(100); lcd.setCursor(0,1); lcd.write(5);
lcd.setCursor(1,1); lcd.write(6);delay(100);lcd.setCursor(1,1); lcd.write(7);delay(100); lcd.setCursor(1,1); lcd.write(8);
delay(100);
lcd.setCursor(2,1); lcd.write(3);delay(100);lcd.setCursor(2,1); lcd.write(4);delay(100); lcd.setCursor(2,1); lcd.write(5);
lcd.setCursor(3,1); lcd.write(6);delay(100);lcd.setCursor(3,1); lcd.write(7);delay(100); lcd.setCursor(3,1); lcd.write(8);
delay(100);
lcd.setCursor(4,1); lcd.write(3);delay(100);lcd.setCursor(4,1); lcd.write(4);delay(100); lcd.setCursor(4,1); lcd.write(5);
lcd.setCursor(5,1); lcd.write(6);delay(100);lcd.setCursor(5,1); lcd.write(7);delay(100); lcd.setCursor(5,1); lcd.write(8);
delay(100);
lcd.setCursor(6,1); lcd.write(3);delay(100);lcd.setCursor(6,1); lcd.write(4);delay(100); lcd.setCursor(6,1); lcd.write(5);
lcd.setCursor(7,1); lcd.write(6);delay(100);lcd.setCursor(7,1); lcd.write(7);delay(100); lcd.setCursor(7,1); lcd.write(8);
delay(100);
lcd.setCursor(8,1); lcd.write(3);delay(100);lcd.setCursor(8,1); lcd.write(4);delay(100); lcd.setCursor(8,1); lcd.write(5);
lcd.setCursor(9,1); lcd.write(6);delay(100);lcd.setCursor(9,1); lcd.write(7);delay(100); lcd.setCursor(9,1); lcd.write(8);
delay(100);
lcd.setCursor(10,1);lcd.write(3);delay(100);lcd.setCursor(10,1);lcd.write(4);delay(100); lcd.setCursor(10,1); lcd.write(5);
lcd.setCursor(11,1);lcd.write(6);delay(100);lcd.setCursor(11,1);lcd.write(7);delay(100); lcd.setCursor(11,1); lcd.write(8);
delay(100);
lcd.setCursor(12,1);lcd.write(3);delay(100);lcd.setCursor(12,1);lcd.write(4);delay(100); lcd.setCursor(12,1); lcd.write(5);
lcd.setCursor(13,1);lcd.write(6);delay(100);lcd.setCursor(13,1);lcd.write(7);delay(100); lcd.setCursor(13,1); lcd.write(8);
delay(100);
lcd.setCursor(14,1);lcd.write(3);delay(100);lcd.setCursor(14,1);lcd.write(4);delay(100); lcd.setCursor(14,1); lcd.write(5);
lcd.setCursor(15,1);lcd.write(6);delay(100);lcd.setCursor(15,1);lcd.write(7);delay(100); lcd.setCursor(15,1); lcd.write(8);
delay(2000);
delay(1000);
lcd.clear();
lcd.print("MENU");
}
void loop() {
key = lcd.get_key(); // read the value from the sensor & convert into key press
if (key != oldkey) // if keypress is detected
{
delay(50); // wait for debounce time
key = lcd.get_key(); // read the value from the sensor & convert into key press
if (key != oldkey)
{
oldkey = key;
/////////////////////////////////////////////////////////////////////////////////
{
oldkey = key;
// 0: Right Key
if (key ==0 ){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.clear();lcd.setCursor(0, 0);lcd.print(msgs[key]);
}}
/////////////////////////////////////////////////////////////////////////////////
{
oldkey = key;
// 1: Up Key
if (key ==1 ){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.clear();lcd.setCursor(0, 0);lcd.print(msgs[key]);
}}
/////////////////////////////////////////////////////////////////////////////////
{
oldkey = key;
// 2: Down Key
if (key ==2 ){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.clear();lcd.setCursor(0, 0);lcd.print(msgs[key]);delay(1000);
lcd.setCursor(0, 1);
lcd.print("Debut du test ");delay(1000);
lcd.setCursor(0, 1);lcd.print("3 ");delay(1000);
lcd.setCursor(0, 1);lcd.print("2 ");delay(1000);
lcd.setCursor(0, 1);lcd.print("1 ");delay(1000);
lcd.setCursor(0, 1);lcd.print("TEST ");
const char *msg = "hello";
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
delay(200);
lcd.print("Fin du test ");delay(1000);
lcd.setCursor(0, 1);lcd.print(" ");
} }
/////////////////////////////////////////////////////////////////////////////////
{
oldkey = key;
// 3: Left Key
if (key ==3 ){
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.clear();lcd.setCursor(0, 0);lcd.print(msgs[key]);
}}
/////////////////////////////////////////////////////////////////////////////////
{
oldkey = key;
// 4: Select Key
if (key ==4 ){
{lcd.clear();lcd.setCursor(0, 0);lcd.print("ZEO ANALYSEUR");delay(1000);
// attend les informations
if (Serial.available() > 0) {
// lecture des donnees :
incomingByte = Serial.read();
if ( incomingByte == 65 ) { holeHeader(); } // nouvelles informations arrivent
}
else { lcd.setCursor(0, 1);lcd.print(" en attente");}
}
}}
/////////////////////////////////////////////////////////////////////////////////
}
}
//delay(1000);
}
void holeHeader() {
NOMBRE = 0;
while ( NOMBRE < 10 ) {
if (Serial.available() > 0) {
header[NOMBRE] = Serial.read();
NOMBRE++;}
}
SIZE = (( header[3] * 256 ) + header[2]);
if ( SIZE > 20 ) { SIZE = 1; } // dont read long raw waveform packages
if ( header[3] + header[5] == 255 & header[2] + header[4] == 255 ) { holeDaten(SIZE); }
else { Serial.println(" CAPTEURS = AUCUNES INFORMATIONS DETECTEES ");}
}
void holeDaten(int SIZE) {
DATA = (int*)calloc(1, SIZE * sizeof(int));
NOMBRE = 0;
while ( NOMBRE < SIZE ) {
if (Serial.available() > 0) {
DATA[NOMBRE] = Serial.read();
NOMBRE++;
}
}
if ( DATA[0] == 157 ) { Serial.print("Phase de sommeil ");
if (DATA[1] == 0) { Serial.println(": INCONNUE //phase cible// "); REMnombre++; }
if (DATA[1] == 1) { Serial.println(": EVEIL"); REMnombre = 0 ; }
if (DATA[1] == 2) { Serial.println(": REM"); REMnombre = 0 ; }
if (DATA[1] == 3) { Serial.println(": LEGER"); REMnombre = 0; }
if (DATA[1] == 4) { Serial.println(": PROFOND"); REMnombre = 0; }
Serial.print("numero = "); Serial.println(REMnombre);
}
if ( REMnombre > 1 ) { playcomplete("vib.WAV"); REMnombre = 0; } // si la phase cible est superieure à 2 lectures (1 min) jouer vib WAV. repeter toutes les 1 mn jusqu au changement de phase.
free(DATA);
}
void printName(dir_t &dir)
{
for (uint8_t i = 0; i < 11; i++) {
if (dir.name[i] == ' ')continue;
if (i == 8) Serial.print('.');
Serial.print(dir.name[i]);
}
if (DIR_IS_SUBDIR(dir)) Serial.print('/');
}
void makeLEDsblink() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW){
ledState = HIGH; }
else {
ledState = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}
void ls() {
dir_t d;
root.rewind();
while (root.readDir(d) > 0) {
printName(d);
Serial.println();
}
}
void playcomplete(char *name) {
playfile(name);
while (wave.isplaying) {
makeLEDsblink();
}
}
void playfile(char *name) {
if (wave.isplaying) {// deja en train de jouer quelque chose, donc stop !
wave.stop(); // stop
}
if (!f.open(root, name)) {
putstring("Impossible d ouvrir le fichier "); Serial.print(name); return;
}
if (!wave.create(f)) {
putstring_nl("WAV non valide"); return;
}
// lecture !
wave.play();
}
Retourner vers Vos projets, vos idées
Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité