So, in javascript(coffeescript), I have some code that looks like this:
"BRIGHT":
min: 1
max: 4
step: 1
value: 3
bluetooth:
options: [ 'off', 'on' ] # SOMETIMES I NEED ARRAY
callback: ->
rangeFinder.bluetooth = rangeFinder.getSetting().value
mode:
options: [ 'basic', 'advanced', 'config' ] # OF DIFFERENT LENGTHS
callback: ->
rangeFinder.lastMode = rangeFinder.getSetting().value
How do I do something like this in c++?
I've got an array of 3 objects similar to brightness
#include "setting.cpp"
class GlobalMenu {
public:
MenuSetting settings[3];
int setting;
GlobalMenu();
};
GlobalMenu::GlobalMenu(void){
// What is the currently selected setting?
this -> setting = 0;
this -> settings[0].name = "BRIGHT";
this -> settings[0].min = 1;
this -> settings[0].max = 4;
this -> settings[0].step = 1;
this -> settings[0].value = 3;
this -> settings[1].name = "BLUETOOTH";
// HOW DO I GET VARIABLE LENGTH ARRAYS HERE?
}
and in setting.cpp
class MenuSetting {
public:
char *name;
int min;
char options[][5];
int max;
int step;
int value;
};
somewhere else, this code changes the setting (and works)
void RangeFinder::changeSetting(int dir) {
this -> data.global.settings[this -> data.global.setting].value +=
(dir ? 1 : -1) *
this -> data.global.settings[this -> data.global.setting].step;
this -> enforceMinMax();
this -> render();
}
also if you can find a way to clean it up that would help
So, I can probably figure out how to detect if options has a length, but I am having problems assigning any number of options into the options array
The solution cannot use the STD.
As far as i know the atmega32 micro-controller can't use std lib.