I am working on a project where I have to build an IR program that works with all of the AVR/Arduino boards to control the IR devices such as TV, DVD, etc. I am building a struct that can carry the Pronto code information and this is what I have so far:
struct Pronto {
char* code;
public:
Pronto(){}
Pronto(char* code) {
bool isValid = validateProntoCode(code);
if(isValid)
this->code = code;
}
Pronto toPronto(char* code) {
Pronto cde(code);
return cde;
}
void setPronto(char* code){
bool isValid = validateProntoCode(code);
if(isValid)
this->code = code;
}
char* toString(){
return code;
}
private:
bool validateProntoCode(char* code) {
if(!isInHex(code[strlen(code)-1]))
return false;
for (int i = 0; i < strlen(code); i++) {
if (!isInHex(code[i]) && !(i % 5 == 4 ))
return false;
if (i % 5 == 4 && code[i] != ' ')
return false;
if (i % 5 == 0 && (!isInHex(code[i]) || !isInHex(code[i] + 1) || !isInHex(code[i] + 2) || !isInHex(code[i + 3])))
return false;
}
return true;
}
bool isInHex(char c) {
char list[22] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','a','b','c','d','e','f'};
for (int i = 0; i < 22; i++) {
if (c == list[i])
return true;
}
return false;
}
};
This struct code I can set the Pronto code, validate it, and get the string value from it. Now, whenever I declare the struct inside the Arduino IDE:
pronto.setPronto("0000 006D 0000 00BF 009F 0031 0030 0010 0010 0031");
I get this following message:
Sketch uses 4082 bytes (12%) of program storage space. Maximum is 32256 bytes.
Global variables use 2137 bytes (104%) of dynamic memory, leaving -89 bytes for local variables. Maximum is 2048 bytes.
Not enough memory; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing your footprint.
Pictures:
Basically, I just showed all my work on code I did. I commented out any global vars, nothing changed. BUT, when I comment "pronto.setPronto("0000 0000");", I get free space.
So, how can I modify this struct in-order for it not to take allot of space?
The char* code right? That's the problem. Now can you help me modify code or at least tell me how I can resolve this.