鹅卵石时间颜色配置

时间:2015-08-05 20:34:14

标签: c pebble-watch pebble-sdk cloudpebble

我尝试优化我的鹅卵石时间表面的配置。为了避免字符串比较,我将所有GColor值放入一个数组中,但它根本不起作用:(

数组:

static uint8_t colors[] = {
GColorInchwormARGB8,    //1
GColorSpringBudARGB8,    //2
GColorBrightGreenARGB8,    //3
GColorMintGreenARGB8,    //4
GColorScreaminGreenARGB8,    //5
GColorGreenARGB8,    //6
GColorMalachiteARGB8,    //7
};

从配置中读取数据:

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);
  } 
}

我尝试了uint8,uint16,uint32,int8,int16和int32。如果我使用int32手表崩溃。

将颜色设置为图层:

time_color = (GColor)colors[persist_read_int(timeColor)];

当我使用时:

time_color = (GColor)colors[4];

出现正确的颜色。

html页面的值:

 <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>

有人有建议解决吗?我错了什么?

1 个答案:

答案 0 :(得分:1)

根据事件的确切顺序,可能尚未保存颜色值。你在检查价值是否存在?

if(persist_exists(timeColor)) {
  time_color = (GColor)colors[persist_read_int(timeColor)];
}