Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Issues with Pass Array of Structures to Library by Reference on: May 18, 2013, 12:45:56 am
GoForSmoke:

Comfortable not yet...but ironically I very vaguely remember doing a similar exercise trying to get familiar with C and pointers at some point around about 1978 or so on a PDP-11 running a very early release of Unix System V.  Except that now you can run Linux on a credit card sized computer.

That second link is a real good one...needed it a bit earlier when trying to get a CRC routine working :-o

Thanks,
Wisar
2  Using Arduino / Programming Questions / Re: Issues with Pass Array of Structures to Library by Reference on: May 17, 2013, 10:59:32 am
Below is the output from a sketch that tries to demonstrate a lot of the pointers on pointers that I got from this thread.   The code was too long to post here but is available here:
Code:
https://docs.google.com/file/d/0BxF8IoGgsWZwdUtZMmE5MTdHYzA/edit?usp=sharing
  I know there are probably a zillion more ways to address things but these feel like the ones that I will be using for my current projects!

Quote
Pointer to an integer
a is now = 200
Another way to use that pointer...
a is now = 300
...which allows you to do this
a is now = 301

Pointer to a char array
abcdefghijklmnopqrstuvwxyz0123456789 <- Printed using original assignment of 'myS'
a <- Printed using '*myS'
a <- Printed using pointer '*ptrmyS'
abcdefghijklmnopqrstuvwxyz0123456789 <- Printed using pointer 'ptrmyS'
abcdefghijklmnopqrstuvwxyz0123456789 <- Printed by walking pointer down char array
abcde#ghijklmnopqrstuvwxyz0123456789 <- after modifying using array notation
abcde#ghij#lmnopqrstuvwxyz0123456789 <- after modifying using pointer notation

Printed in a function using a variable...
abcde#ghij#lmnopqrstuvwxyz0123456789 ...passed using original assignment
abcde#ghij#lmnopqrstuvwxyz0123456789 ...passed using pointer '*ptr2myS
abcde#ghij#lmno#qrstuvwxyz0123456789 ...passed using pointer '*ptr2myS and modified

Pointers to an integer array...
...int *B = A + 5; = 5
...int C = *B + 10; = 15
...*B = 21; = 21

Pointers into a two dimensional array...
abcdefg <- Printed as myData[3]
d <- Printed as myData[3][3]
e <- Printed as *( myData[3] + 4 )
abcdefg <- Printed as myDataAsPtr[3]
defg <- Printed as myDataAsPtr[3] + 3
a <- Printed as *myDataAsPtr[3]
t <- Printed as *( myDataAsPtr[1] + 3 )
22222 <- Printed as *ptr after 'const char (*ptr)[10] = (myData) + 2;'

Pointers into a two dimensional array...
abcdefg <- Printed as myData[3]
d <- Printed as myData[3][3]
e <- Printed as *( myData[3] + 4 )
abcdefg <- Printed as myDataAsPtr[3]
defg <- Printed as myDataAsPtr[3] + 3
a <- Printed as *myDataAsPtr[3]
t <- Printed as *( myDataAsPtr[1] + 3 )
wertyu <- Printed as *ptr1 after 'const char (*ptr1)[10] = (myData) + 2;'

Pointers into an array of structures...
line2 <- Printed via function passed a pointer to a row
selGraph <- Printed via a pointer to a row
selStats
selGraph
line2
 <- Printed via function passed the whole blob
3  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 16, 2013, 03:56:30 pm
GoForSmoke and Hashma:

Thanks for both of the above posts.   Hashma: Not only does the CRC sketch compile it even returns the right answer!

GoForSmoke:   I got sidetracked into trying to get the demo on the Arduino website to work which then convinced me there was something wrong with the configuration of my machine...which...etc, etc.  While I have given up on using Progmem for a complex structure I can get what I need with a CSV string and the example you posted.

Cheers,
Wisar
4  Using Arduino / Programming Questions / Re: Issues with Pass Array of Structures to Library by Reference on: May 15, 2013, 02:51:34 pm
GoForSmoke, EconJack, Pyro:   Thanks for giving me so much to think about!   Great discussion.  Pointers still make my head hurt but to work in Arduino'land I guess I will have to deal. 

EconJack:  I had actually arrived at your version of my script but was hoping for a way to pass a single pointer to the whole mess and then have the function navigate the array?   At this point I think I need to step back and really try to understand what is happening, and what has been said above, rather than to keep flailing at the ball!   I also have this dream of using PROGMEM but that is another topic.....

Cheers,
Wisar
5  Using Arduino / Programming Questions / Re: PROGMEM Demo on Arduino.cc Will not Compile? on: May 15, 2013, 04:01:58 am
HeliBob:

I am running IDE 1.0.1 on all three machines that I have tried including the one that works (with all 58 lines of the sketch!).   This appears to be the latest version packaged in apt-get for Ubuntu and Debian as the installs are new.

I do seem to have the pgmspace.h file:

-rw-r--r-- 1 root root 41927 May 23  2012 /usr/lib/avr/include/avr/pgmspace.h

Assuming that is the right place for it!

Wisar
6  Using Arduino / Programming Questions / PROGMEM Demo on Arduino.cc Will not Compile? on: May 15, 2013, 02:22:51 am
Is there something wrong with the configuration of my machine(s) such that the demo of PROGMEM from the below page does not compile on Ubuntu or on a Raspberry Pi running Debian (but does compile on a MAC)?

http://www.arduino.cc/en/Reference/PROGMEM

The error that I am getting is that prog_char does not define a type.

Thanks for any help,
Wisar
7  Using Arduino / Programming Questions / Re: Issues with Pass Array of Structures to Library by Reference on: May 15, 2013, 12:24:02 am
econjack:

My degree in CS dates back a long long ways...in fact so far back that "C" was only just starting to gain in popularity and Unix System V had just come out of Bell Labs into the university community.   Pointers made my head hurt then and they still do today!

majenko:

Thanks for the pointer <sic> as it did put me exactly on the path to what I need.   What I ended up with is the below all pulled into one sketch:

Code:
#include <UTFT.h>
#include <UTouch.h>

// #include <Forms4Utft.h>
// Forms4Utft forms;

struct F4Utft {
    String name;
    int x;
    int y;
    String formatName;
};

const int DEF_MENU1 = 3;

static struct F4Utft m01 = {"selStats", 15, 195, "BigFontS"};
static struct F4Utft m02 = {"selGraph", 215, 195, "BigFontS"};
static struct F4Utft m03 = {"line2", 15, 185, "None"};

struct F4Utft *Def_Menu[] = {&m01, &m02, &m03};

void setup() {
    // For debugging messages
    Serial.begin(57600);

    Serial.println("--->" + Def_Menu[1]->formatName);
    Serial.println("--->" + String(test(Def_Menu)));
}

void loop() {
    while (true) {

    }
}

String test(struct F4Utft** menu) {
    return(menu[1]->formatName);
}

The initializer gave me fits and there is another format (single statement with a structure declaration before each entry) that I liked better could not get to work...but this does so I am happy and can move on!

My next challenge is to try and understand why I can not seem to put this resultant structure into PROGMEM without it killing my script (any ideas?)

Thanks again for the help,
Wisar and a little Wiser
8  Using Arduino / Programming Questions / Issues with Pass Array of Structures to Library by Reference on: May 14, 2013, 10:36:38 am
I am humbled to be back at the well so soon but I have spent the better part of the day fighting with pointers.   I am able to pass a pointer for one row of my structure but not for the entire structure.   I recognize that I am doing something stupid and would appreciate a [gentle] slap on the head...here is my code

The called CPP library:
Code:
#ifndef Forms4Utft_h
#define Forms4Utft_h

class Forms4Utft {
   public:
        String test(struct F4Utft*);
};
#endif

The library .H
Code:
#include <Arduino.h>
#include "Forms4Utft.h"

struct F4Utft {
    String name;
    int x;
    int y;
    String formatName;
};

String Forms4Utft::test(struct F4Utft* menu) {
    return(menu[0].formatName);
}

The calling INO:
Code:
#include <UTFT.h>
#include <UTouch.h>

#include <Forms4Utft.h>

Forms4Utft forms;

struct F4Utft {
    String name;
    int x;
    int y;
    String formatName;
};

const int DEF_MENU1 = 3;

struct F4Utft Def_Menu[DEF_MENU1] = {
     {"selStats", 15, 195, "BigFontS"},
     {"selGraph", 215, 195, "BigFontS"},
     {"line2", 15, 185, "None"},
};

void setup() {
    // For debugging messages
    Serial.begin(57600);

    struct F4Utft ptr = Def_Menu[2];

    Serial.println("--->" + Def_Menu[0].formatName);
    Serial.println("--->" + String(forms.test(&ptr)));
}

void loop() {
    while (true) {

    }
}

When I do what I think should be done:

Code:
Change...
    struct F4Utft ptr = Def_Menu[0];
...to:
    struct F4Utft ptr = &Def_Menu;


I get errors: conversion from F4Utft[3] to non-scalar type F4Utft requested
9  Using Arduino / Programming Questions / Re: Force Concatenation Order for Multiple File Sketches on: May 14, 2013, 02:39:11 am
Well. Darn.   Nothing is ever easy.  

...

Actually....I just included the file above, as generated, and it seems to be working.   Or at least I am not getting the same errors and have others that I can now attack!

Thanks for the help,
Wisar
10  Using Arduino / Programming Questions / Re: Force Concatenation Order for Multiple File Sketches on: May 14, 2013, 02:02:42 am
TobyB:

Thanks for the help....but.....are you sure that is the only way forward?   I have working libraries but as I read the following from Hacking the Arduino I 'should' be able to concatenate files as I am trying to do (unless, of course, the concatenation is only from the back.....):

Quote
Multi-file sketches

A sketch can contain multiple files (tabs). To manage them, click on the right-facing arrow just above the scroll bar near the top of the environment. Tabs have one of four extensions: no extension, .c, .cpp, or .h (if you provide any other extension, the period will be converted to an underscore). When your sketch is compiled, all tabs with no extension are concatenated together to form the "main sketch file". Tabs with .c or .cpp extensions are compiled separately. To use tabs with a .h extension, you need to #include it (using "double quotes" not <angle brackets>).

I guess I could construct it as a ".h" ..... but as this is generated code I would rather have it be simpler than not simpler.

Wisar
11  Using Arduino / Programming Questions / Re: Force Concatenation Order for Multiple File Sketches on: May 14, 2013, 01:24:01 am
I was hoping there was something obvious that I was missing.......

Here is the primary INO (forms4UtftTest.ino):
Code:
#include <UTFT.h>
#include <UTouch.h>

// Declare which fonts we will be using
extern uint8_t BigFont[];
extern uint8_t SevenSegNumFont[];

UTFT myGLCD(ITDB32S, 38,39,40,41);
UTouch myTouch(6,5,4,3,2);

void setup()
{
    // For debugging messages
    Serial.begin(57600);

    myGLCD.InitLCD();
    myGLCD.clrScr();
    myTouch.InitTouch();
    myTouch.setPrecision(PREC_MEDIUM);
}

void loop() {
    while (true)
    {
        if (myTouch.dataAvailable())
        {
            myTouch.read();
            int x=myTouch.getX();
            int y=myTouch.getY();
            for (int i = 0; i < DEF_MENU; i++) {
                if (x >= Def_Menu[i].x && x <= Def_Menu[i].x1) {
                    Serial.println("Pressed " + Def_Menu[i].name);
                }
            }
        }
    }
}

Here is it's companion that is getting sucked into the compiler behind the above( Forms4Utft.ino):
Code:
// Generated by Forms for TFT a companian to www.Form-Builder-for-PHP.com
//

// Enable storage of literals in program space rather than RAM
#include <avr/pgmspace.h>

struct Forms4Utft {
    String name;
    int x;
    int y;
    String formatName;
    int width;
    int height;
    String type;
    String color;
    String backColor;
    int round;
};

const int DEF_MENU = 12;

const Forms4Utft Def_Menu[DEF_MENU] = {
     {"selStats", 15, 195, "BigFontS", 90, 35, "btn", "000000", "      ", 0},
     {"selGraph", 215, 195, "BigFontS", 90, 35, "btn", "000000", "      ", 0},
     {"line2", 15, 185, "", 300, 2, "hline", "000000", "      ", 0},
     {"line1", 15, 95, "", 300, 2, "hline", "000000", "      ", 0},
     {"testStatus", 15, 105, "BigFontS", 280, 0, "txt", "000000", "      ", 0},
     {"header", 15, 5, "BigFontS", 280, 0, "txt", "000000", "      ", 0},
     {"maxSustainedBar", 15, 160, "", 290, 15, "hline", "000000", "      ", 0},
     {"selTest20", 115, 35, "7SegNumFontR", 90, 50, "btn", "000000", "      ", 1},
     {"selTest30", 215, 35, "7SegNumFontR", 90, 50, "btn", "000000", "      ", 1},
     {"maxSustained", 85, 130, "BigFontS", 200, 15, "txt", "000000", "      ", 0},
     {"selTest10", 15, 35, "7SegNumFontR", 90, 50, "btn", "000000", "      ", 1},
     {"obsSec", 15, 130, "BigFontS", 40, 0, "txt", "000000", "      ", 0},
};


And the exact error messages:
Forms4UtftTest.cpp: In function ‘void loop()’:
Forms4UtftTest.cpp:33:33: error: ‘DEF_MENU’ was not declared in this scope
Forms4UtftTest.cpp:34:26: error: ‘Def_Menu’ was not declared in this scope
12  Using Arduino / Programming Questions / Force Concatenation Order for Multiple File Sketches on: May 14, 2013, 12:25:06 am
I am trying to develop a multiple file sketch and am getting "not declared in this scope" errors because one of my files (one with some definitions) is being concatenated AFTER the main INO.   I have tried renaming to change the order in the directory but this does not seem to help.

Help would be appreciated before I toss an Arduino in the Thames out of frustration!

Wisar
13  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 10, 2013, 03:53:01 am
GoForSmoke:

I still have issues.   As you suspected my 'solution' may have gotten me a clean compile but the array is NOT going to program memory.   AND...when I put the prog_ prefix back in front of the type I get the compile error saying that it is a non existent type.   Something else is going wrong in my environment and I am not sure where to look...!

Wisar
14  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 09, 2013, 03:53:14 pm
I have not checked though I do mean to.   http://www.arduino.cc/en/Reference/PROGMEM says it is position neutral...

Wisar
15  Using Arduino / Programming Questions / Re: Compile errors with Progmem on: May 09, 2013, 11:38:54 am
Making the change to const from static AND pulling off the prog_ prefix to the type got me a clean compile and a working sketch.   I could have sworn that I had tried that combination but obviously did not!

Code:
PROGMEM const uint32_t crc_table[16] = {
    0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
    etc, etc...

Thanks for the help. 

Cheers, Wisar
Pages: [1] 2