|
8#
楼主 |
发表于 2016-11-18 15:10:14
|
只看该作者
本帖最后由 飘云 于 2016-11-18 15:12 编辑
。。。不是,这段是让WiFi进入配置的部分
上下文是这样的,其他的都是和微信宠物的源代码一样~~~
- arduino 初始化关键代码片段:
- void KEY_Handle(void)
- {
- /* 长按是指按住按键3s以上 */
- switch (gokit_keydown())
- {
- case KEY1_SHORT_PRESS:
- break;
- case KEY1_LONG_PRESS:
- GizWits_D2WResetCmd();
- digitalWrite(LED_PORT2, HIGH);
- delay(5000);
- digitalWrite(LED_PORT2, LOW);
- break;
- case KEY2_SHORT_PRESS:
- GizWits_D2WConfigCmd(SoftAp_Mode);
- NetConfigureFlag = 1;
- digitalWrite(LED_PORT2, HIGH);
- delay(1000);
- digitalWrite(LED_PORT2, LOW);
- break;
- case KEY2_LONG_PRESS:
- GizWits_D2WConfigCmd(AirLink_Mode);
- NetConfigureFlag = 1;
- digitalWrite(LED_PORT2, HIGH);
- delay(1000);
- digitalWrite(LED_PORT2, LOW);
- delay(1000);
- break;
- default:
- break;
- }
- }
- void GoKit_Init()
- {
- #if(DEBUG==1)
- //自定义引脚通信SoftwareSerial初始
- mySerial.begin(9600);
- #endif
- pinMode(LED_PORT, OUTPUT);
- pinMode(LED_PORT2, OUTPUT);
- // 按键初始
- pinMode(KEY1, INPUT_PULLUP); //KEY1 上拉输入
- pinMode(KEY2, INPUT_PULLUP); //KEY2 上拉输入
- memset(&ReadTypeDef, 0, sizeof(ReadTypeDef));
- memset(&WriteTypeDef, 0, sizeof(WriteTypeDef));
- GizWits_init(sizeof(ReadTypeDef_t));
- }
- void setup()
- {
- GoKit_Init();
- #if (DEBUG==1)
- mySerial.println(F("GoKit init OK!"));
- mySerial.print(F("freeMemory()="));
- mySerial.println(freeMemory());
- #endif
- }
- void loop()
- {
- uint8_t ret = 0;
- uint8_t buf[MAX_P0_LEN];
- KEY_Handle();
- ret = GizWits_MessageHandle(buf, sizeof(WriteTypeDef_t));
- if (ret == 0)
- {
- memcpy((uint8_t *)&WriteTypeDef, buf, sizeof(WriteTypeDef_t));
- GizWits_ControlDeviceHandle();
- GizWits_DevStatusUpgrade((uint8_t *)&ReadTypeDef, 10 * 60 * 1000, 1, NetConfigureFlag);
- }
- if (gaterSensorFlag != 0)
- {
- GizWits_GatherSensorData();
- gaterSensorFlag = 0;
- }
- GizWits_DevStatusUpgrade((uint8_t *)&ReadTypeDef, 10 * 60 * 1000, 0, NetConfigureFlag);
- //digitalWrite(LED_PORT2, HIGH);
- //delay(1000); // wait for a second
- //digitalWrite(LED_PORT2, LOW);
- //delay(1000); // wait for a second
- }
复制代码
|
|