【问题标题】:pebble time color configuration卵石时间颜色配置
【发布时间】:2015-08-05 20:34:14
【问题描述】:

我尝试优化我的卵石时间表盘的配置。为了避免字符串比较,我将所有 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>

有没有人有修复它的建议?我哪里错了?

【问题讨论】:

    标签: c pebble-watch pebble-sdk cloudpebble


    【解决方案1】:

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

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

    【讨论】:

    • 这可能是它......文档说你应该在阅读之前检查存在。写入也可能失败,因此您应该在写入时检查返回码。
    猜你喜欢
    • 2016-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2020-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多