Reputation: 1
I try to optimize my configuration of my pebble time watchface. To avoid string comparisons I put all GColor values into an array, but it doesn't work at all :(
The array:
static uint8_t colors[] = {
GColorInchwormARGB8, //1
GColorSpringBudARGB8, //2
GColorBrightGreenARGB8, //3
GColorMintGreenARGB8, //4
GColorScreaminGreenARGB8, //5
GColorGreenARGB8, //6
GColorMalachiteARGB8, //7
};
read the data from the config:
static void in_recv_handler(DictionaryIterator *iterator, void *context)
{
Tuple *t = dict_read_first(iterator);
while (t != NULL){
switch (t -> key){
//++++++ background color +++++++
case bgColor:
persist_write_int(bgColor, t->value->int8);
break;
//++++++ time color ++++++
case timeColor:
persist_write_int(timeColor, t->value->int8);
break;
}
t = dict_read_next(iterator);
}
}
I tried uint8, uint16, uint32, int8, int16 and int32. If I use int32 the watch crash.
Set the color to the layer:
time_color = (GColor)colors[persist_read_int(timeColor)];
When I use:
time_color = (GColor)colors[4];
the right color appears.
the values of the html page:
<select id="bg_select">
<option class="inchworm" value="0">Inchworm</option>
<option class="springBud" value="1">Spring Bud</option>
<option class="brightGreen" value="2">Bright Green</option>
<option class="mintGreen" value="3">Mint Green</option>
</select>
Does anybody have suggestions to fix it? What do I wrong?
Upvotes: 0
Views: 168
Reputation: 3816
Depending on the exact order of events, the color value might not have been saved yet. Are you checking for whether the value exists?
if(persist_exists(timeColor)) {
time_color = (GColor)colors[persist_read_int(timeColor)];
}
Upvotes: 1