J'ai un peu regardé sur le net mais pour les pointeurs mais c'est pas pratique de comprendre sur le net tout seul
pas encore eu le temps d'aller voir pour le bouquin je pense que je vais attendre le mois prochain pour l'acheter ce mois ci c'est un peu juste :-p
Je n'ai pas saisi si il était possible d'éviter d'utiliser les * ou de passer de char* à char pas exemple
depuis le début dès que j'essayais avec juste char j'ai des erreurs à la compilation
par exemple dans struct j'ai "char* nom_sonde;"
si j'essaye "char nom_sonde;" à la place j'ai une erreur à "myGLCD.print(sonde[0].nom_sonde,10,36);":
"invalid conversion from 'char' to 'const char*'"
sinon
DeviceAddress vient de
DallasTemperature.h :
"typedef uint8_t DeviceAddress[8];"
textbBuffer est une ligne de texte "file.readLn(textBuffer, 50);"
(tableau de caractère) normalement
file.readLn(buffer, bufSize);
Read the next line of text from an open text-file.
Parameters:
buffer: charArray to put the next line of text into
bufSize: size of buffer in bytes
Returns: Result as a word
Usage: res = file.readLn(st, 80); // Attempt to read the line of text and return it in st
Notes:
• The result will be the length of the textline that are returned
• If the buffer was to small it will be filled with all the text it could contain, and result will be BUFFER_OVERFLOW. It the end of the file was reached during the read result will be EOF
• Result can also be FILE_IS_EMPTY, ERROR_NO_FILE_OPEN or ERROR_WRONG_FILEMODE
Je vais essayer de mettre un peu plus de code concerné mais vu que c'est une une mise au point c'est un peu fouillis faut que je réorganise/ nettoie /commente le code
#include <Wire.h>
#include <tinyFAT.h>
#include <UTFT.h>
#include <UTFT_tinyFAT.h>
#include <ITDB02_Touch.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Timer.h>
#include <tinyFAT.h>
#include <String.h>
Timer t;
// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 8
int ledalert = 9;
int buzzer = 10;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
int x, y;
int n = 1;
typedef struct
{
DeviceAddress adresse;
char* nom_sonde;
float temp_actuelle;
float temp_min;
float temp_max;
}
sondes_temp;
sondes_temp sonde[10];
// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
...
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
return ( (val/16*10) + (val%16) );
}
....
byte res;
word result;
char textBuffer[81];
/***DEBUT SETUP *************************************************************************************************************************/
void setup(){
Wire.begin();
Serial.begin(9600);
zero=0x00;
dispHeure = String ();
// initialize digital pin as output.
pinMode(ledalert, OUTPUT);
pinMode(buzzer, OUTPUT);
myGLCD.InitLCD(LANDSCAPE);
myGLCD.clrScr();
file.initFAT();
myGLCD.setFont(BigFont);
myTouch.InitTouch(LANDSCAPE);
myTouch.setPrecision(PREC_MEDIUM);
myGLCD.fillScr(255, 255, 255);
myGLCD.setBackColor(153, 204, 255);
myGLCD.loadBitmap(0, 0, 320, 240, "fond.raw");
myGLCD.setColor(0, 0, 0);
myGLCD.print("Carte Gestion bacs", CENTER, 5);
myGLCD.setFont(SmallFont);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(Tempad1, 10);
sensors.setResolution(Tempad2, 10);
int tickEvent = t.every(1000, getDateDs1307tolcd);
getSondesInfos();
//Chargement SD
delay(1000);
}
/*FIN SETUP *************************************************************************************************************************/
/*DEBUT LOOP ************************************************************************************************************************/
void loop(){
//rafraich timer
t.update();
temptolcd();
...
myGLCD.print(String(freeRam()),280,200);
delay(1000);
}
/*FIN LOOP ************************************************************************************************************************/
void temptolcd(){
sensors.requestTemperatures();
float thistemp = printTemperature((uint8_t*)sonde[0].adresse);
sonde[0].temp_actuelle = thistemp;
Serial.println(sonde[0].temp_actuelle);
myGLCD.print(sonde[0].nom_sonde,10,36); //
myGLCD.printNumF( sonde[0].temp_actuelle,1,133,36); // temperature bac
myGLCD.drawCircle(167,36,1); // Cercle degre bac
myGLCD.print("C",172,36); // "c" de temperature bac
if (sonde[0].temp_actuelle > sonde[0].temp_max){
myGLCD.loadBitmap(100, 26, 32, 32, "thermoal.raw");
ledalertOn();
buzzOn();
}
else if (sonde[0].temp_actuelle < sonde[0].temp_min){
myGLCD.loadBitmap(100, 26, 32, 32, "thermof.raw");
ledalertOn();
buzzOn();
}
else {
myGLCD.loadBitmap(100, 26, 32, 32, "thermo.raw");
ledalertOff();
buzzOff();
}
sensors.requestTemperatures();
//lcd.print("Temp3: ");
//printTemperature(Tempad2);
}
void buzzOn(){
analogWrite(buzzer,128);
delay(500);
digitalWrite(buzzer, LOW);
delay(500);
}
void buzzOff(){
digitalWrite(buzzer, LOW);
}
void ledalertOn(){
digitalWrite(ledalert, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledalert, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}
void ledalertOff(){
digitalWrite(ledalert, LOW);
}
...
float printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.println("Error getting temperature");
printAddress(deviceAddress);
return tempC;
}
else {
return tempC;
}
}
void getSondesInfos()
{
//sonde[0].adresse = {0x28,0xC6,0x4D,0x21,0x04,0x00,0x00,0x57};
//sonde[0].nom_sonde = "Temp test";
//sonde[0].temp_actuelle = 21;
//sonde[0].temp_min = 10;
//sonde[0].temp_max = 26;
int line=0;
if (file.exists("temp1.txt"))
{
res=file.openFile("temp1.txt", FILEMODE_TEXT_READ);
if (res==NO_ERROR)
{
result=0;
while ((result!=EOF) and (result!=FILE_IS_EMPTY))
{
line ++;
result=file.readLn(textBuffer, 50);
if (result!=FILE_IS_EMPTY)
{
if (result==BUFFER_OVERFLOW)
Serial.print(textBuffer);
else{
if (line==2) {
//Si ligne adresse
Serial.println("ok 2 adr");
char *p = textBuffer;
uint8_t *str;
int itr= 0;
while ((str = (uint8_t *)strtok_r(p, ",", &p)) != NULL){ // delimiter is the semicolon
Serial.print(itr);
Serial.print(" : ");
Serial.print((char*)str);
Serial.print(" -> ");
sonde[0].adresse[itr]= str;
Serial.println((char*) sonde[0].adresse[itr]);
itr++;
}
}
else if (line==4) {
//Si ligne nom sonde
Serial.println("ok 4 nom");
strcpy( sonde[0].nom_sonde, textBuffer );
}
Serial.print("Line :");
Serial.println(line);
Serial.println(textBuffer);
}
}
else
Serial.println("** ERROR: File is empty...");
}
Serial.println();
file.closeFile();
}
else
{
switch(res)
{
case ERROR_ANOTHER_FILE_OPEN:
Serial.println("** ERROR: Another file is already open...");
break;
default:
Serial.print("** ERROR: ");
Serial.println(res, HEX);
break;
}
}
}
else{
Serial.println("** ERROR: 'temp1.txt' does not exist...");
}
Serial.println("** sensor init...");
printAddress(sonde[0].adresse);
Serial.println("** sensor init... fin");
}
int freeRam () {
extern int __heap_start, *__brkval;
int v;
return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress[i] < 8) Serial.print("0");
Serial.print(deviceAddress[i],HEX);
Serial.print(" - ");
}
}
J'ai enlevé des morceau c'était trop gros , ça ne passais pas