le main :
#include "Pin.h"
#include "General.h"
#include "MsTimer2.h"
boolean received = false; // Boléen pour connaitre si une donnée est reçue
int tick_time_to_update=0;
byte inByte;
//identifiant de la trame série reçue
int Identifiant =0;
//variables des états des réseaux
int wifi =0;
int ethernet =0;
int bluetooth =0;
//variable pour stocker les messages série reçues
int msg[RCVSIZE];
//commande d'alimentation de l'affichage
char cmd_alimentation_affichage =0;
void IRQ_tick(void)
{
static int cpt1 = 0;
cpt1++;
if(cpt1 >= TEMPO_200msec)
{
tick_time_to_update = 1;
cpt1 = 0;
}
}
void Update(void)
{
if(received)
{
Identifiant = msg[0]; //on définit le premier char provenant de l'udoo comme un identifiant d'une trame série
switch (1)
{
case Identifiant_Alimentation:
cmd_alimentation_affichage= msg[1];
//GereAlimentation(cmd_alimentation_affichage);
break;
case 1:
//Serial.println("update");
wifi = msg[0]; // wifi
ethernet = msg[1]; //ethernet
bluetooth = msg[2]; //bluetooth
//Serial.println("wifi avant gereled");
//Serial.println(wifi);
GereLedEtat(wifi, ethernet, bluetooth);
break;
case Identifiant_Alimentation_Led:
cmd_alimentation_affichage= msg[1];
wifi = msg[2];
ethernet = msg[3];
bluetooth =msg[4];
// GereAlimentation(cmd_alimentation_affichage);
GereLedEtat(wifi,ethernet,bluetooth);
break;
default:
break;
}
}
received=false;
}
// the setup routine runs once when you press reset:
void setup() {
//initialisation des pins d'entrée analogique des réveils 1 et 2
pinMode(PinReveil1, INPUT);
pinMode(PinReveil2, INPUT);
//initialisation des pins de sorties analogiques
pinMode(PinkeepAlive,OUTPUT);
//initialisation des Leds
pinMode(Pin_led_wifi_R,OUTPUT);
pinMode(Pin_led_wifi_G,OUTPUT);
pinMode(Pin_led_ethernet_R,OUTPUT);
pinMode(Pin_led_ethernet_G,OUTPUT);
pinMode (Pin_led_bluetooth_R,OUTPUT);
pinMode (Pin_led_bluetooth_G,OUTPUT);
//initialisation de l'ensemble des leds
digitalWrite(Pin_led_wifi_R,LOW);
digitalWrite(Pin_led_wifi_G,LOW);
digitalWrite(Pin_led_ethernet_R,LOW);
digitalWrite(Pin_led_ethernet_G,LOW);
digitalWrite (Pin_led_bluetooth_R,LOW);
digitalWrite (Pin_led_bluetooth_G,LOW);
//InitAlimentation();
MsTimer2::set(20,IRQ_tick);
MsTimer2::start();
//initialisation du port série à un baud rate de 115200 bps
Serial.begin(115200);
delay(100);
//Serial.println("start");
}
void loop() {
//variables pour la réception sur le port série
int count = 0;
while (Serial.available() > 0) {
// get the new byte:
byte inByte =(byte)Serial.read();
msg[count] = inByte;
count++;
received = true;
} //lecture du port série et remplissage d'un buffer tant qu'il y a des données à lire
if(tick_time_to_update)
{
Update();
tick_time_to_update =0;
}
delay(10);
}
le code pour gérer les leds ;
#include "Pin.h"
#include "GereLedEtat.h"
// 3 Leds RGBs
void GereLedEtat(int x_wifi, int x_ethernet, int x_bluetooth )
{
etat_reseaux wifi = (etat_reseaux) x_wifi;
etat_reseaux ethernet= (etat_reseaux) x_ethernet;
etat_reseaux bluetooth = (etat_reseaux) x_bluetooth;
//conversion de x_wifi,x_ethernet,x_bluetooth en type etat_reseaux, arduino ne prend pas de type enum/struct en paramètre
Serial.println("wifi");
Serial.println(wifi);
switch(wifi)
{
case CONNECTE:
digitalWrite(Pin_led_wifi_G,!digitalRead(Pin_led_wifi_G));
digitalWrite(Pin_led_wifi_R,LOW);
break;
case DECONNECTE:
digitalWrite(Pin_led_wifi_G,HIGH);
digitalWrite(Pin_led_wifi_R,LOW);
break;
case INDISPONIBLE:
digitalWrite(Pin_led_wifi_R,HIGH);
digitalWrite(Pin_led_wifi_G,LOW);
break;
default:
break;
}
switch(ethernet)
{
case CONNECTE:
digitalWrite(Pin_led_ethernet_G,!digitalRead(Pin_led_ethernet_G));
digitalWrite(Pin_led_wifi_R,LOW);
break;
case DECONNECTE:
digitalWrite(Pin_led_ethernet_G,HIGH);
digitalWrite(Pin_led_ethernet_R,LOW);
break;
case INDISPONIBLE:
digitalWrite(Pin_led_ethernet_R,HIGH);
digitalWrite(Pin_led_ethernet_G,LOW);
break;
default:
break;
}
switch(bluetooth)
{
case CONNECTE:
digitalWrite(Pin_led_bluetooth_G,!digitalRead(Pin_led_bluetooth_G));
digitalWrite(Pin_led_bluetooth_R,LOW);
break;
case DECONNECTE:
digitalWrite(Pin_led_bluetooth_G,HIGH);
digitalWrite(Pin_led_bluetooth_R,LOW);
break;
case INDISPONIBLE:
digitalWrite(Pin_led_bluetooth_R,HIGH);
digitalWrite(Pin_led_bluetooth_G,LOW);
break;
default:
break;
}
}
J'ai remarqué que lorsque le moniteur série est ouvert, il n'y a plus aucun problèmes, mais je ne souhaite pas avoir à ce qu'il soit ouvert pour que ça fonctionne.
Ah et pour ouvrir le port série et envoyer des données depuis mon PC j'utilise des appels systèmes comme write()