Strange restarts when passing an array between functions using pointers
this peculiar 1 , i'm having trouble isolating cause of issue. many things @ point, after hours of trial , error thing i've narrowed down, although don't know why issue.
here's i've got.... adafruit cc3000 rest api passing params url custom functions control rgb leds.
here's 2 example calls...
set led yellow: http://###.###.###.###/setrgb?params=255,255,0
fade led cyan on 5secs http://###.###.###.###/fadergb?params=0,255,255,5000
the adafruit lib works this... access function defined in sketch, have declare first, , call rest call. note functions needs take string unique argument (for parameters passed function) , return integer.
so wrote universal function split string of comma separated integer values array of long ints use within different functions. here is:
so in function setrgb use this...
for splitcommand() used in 2 functions setrgb() , fadergb() writing lots more functions. have found if declare 1 of these functions in rest api works. if declare both functions rest calls strange results. random resets functions arn't available via rest api. if pick 1 of 2 rgb functions , declare works great. if add function works fine long doesn't make use of splitcommand() function.
does have ideas, i'm totally open differnt solution splitcommand() i need turn string of params ints can accessed different functions.
here's i've got.... adafruit cc3000 rest api passing params url custom functions control rgb leds.
here's 2 example calls...
set led yellow: http://###.###.###.###/setrgb?params=255,255,0
fade led cyan on 5secs http://###.###.###.###/fadergb?params=0,255,255,5000
the adafruit lib works this... access function defined in sketch, have declare first, , call rest call. note functions needs take string unique argument (for parameters passed function) , return integer.
so wrote universal function split string of comma separated integer values array of long ints use within different functions. here is:
code: [select]
void splitcommand(string command, long *vals, byte len) {
int = 0;
int j = 0;
int inchar;
string instring;
{
inchar = command[i];
if (isdigit(inchar)) {
instring += (char)inchar;
} else if (inchar == 44) {
vals[j] = instring.toint();
instring = "";
j++;
}
i++;
} while(inchar > 0 && < 255 && j < len);
if(j < len) vals[j] = instring.toint();
}so in function setrgb use this...
code: [select]
int setrgb(string command) {
long vals[3];
splitcommand(command, vals, 3);
red = vals[0];
green = vals[1];
blue = vals[2];
//do stuff...
for splitcommand() used in 2 functions setrgb() , fadergb() writing lots more functions. have found if declare 1 of these functions in rest api works. if declare both functions rest calls strange results. random resets functions arn't available via rest api. if pick 1 of 2 rgb functions , declare works great. if add function works fine long doesn't make use of splitcommand() function.
does have ideas, i'm totally open differnt solution splitcommand() i need turn string of params ints can accessed different functions.
i suggest not use string class , use character arrays instead. parse command strtok() , atoi().
Arduino Forum > Using Arduino > Programming Questions > Strange restarts when passing an array between functions using pointers
arduino
Comments
Post a Comment