simonliu009 发表于 2018-9-21 14:40:32

ESP8266 SOC方案枚举数据点总是越界,无默认值

本帖最后由 simonliu009 于 2018-9-21 14:43 编辑

你好:
我现在用SOC源码定义了一个枚举数据点,如下:

显示名称:风力模式
标识名:windmode
读写类型:可写
数据类型:枚举

枚举范围:0.普通 1.自然风 2.睡眠风

备注: 风力模式调节



但是现在遇到了问题:
1. 使用了机智云通用APP进行控制,但是每次打开APP,默认总是没有选择任何值,如图

2. 同时看Log有提示越界: valuewindmode Error , Illegal Overstep
值是-1


3. 代码中,只在user_main.c的按键里面更改枚举值:
LOCAL void ICACHE_FLASH_ATTR key2LongPress(void)
{

      currentDataPoint.valuewindmode = (currentDataPoint.valuewindmode + 1)%3;
      GIZWITS_LOG(" \r\n ========== Windmode changes to: %d ========== \r\n", currentDataPoint.valuewindmode);
}

所以我的问题是:1. 枚举数据点是否有默认值?

2. 哪里的代码会导致枚举值为-1?

3. 对于这个问题有什么建议?

Seasonic 发表于 2018-9-21 15:12:38

void ICACHE_FLASH_ATTR userInit(void)
{
    gizMemset((uint8_t *)¤tDataPoint, 0, sizeof(dataPoint_t));

        /** Warning !!! DataPoint Variables Init , Must Within The Data Range **/
    /*
                   currentDataPoint.valueLED_OnOff = ;
                   currentDataPoint.valueLED_Color = ;
                   currentDataPoint.valueLED_R = ;
                   currentDataPoint.valueLED_G = ;
                   currentDataPoint.valueLED_B = ;
                   currentDataPoint.valueMotor_Speed = ;
                   currentDataPoint.valueInfrared = ;
                   currentDataPoint.valueTemperature = ;
                   currentDataPoint.valueHumidity = ;
                   currentDataPoint.valueAlert_1 = ;
                   currentDataPoint.valueAlert_2 = ;
                   currentDataPoint.valueFault_LED = ;
                   currentDataPoint.valueFault_Motor = ;
                   currentDataPoint.valueFault_TemHum = ;
                   currentDataPoint.valueFault_IR = ;
    */
}在gizwits_product.c文件中 ,userInit函数是赋初值的地方,另外枚举类型的在没有明确赋值的情况下,默认是从0开始,依次递增+1

simonliu009 发表于 2018-9-21 15:14:28

Seasonic 发表于 2018-9-21 15:12
在gizwits_product.c文件中 ,userInit函数是赋初值的地方,另外枚举类型的在没有明确赋值的情 ...

默认是0
void ICACHE_FLASH_ATTR userInit(void)
{
    gizMemset((uint8_t *)&currentDataPoint, 0, sizeof(dataPoint_t));

        /** Warning !!! DataPoint Variables Init , Must Within The Data Range **/

                   currentDataPoint.valueoscillating = 0;
                   currentDataPoint.valuepower = 0;
                   currentDataPoint.valuewindmode = 0;
                   currentDataPoint.valuespeed = 0;

}
页: [1]
查看完整版本: ESP8266 SOC方案枚举数据点总是越界,无默认值