Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions 24h.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "Carte.h"

// Shell
#include "shell.h"
#include "config.h"

// Interupt
Expand All @@ -11,32 +10,31 @@

// Rule Checker
#include "rule_checker.h"

// Shell commands
shell_command_t shell_commands[SHELL_COMMAND_COUNT];
#include "utils.h"

void setup(void)
{
SHELL_COMMAND_DECL(0, "help", "this help", false, shell_command_help);
SHELL_COMMAND_DECL(1, "send", "send a debug static frame", true, sendDbgFrames);
SHELL_COMMAND_DECL(2, "init", "send a debug static frame", false, sendInit);
SHELL_COMMAND_DECL(3, "address", "display address", false, display_address);
SHELL_COMMAND_DECL(4, "status", "display status", false, display_status);
shell_setup();

io_setup();
//rc_setup();
Serial.begin(9600);
pinMode(dbg0_pin, OUTPUT);
pinMode(dbg1_pin, OUTPUT);
carte_setup();
FlexiTimer2::set(25, 1.0/10000, tick2500us); // call every 500 1ms "ticks"
// FlexiTimer2::set(500, flash); // MsTimer2 style is also supported
FlexiTimer2::start();

//carte_update();
//io_setup();
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);

//carte_update();
//io_loop();
}

void loop(void)
{
shell_loop();
carte_loop();
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
carte_update();
io_loop();
// Please dont add delay here :(
// delay(1500);
}
140 changes: 48 additions & 92 deletions Carte.cpp
Original file line number Diff line number Diff line change
@@ -1,111 +1,67 @@
#include "my_def.h"
#include "Arduino.h"
#include "Carte.h"
#include "my_def.h"

#define BASIC 0
#define ALPHABET 1
#define SEMAINE 2

#define RULE BASIC

Carte my_carte(1, 1);

Carte::Carte(int val, int state):
myval(val),
mystate(state),
Dval(2),
Gval(4),
AllG(true),
LocG(false)
{
// FIXME: these statments do not have any effect!
this->DG[2];
this->hasLCD;
#include "rule_checker.h"

Carte::Carte(int myname):
name(myname),
state(0x03),
Rname(0),
Lname(0),
Rstate(0),
Lstate(0),
globSol(true),
locSol(false),
hasLCD(false){}

boolean Carte::update_globSol(){
boolean globSol=this->state & (1 << 0);//macro avrlib _BV
return globSol;
}

//Verififier que c est les bon bits
boolean Carte::get_AllGood(int PIN,byte mystate){
boolean AllG=this->mystate & (1 << 0);//macro avrlib _BV
return AllG;
boolean Carte::update_locSol(){
boolean locSol=this->state & (1 << 1);//macro avrlib _BV
return locSol;
}

boolean Carte::get_LocGood(int PIN, byte mystate){
boolean AllL=this->mystate & (1 << 1);//macro avrlib _BV
return LocG;
}
//Verififier que c est les bon bits
//boolean Carte::get_globSol(){
// return this->state & (1 << 0);//macro avrlib _BV
//}

//tester si le comp fonctionne en bytes
boolean Carte::valid(int D_val,int G_val){
return D_val-'0'<=G_val-'0';
}
//boolean Carte::get_globSol(){
// return this->state & (1 << 1);//macro avrlib _BV
//}

void Carte::check(){
byte Dval=2;
byte Gval=4;
this->DG[0]=valid(this->Dval, this->myval);
this->DG[1]=valid(this->myval, this->Gval);
}

void Carte::update(){
boolean DG[2];
boolean DAllG, GAllG;

switch (RULE){
case (BASIC):
this->check();
this->LocG=DG[0] && DG[1];


this->locSol=basic_check(this->name, this->Lname, this->Rname);
case (ALPHABET || SEMAINE):
LocG=rule_check(this->myval, this->Gval, this->Dval);
this->locSol=rule_check(this->name, this->Lname, this->Rname);
}
this->check();
this->LocG=DG[0] && DG[1];
this->AllG=(DAllG && GAllG && LocG);
}

void carte_setup()
{
if (RULE != BASIC){
rc_setup();
}
pinMode(PIN_LED_ROUGE, OUTPUT);
pinMode(PIN_LED_JAUNE, OUTPUT);
digitalWrite(PIN_LED_ROUGE, LOW);
digitalWrite(PIN_LED_JAUNE, LOW);
// Phase 1 : Est-on en extrémité ?
this->globSol=(this->Rstate%2 && this->Lstate%2 && this->globSol);

}

void carte_loop()
{
//Serial.println(my_carte.myval);
//my_carte.update();

// Phase 3 : Diffusion de mon Adresse

// Phase 4 : Apprentissage - qui sont mes voisins ?

// Phase 5 : Détermination Etat Local et Global




void Carte::display_names(){
Serial.println(" L | * | R");
Serial.println("----------------");
Serial.print(this->Lname);
Serial.print(" | ");
Serial.print(this->name);
Serial.print(" | ");
Serial.println(this->Rname);
Serial.println("________________");
}

void display_carte_props()
{
/*
Serial.println("Droite| Moi |Gauche");
Serial.print(my_carte.Dval);
Serial.print(" | ");
Serial.print(my_carte.myval);
Serial.print(" | ");
Serial.println(my_carte.Gval);
*/
Serial.print(my_carte.DG[0]);
Serial.print(" | ");
Serial.print("D G");
Serial.print(" | ");
Serial.print(my_carte.DG[1]);
}
void Carte::display_states(){
Serial.print(" Loc/Glob | ");
bool isLoc=(this->Lname<=this->name && this->name<=this->Rname)? 'Good!':'Bad';
Serial.print(isLoc);
bool isGlob=(this->Lname<=this->name && this->name<=this->Rname)? 'Good!':'Bad';
Serial.print(" ");
Serial.println(isGlob);
Serial.println("____________");
}
28 changes: 13 additions & 15 deletions Carte.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,22 @@

class Carte{
public:
Carte(int val, int state);
int myval; //Nom ou adresse de la carte
int mystate; //donnees libres
int Dval;
int Gval;
boolean AllG; //All good : no error detected
Carte(int);
int name; //Nom ou adresse de la carte
int state; //donnees libres
int Rname;
int Lname;
int Rstate;
int Lstate;
boolean globSol; //All good : no error detected
boolean locSol; //All good : no error detected
boolean hasLCD; //All good : no error detected
boolean LocG; //Local good: mes voisins sont bons
boolean DG[2]; //validite des voisins Droit et Gauche
boolean get_AllGood(int, byte);
boolean get_LocGood(int, byte);
boolean valid(int, int); //rule checker
void check(); //update DG
boolean update_globSol();
boolean update_locSol();
void update(); //update All Good and Locally Good
void display();
void display_names();
void display_states();
};

void carte_setup();
void carte_loop();
void display_carte_props();
#endif
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__

#define SHELL_COMMAND_COUNT 5
#define SHELL_COMMAND_COUNT 2

#endif
Loading