c - 卵石时间颜色配置

标签 c pebble-watch pebble-sdk cloudpebble

我尝试优化我的 pebble time 表盘的配置。为了避免字符串比较,我将所有 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 watch 就会崩溃。

设置图层颜色:

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>

有人有解决这个问题的建议吗?我做错了什么?

最佳答案

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

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

关于c - 卵石时间颜色配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31842302/

相关文章:

c - 如何从父线程中杀死子线程 - C

c - 使用 SOCK_DGRAM 从服务器获取信息时出现问题

pebble-watch - CloudPebble 与原生 Pebble SDK

android - AppSync Pebble : I get wrong values

ios - 从 Pebble watchapp 打开与 iOS 应用程序的通信 session

c - 将取消引用的指针(即按值)传递给需要指针的函数

ios - sqlite3_last_insert_rowid 在第一次插入后返回 0

c++ - 错误 - 当前位置没有可用的源代码

pebble-watch - 卵石表盘

在运行时更改静态变量