Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: AGHW-Arduino-Pass C++ string to function as parameter... on: February 28, 2011, 07:37:55 am
Code:
    for (unsigned int t=0; t<sizeof(AID_AGHead); t++)
      EEPROM.write(APtr_AGHead + t, *((char*)&AID_AGHead + t));

In this part of the function I will change the sizeof with the strlen()... but I have problem also with the bytes which get write in the EEPROM... It seems that *((char*)&AID_AGHead + t) does not return the correct byte (from the AID_AGHead)...

Do I have to change it to *((char*)AID_AGHead + t) ? (I cannot test it right now)... in order to work?
2  Using Arduino / Programming Questions / Re: AGHW-Arduino-Pass C++ string to function as parameter... on: February 28, 2011, 06:49:12 am
How can I get the char array (through the pointer)? so the sizeof will be working...
3  Using Arduino / Programming Questions / AGHW-Arduino-Pass C++ string to function as parameter... on: February 28, 2011, 12:28:30 am
I have the function:
Code:
// Open the EDB table, if existed or created...
void AG_Table_Open(unsigned long APtr_AGHead, char* AID_AGHead){
  DBGL3_PRN("(1) AID_AGHead: ");
  DBGL3_PRN(AID_AGHead);
  DBGL3_PRN(", size: ");
  DBGL3_PRNLN(sizeof(AID_AGHead));

  AG_LogStruct strucRec;
  String dbDescr;
/*  DBGL3_PRN("(");
  DBGL3_PRN(AID_AGHead);
  DBGL3_PRN("=");
  DBGL3_PRN(AG_EDBIndex_ID);
  DBGL3_PRNLN(")=========================");*/

  if (strcmp(AID_AGHead, AG_EDBIndex_ID)==0){
//  if (AID_AGHead==AG_EDBIndex_ID){
    dbDescr = "AG_EDBIndex";
  }
  else {
    LOG_PRN("unknown AG_Table! (");
    LOG_PRN(AID_AGHead);
    LOG_PRNLN(")");
    return;
  }
  EDB db(&AG_Table_EEPROM_Writer, &AG_Table_EEPROM_Reader);
  DBGL3_PRNLN("DB object created...");
  int memPos = APtr_AGHead+sizeof(AID_AGHead)-1;

  if (EEPROM.read(APtr_AGHead + 0) == AID_AGHead[0] &&
      EEPROM.read(APtr_AGHead + 1) == AID_AGHead[1] &&
      EEPROM.read(APtr_AGHead + 2) == AID_AGHead[2]) {
    DBGL3_PRN(dbDescr);
    DBGL3_PRN(" DB exists... (mem loc: ");
    DBGL3_PRN(memPos, DEC);
    DBGL3_PRNLN(")");
    if (db.open(memPos)==EDB_OK){
      DBGL3_PRN(dbDescr);
      DBGL3_PRN(" DB opened... (RecCount: ");
      DBGL3_PRN(db.count(), DEC);
      DBGL3_PRNLN(")");
    }
    else {
      DBGL3_PRN(dbDescr);
      DBGL3_PRNLN(" DB could not opened...!");
//    db.create(200, TABLE_SIZE, sizeof(logUpPeriod));
//    db.create(300, 100, sizeof(logUpPeriod));
//    DBGL3_PRNLN("DB created...");
    }
  }
  else {
    DBGL3_PRN("AID_AGHead: ");
    DBGL3_PRN(AID_AGHead);
    DBGL3_PRN(", size: ");
    DBGL3_PRNLN(sizeof(AID_AGHead));
    for (unsigned int t=0; t<sizeof(AID_AGHead); t++)
      EEPROM.write(APtr_AGHead + t, *((char*)&AID_AGHead + t));
    DBGL3_PRN(dbDescr);
    DBGL3_PRNLN(" DB header ID saved...!");
    if (strcmp(AID_AGHead, AG_EDBIndex_ID)==0){
//    if (AID_AGHead==AG_EDBIndex_ID){
      db.create(memPos, 120, sizeof(strucRec));
    }
  }
}

I am calling it through:
Code:
 AG_Table_Open(AG_EDBIndex_START, AG_EDBIndex_ID);

where:
Code:
#define AG_EDBIndex_START 50
#define AG_EDBIndex_ID "a@i"

The sizeof AID_AGHead (inside the function) is 2! (instead of 4) but the contents looks OK ("a@i")...!?

Why is this happening?

What I am doing wrong?

What is the correct way of passing strings in Arduino (C++)?

Thank you
4  Using Arduino / Programming Questions / Re: AGHW-"error: expected primary-expression before..." on: February 26, 2011, 02:01:02 pm
If I remove it:
Code:
  AG_Table_Open(AG_EDBIndex_START, AG_EDBIndex_ID, stctAGEDBIndexRec);
The compiler:
Quote
_AG_Template_Prg.cpp: In function 'void setup()':
_AG_Template_Prg:114: error: cannot convert 'AG_EDBIndexRec' to 'byte*' for argument '3' to 'void AG_Table_Open(long unsigned int, char*, byte*)'
5  Using Arduino / Programming Questions / AGHW-"error: expected primary-expression before..." on: February 26, 2011, 12:22:13 pm
I have made this function:
Code:
void AG_Table_Open(unsigned long APtr_AGHead, char* AID_AGHead, EDB_Rec A_Rec){
  EDB dbagidx(&AG_Table_EEPROM_Writer, &AG_Table_EEPROM_Reader);
  int memPos = APtr_AGHead+sizeof(AID_AGHead)-1;

  if (EEPROM.read(APtr_AGHead + 0) == AID_AGHead[0] &&
      EEPROM.read(APtr_AGHead + 1) == AID_AGHead[1] &&
      EEPROM.read(APtr_AGHead + 2) == AID_AGHead[2]) {
    DBGL3_PRN("AG_EDBIndex DB exists... (mem loc: ");
    DBGL3_PRN(memPos, DEC);
    DBGL3_PRNLN(")");
    if (dbagidx.open(memPos)==EDB_OK){
      DBGL3_PRN("AG_EDBIndex DB opened... (RecCount: ");
      DBGL3_PRN(dbagidx.count(), DEC);
      DBGL3_PRNLN(")");
    }
    else {
      DBGL3_PRNLN("AG_EDBIndex DB could not opened...!");
//    db.create(200, TABLE_SIZE, sizeof(logUpPeriod));
//    db.create(300, 100, sizeof(logUpPeriod));
//    DBGL3_PRNLN("DB created...");
    }
  }
  else {
    for (unsigned int t=0; t<sizeof(AID_AGHead); t++)
      EEPROM.write(APtr_AGHead + t, *((char*)&AID_AGHead + t));
    DBGL3_PRNLN("AG_EDBIndex DB header ID saved...!");
    dbagidx.create(memPos, 120, sizeof(A_Rec));
  }
}

and I am trying to call it:
Code:
struct AG_EDBIndexRec {
  byte id;
}
stctAGEDBIndexRec;
...
  AG_Table_Open(AG_EDBIndex_START, AG_EDBIndex_ID, EDB_Rec stctAGEDBIndexRec);

The compiler reports:
Quote
_AG_Template_Prg.cpp: In function 'void setup()':
_AG_Template_Prg:113: error: expected primary-expression before 'stctAGEDBIndexRec'

Why I get this compiler error? I am very confused!

Actually I want to pass the record structure in the function in order to be used...

Thank you
6  Development / Other Software Development / Re: AGHW-Database handling-EDB library on: February 26, 2011, 02:38:59 am
No-one???
7  Development / Other Software Development / AGHW-Database handling-EDB library on: February 22, 2011, 11:55:40 pm
I am looking in the edb lib... very interesting...!

With edb we can open a edb table from the EEPROM... How can we make sure that the opened edb object holds the correct data (for the corresponding record structure)?

I mean how can I confirm that the already opened data structure (EEPROM) and the EDB object (opened) use the absolute same record structure?

I think that something is missing here...
8  Using Arduino / Programming Questions / Re: AGHW-Arduino - Generic cpp and h files... ShareActions ! Actions ! Δημοσιεύσει on: February 17, 2011, 11:12:28 am
Great! Thank you!
9  Using Arduino / Programming Questions / Re: AGHW-Arduino - Generic cpp and h files... ShareActions ! Actions ! Δημοσιεύσει on: February 17, 2011, 09:57:38 am
You are correct! This must be the problem...! I will check it tonight...

Thank you

Where is it appropriate to create the "AG_ConfigStruct" structure? In "AGGen.cpp" or in each pde file which uses (includes) AGGen.h?
10  Using Arduino / Programming Questions / Re: AGHW-Arduino - Generic cpp and h files... ShareActions ! Actions ! Δημοσιεύσει on: February 17, 2011, 12:20:12 am
Actually this was a typing mistake by me..

In h file the function prototype is
    void AG_LoadConfig();
and not
    void AG_LoadConfig() {
(I fixed in first post...)

I do not know why I am taking this message...
11  Using Arduino / Programming Questions / AGHW-Arduino - Generic cpp and h files... ShareActions ! Actions ! Δημοσιεύσει on: February 16, 2011, 11:17:49 am
Hello,

I want to move some functions in an other cpp file and some declarations in a another h file, in order to use them in several pde files (arduino source)...

AGGen.h file:
#ifndef AGGen_h
#define AGGen_h

#include "WProgram.h"

#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM

struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};

#endif

AGGen.cpp file:
#include "WProgram.h"
#include <AGGen.h>
#include <EEPROM.h>

bool AG_LoadConfig_from_EEPROM() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (EEPROM.read(AG_CONFIG_START + 0) == AG_CONFIG_ID[0] &&
EEPROM.read(AG_CONFIG_START + 1) == AG_CONFIG_ID[1] &&
EEPROM.read(AG_CONFIG_START + 2) == AG_CONFIG_ID[2]) {
for (unsigned int t=0; t<sizeof(AG_Config); t++)
*((char*)&AG_Config + t) = EEPROM.read(AG_CONFIG_START + t);
Serial.println("loadConfig.....");
Serial.print("storage.len: ");
Serial.print(AG_Config.len, DEC);
Serial.println("----------");
return true;
}
return false;
}

void AG_LoadConfig() {
// To make sure there are settings, and they are YOURS!
// If nothing is found it will use the default settings.
if (not AG_LoadConfig_from_EEPROM()){
AG_SaveConfig();
AG_LoadConfig_from_EEPROM();
}
}

In pde file:
#include <AGGen.h>
...
void setup () {
Serial.begin(57600);
...
AG_LoadConfig();
}

Whan compile, I get the message:
JeeTest_EEPROM.cpp: In function 'void setup()':
JeeTest_EEPROM:189: error: 'AG_LoadConfig' was not declared in this scope

If I add the declaration to AGGen.h:
#ifndef AGGen_h
#define AGGen_h

#include "WProgram.h"

#define AG_CONFIG_ID "a@g" // ID of the settings block
#define AG_CONFIG_Ver 1 // 0..255 with the version of the config structure
#define AG_CONFIG_START 0 // Tell it where to store your config data in EEPROM

struct AG_ConfigStruct { // AG settings structure
char id[4]; // This is for mere detection if they are your settings
byte ver;
char len;
} AG_Config = {AG_CONFIG_ID, AG_CONFIG_Ver,32};

void AG_LoadConfig();

#endif

compiler show:
AGLib\AGGen.cpp.o:(.data.AG_Config+0x0): multiple definition of `AG_Config'
JeeTest_EEPROM.cpp.o:(.data.AG_Config+0x0): first defined here

Can someone tell me how can I do this? How can I transfer some code in an other cpp/h file...? and use it in several pde files?

What am I doing wrong in above code?

Thank you
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: AGHW-Arduino-LCD.createChar-Parametric data on: December 05, 2010, 12:50:23 am
I try:

byte SpecialCharToDisplay[] = {};

SpecialCharToDisplay = GrChrGama;

lcd.createChar(iSpecialChrPos, SpecialCharToDisplay);

but this way I do not know the size of the array that could be assigned so I leave it empty... I get an error:
"incompatible types in assignment of 'byte [7]' to 'byte
  • '"

Can I declare the array with the biggest possible values? What happened if assign a smaller array?
13  Forum 2005-2010 (read only) / Syntax & Programs / AGHW-Arduino-LCD.createChar-Parametric data on: December 04, 2010, 02:06:30 pm
byte GrChrDelta[] = {0x4,0xa,0x11,0x11,0x11,0x1f,0x0};       //[ch916] -
byte GrChrThita[] = {0xe,0x11,0x11,0x1f,0x11,0x11,0xe};      //[ch920] -
byte SpecialCharToDisplay;

SpecialCharToDisplay = *GrChrDelta;
lcd.createChar(iSpecialChrPos, SpecialCharToDisplay);

In above code I want to store the character data to a variable and then call the createChar... and ofcourse it does not working!

Could someone help me with this?

How can I save it, in what type of variable and how I must use it in the createChar?

Thank you
14  Forum 2005-2010 (read only) / Interfacing / Re: AGHW-Arduino-Strings-Greek chars... on: December 05, 2010, 04:21:18 am
I write code in order to be able to write (easy) to the LCD text that might contain also Greek chars without bother for the technical details...

I transform all of them in capital (upper-case) Latin and for the the 10 Greek chars which do not exist in Latin alphabet I create them  (createChar) and use them... Because the special chars are 8 (only) if happened to need more (9 or 10) in the same screen text, then only the first 8 (different) will be show...

This is my first code attempt in C and Arduino please be welcome to make any suggestions...

Waiting for your opinion...

PS: The Greek chars was designed by my 9year old son so be tolerant... this is his first attempt also...

Code:
/*
  LiquidCrystal Library - display() and noDisplay()
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD and uses the
 display() and noDisplay() functions to turn on and off
 the display.
 
 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 25 July 2009
 by David A. Mellis

 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//  pins: 4, 5, 6, 7,                  // could not change!
//        8 (RS), 9 (Enable), 11 (RW)  // could be changed!
// RS, RW, E, D4, D5, D6, D7
LiquidCrystal lcd(8, 11, 9, 4, 5, 6, 7);

const String ChrsTblTfrm = "ABgdEZHtIKlMNkOpPsTYfXcw";
const String ChrsTblGrChrs = "gdtlkpsfcw";
const String ChrsTblEngChrSet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const String ChrsTblGrChrSet = "[ch945][ch946][ch947][ch948][ch949][ch950][ch951][ch952][ch953][ch954][ch955][ch956][ch957][ch958][ch959][ch960][ch961][ch963][ch964][ch965][ch966][ch967][ch968][ch969][ch913][ch914][ch915][ch916][ch917][ch918][ch919][ch920][ch921][ch922][ch923][ch924][ch925][ch926][ch927][ch928][ch929][ch931][ch932][ch933][ch934][ch935][ch936][ch937]1234567890";

byte GrChrGama[]  = {0x1f,0x10,0x10,0x10,0x10,0x10,0x0};     //[ch915] -
byte GrChrDelta[] = {0x4,0xa,0x11,0x11,0x11,0x1f,0x0};       //[ch916] -
byte GrChrThita[] = {0xe,0x11,0x11,0x1f,0x11,0x11,0xe};      //[ch920] -
byte GrChrLamda[] = {0x4,0xa,0x11,0x11,0x11,0x11,0x0};       //[ch923] -
byte GrChrXi[]    = {0x1f,0x0,0xe,0x0,0x0,0x1f,0x0};         //[ch926] -
byte GrChrPi[]    = {0x1f,0x11,0x11,0x11,0x11,0x11,0x0};     //[ch928] -
byte GrChrSigma[] = {0x1f,0x18,0x4,0x8,0x10,0x1f,0x0};       //[ch931] -
byte GrChrFi[]    = {0x4,0xe,0x15,0xe,0x4,0x4,0x0};          //[ch934] -
byte GrChrPsi[]   = {0x4,0x15,0xe,0x4,0x4,0x4,0x0};          //[ch936] -
byte GrChrOmega[] = {0x0,0xe,0x11,0x11,0xa,0x1b,0x0};        //[ch937] -

void setup() {
  String strText;

  Serial.begin(9600);

  lcd.begin(16, 2);

//  debugOutputGrChrSet();

  strText = "";
  for (int i=33; i <= 64; i++){
    strText += char(i);
  }
  
  displayTextOnLCD("[ch945][ch946][ch947][ch948][ch949][ch950][ch951][ch952][ch953][ch954][ch955][ch956][ch957][ch958][ch959][ch960][ch961][ch963][ch964][ch965][ch966][ch967][ch968][ch969]");
  displayTextOnLCD("[ch913][ch914][ch915][ch916][ch917][ch918][ch919][ch920][ch921][ch922][ch923][ch924][ch925][ch926][ch927][ch928][ch929][ch931][ch932][ch933][ch934][ch935][ch936][ch937]");
  displayTextOnLCD(strText);
  displayTextOnLCD("abcdefghijklmnopqrstuvwxyz");
  displayTextOnLCD("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
}

void loop() {
}

void displayTextOnLCD (String strText){
  int iPos = -1;
  int iChrsOnLCD = 0;
  int iSpecialChr = 0;
  int iSpecialChrPos = 0;
  String strLCDSpecialChars = "";
  char chrChar, chrLCDChar;
  boolean boolUnicode = false;
  byte SpecialCharToDisplay[] = {};
  boolean boolSetSpecialChar = false;

  lcd.clear();
  lcd.home();
  for (int i=0; i < strText.length(); i++){
    chrChar = strText.charAt(i);
    boolUnicode = ((int(chrChar) == -50) || (int(chrChar) == -49));
    if (boolUnicode) chrChar = strText.charAt(++i);     // unicode
    chrLCDChar = TransformChar(chrChar);
    Serial.println(chrLCDChar);
    iSpecialChr = -1;
    if (ChrsTblGrChrs.indexOf(chrLCDChar) > -1) {
        iSpecialChr = strLCDSpecialChars.indexOf(chrLCDChar);
        if (iSpecialChr == -1) {
          strLCDSpecialChars.setCharAt(iSpecialChrPos, chrLCDChar);
          if (iSpecialChrPos < 8) {
            boolSetSpecialChar = true;
            switch (chrLCDChar){
              case 'g':
                lcd.createChar(iSpecialChrPos, GrChrGama);
                break;
              case 'd':
                lcd.createChar(iSpecialChrPos, GrChrDelta);
                break;
              case 't':
                lcd.createChar(iSpecialChrPos, GrChrThita);
                break;
              case 'l':
                lcd.createChar(iSpecialChrPos, GrChrLamda);
                break;
              case 'k':
                lcd.createChar(iSpecialChrPos, GrChrXi);
                break;
              case 'p':
                lcd.createChar(iSpecialChrPos, GrChrPi);
                break;
              case 's':
                lcd.createChar(iSpecialChrPos, GrChrSigma);
                break;
              case 'f':
                lcd.createChar(iSpecialChrPos, GrChrFi);
                break;
              case 'c':
                lcd.createChar(iSpecialChrPos, GrChrPsi);
                break;
              case 'w':
                lcd.createChar(iSpecialChrPos, GrChrOmega);
                break;
              default:
                iSpecialChr = -1;
                boolSetSpecialChar = false;
            }
            if (boolSetSpecialChar) iSpecialChr = iSpecialChrPos++;
          }
        }
    }

    if (iSpecialChr > -1) {
      if (iChrsOnLCD <= 16) {
        lcd.setCursor(iChrsOnLCD,0);
      }
      else {
       lcd.setCursor(iChrsOnLCD-16,1);
      }
      lcd.write(iSpecialChr);
    }
    else lcd.write(chrLCDChar);
    lcd.cursor();
//    if (++iChrsOnLCD > 16) lcd.scrollDisplayLeft();
    if (++iChrsOnLCD == 16) lcd.setCursor(0,1);
    delay(500);
  }  

  lcd.blink();
  delay(5000);
  lcd.noBlink();
  for (int i=0; i < 16; i++){
    lcd.scrollDisplayLeft();
    delay(500);
  }
}

/*
  -50, -79([ch945])..-65([ch959])
  -49, -128([ch960])..-127([ch961])
  -49, -125([ch963])..-119([ch969])
  -50, -111([ch913])..-95([ch929])
  -50, -93([ch931])..-87([ch937])
*/
char TransformChar(char chrC){
  int iAscii = int(chrC);
  char Result;
  if (iAscii >= -79 && iAscii <= -65) {     // -79: [ch945] .. -65: [ch959]
    Result = ChrsTblTfrm.charAt(iAscii+79);
  }
  else if (iAscii >= -128 && iAscii <= -127) {     // -128: [ch960], -127: [ch961]
    Result = ChrsTblTfrm.charAt(iAscii+128+(79-65+1));
  }
  else if (iAscii >= -125 && iAscii <= -119) {     // -125: [ch963], -119: [ch969]
    Result = ChrsTblTfrm.charAt(iAscii+125+(79-65+1)+2);
  }
  else if (iAscii >= -111 && iAscii <= -95) {     // -111: [ch913], -95: [ch929]
    Result = ChrsTblTfrm.charAt(iAscii+111);
  }
  else if (iAscii >= -93 && iAscii <= -87) {     // -93: [ch931], -87: [ch937]
    Result = ChrsTblTfrm.charAt(iAscii+93+(111-95+1));
  }
  else if (iAscii >= 32 && iAscii <= 90) {     // A..Z, 0..1, other chars
     Result = chrC;
  }
  else if (iAscii >= 97 && iAscii <= 122) {     // a..z
     Result = chrC-32;
  }
  return Result;
}

void debugOutputGrChrSet (){
  char chrChar;
  unsigned int uiAscii;

  for (int i=0; i < ChrsTblGrChrSet.length(); i++){
    chrChar = ChrsTblGrChrSet.charAt(i);
//    boolUnicode = ((int(chrChar) == -50) || (int(chrChar) == -49));
//    if (boolUnicode) chrChar = ChrsTblGrChrSet.charAt(++i);     // unicode
    uiAscii = chrChar;
    Serial.print(i);
    Serial.print(", ");
    Serial.print(int(chrChar));
    Serial.print(", ");
    Serial.print(uiAscii);
    Serial.print(", ");
    Serial.println(chrChar);
  }
  delay(250000);
}
15  Forum 2005-2010 (read only) / Interfacing / AGHW-Arduino-Strings-Greek chars... on: December 05, 2010, 12:12:24 am
I am trying to read the chars from a String with Greek chars but I see them as 2 bytes probably because of Unicode...

1) How can we handle Unicode strings in Arduino? I mean how can we tell if a string has Unicode chars? The length() is wrong... How can we read the chars?
2) Is there support for Greek?

I am trying to show Greek chars in a LCD 16[ch967]2 but it does not support them.. I will use special chars (unfortunately only 8!) and load the Greek chars for displaying...

I am working in a function which gets the string to display in a LCD as a parameter, replace the Greek chars with Latin substitutes and for the rest it uses the special chars....
Pages: [1] 2