Replies: 2 comments 2 replies
-
You could even use a separate database for this...
JSON and JSONSchema do not restrict the content of arrays, so you can mix anything at all (integers, strings, objects, etc.). The file At present, there is a single This same information can tell the user which object type an array entry is. Handily, as we're not using virtual classes we can define a Note that we also need to include support in ConfigDB for re-useable type definitions, via the
Yep. |
Beta Was this translation helpful? Give feedback.
-
Just re-reading your initial question and noticed I haven't addressed the issue of variant parts of an Object. Might be easier thinking about the C++ code we'd like to generate and work back. class Color: public ConfigDB::UnionTemplate<...> {
public:
struct Struct {
enum class Tag: uint8_t {
RGB,
HSV,
RAW,
};
Tag tag;
union Content {
struct RGB {
uint8_t r;
uint8_t g;
uint8_t b;
};
struct HSV {
uint8_t h;
uint8_t s;
uint8_t v;
};
struct RAW {
uint8_t r;
uint8_t g;
uint8_t b;
uint16_t ww;
uint16_t cw;
};
};
};
const RGB& getRGB() const {
assert(tag == Tag::RGB);
return ...
}
const RGB& getHSV() const {
assert(tag == Tag::HSV);
return ...
}
const RGB& getRAW() const {
assert(tag == Tag::RAW);
return ...
}
}; This would be a member of a regular In the schema the "color": {
"oneOf": [
"RGB": {
...
},
"HSV": {
...
},
"RAW": {
...
}
]
} Once we have "color": {
"$ref": "#/$defs/Color"
},
"$defs": {
"Color": {
"oneOf": [
"RGB": {
"$ref": "#/$defs/RGB"
},
"HSV": {
"$ref": "#/$defs/HSV"
},
"RAW": {
"$ref": "#/$defs/RAW"
}
]
},
"RGB": {
...
},
"HSV": {
...
},
"RAW": {
...
}
} |
Beta Was this translation helpful? Give feedback.
-
so with all this wonderful json database code, I was thinking that I could move a bit of data into the configuration that is not quite as static as the "normal" config but also not totally changing either.
I have had the concept of light presets, groups and group presets for a while. Currently, only light presets are implemented and are stored in files. If I moved them into the schema, I could lose the code that writes them to files, too.
Presets can have three different formats: RAW, RGB or HSV. (the firmware differentiates only between HSV, where it does the full mixing of all three, four or five available channels) and RAW, where every channel is driven separately and no color calucations are made.
An RGB preset would look somewhat like this:
HSV is
and lastly, RAW is
my first thought is: an array can only contain objects that all follow the same schema, right? It would be easier to have name, timestamp and id for all, then a type filed and the color field syntax according to the defined type. From what I understand, I would have to have three arrays, though, or does json / jsonschema allow variants within an array?
I would probably also want to store an array of controllers (found by mDNS)
Scenes could then be stored as an array of (controller_id, preset_id) tupels.
groups would be groups of controllers that I can switch with a single ui action
and lastly, scenes or group presets would combine controllers and presets, I'm not yet 100% sure if I will store the color values with the scene or if I will write a preset and link to it by id.
In order to be able to operate on those IDs sensibly, I guess most of those object should be in the same store to prevent excessive read / thrashing.
The easiest way to do this is all in the front end, there's enough RAM, parsing json in JavaScript is very natural and it does make sense to control it from there. In this case, I might just pull those bits of the configuration into a structure and do all the api calls from there and write back the changes. That would generate the least RAM load on the controller as well as not require it to re-load the store over and over. So I would probably put all of this into stores according to how I structure it in JavaScript (currently Controllers, presets, groups and scenes- so four separate stores) and, in firmware, deal with each of them as a single unit.
(I notice, as usual, my thoughts have become clearer as I write this down :) )
Any thoughts on this?
Beta Was this translation helpful? Give feedback.
All reactions