// test :AT+TEST=1,"abc"<,3> void ICACHE_FLASH_ATTR at_setupCmdTest(uint8_t id, char *pPara) { int result = 0, err = 0, flag = 0; uint8 buffer[32] = {0}; pPara++; // skip '=' //get the first parameter // digit flag = at_get_next_int_dec(&pPara, &result, &err); // flag must be ture because there are more parameter if (flag == FALSE) { at_response_error(); return; } if (*pPara++ != ',') { // skip ',' at_response_error(); return; } os_sprintf(buffer, "the first parameter:%d\r\n", result); at_port_print(buffer); //get the second parameter // string at_data_str_copy(buffer, &pPara, 10); at_port_print("the second parameter:"); at_port_print(buffer); at_port_print("\r\n"); if (*pPara == ',') { pPara++; // skip ',' result = 0; //there is the third parameter // digit flag = at_get_next_int_dec(&pPara, &result, &err); // we donot care of flag os_sprintf(buffer, "the third parameter:%d\r\n", result); at_port_print(buffer); } if (*pPara != '\r') { at_response_error(); return; } at_response_ok(); }
// digitalRead([pin]) void ICACHE_FLASH_ATTR at_setupReadPinCmd(uint8_t id, char *pPara) { int result = 0, err = 0, flag = 0; uint8 buffer[32] = {0}; pPara++; // skip '=' //get the first parameter (uint8_t) // digit flag = at_get_next_int_dec(&pPara, &result, &err); // flag must be true because there are more parameters //if ((flag == FALSE) && (result > 0) ) if (err > 0) { at_port_print("Bad input"); at_response_error(); return; } uint8_t pin = result; // Don't go any further if the pin is un-usable or non-existant if (!pinValid(pin)) { at_response_error(); return; } uint8_t value = GPIO_INPUT_GET(pin); os_sprintf(buffer, "%d\r\n", value); at_port_print(buffer); at_response_ok(); }
// digitalWrite([pin], [value]) void ICACHE_FLASH_ATTR at_setupWritePinCmd(uint8_t id, char *pPara) { int result = 0, err = 0, flag = 0; uint8 buffer[32] = {0}; pPara++; // skip '=' //get the first parameter (uint8_t) // digit flag = at_get_next_int_dec(&pPara, &result, &err); // flag must be true because there are more parameters if ((flag == FALSE) && (result > 0) ) { at_response_error(); return; } uint8_t pin = result; // Don't go any further if the pin is un-usable or non-existant if (!pinValid(pin)) { at_response_error(); return; } if (*pPara++ != ',') { // skip ',' at_response_error(); return; } char value = *pPara++; if ((value == 'h') || (value == 'H') || (value == '1')) { GPIO_OUTPUT_SET(pin, 1); os_sprintf(buffer, "%d=HIGH\r\n", pin); } else if ((value == 'l') || (value == 'L') || (value == '0')) { GPIO_OUTPUT_SET(pin, 0); os_sprintf(buffer, "%d=LOW\r\n", pin); } else { at_response_error(); return; } at_port_print(buffer); at_response_ok(); }
// pinMode([pin], [direction]) void ICACHE_FLASH_ATTR at_setupPinModeCmd(uint8_t id, char *pPara) { int result = 0, err = 0, flag = 0; uint8 buffer[32] = {0}; pPara++; // skip '=' //get the first parameter (uint8_t) // digit flag = at_get_next_int_dec(&pPara, &result, &err); // flag must be true because there are more parameters if ((flag == FALSE) && (result > 0) ) { at_response_error(); return; } uint8_t pin = result; // Don't go any further if the pin is un-usable or non-existant if (!pinValid(pin)) { at_response_error(); return; } if (*pPara++ != ',') { // skip ',' at_response_error(); return; } char mode = *pPara++; if ((mode == 'i') || (mode == 'I')) { if (pin == STATUS_LED_PIN) { wifi_status_led_uninstall(); } PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]); GPIO_DIS_OUTPUT(pin); PIN_PULLUP_DIS(pinMap[pin]); os_sprintf(buffer, "%d=INPUT\r\n", pin); } else if ((mode == 'o') || (mode == 'O')) { if (pin == STATUS_LED_PIN) { wifi_status_led_uninstall(); } PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]); GPIO_OUTPUT_SET(pin, 0); os_sprintf(buffer, "%d=OUTPUT\r\n", pin); } else if ((mode == 'p') || (mode == 'P')) { if (pin == STATUS_LED_PIN) { wifi_status_led_uninstall(); } PIN_FUNC_SELECT(pinMap[pin], pinFunction[pin]); GPIO_DIS_OUTPUT(pin); PIN_PULLUP_EN(pinMap[pin]); os_sprintf(buffer, "%d=INPUT_PULLUP\r\n", pin); } else { at_response_error(); return; } at_port_print(buffer); at_response_ok(); }