/** * Show open hardware logo at startup */ static void ICACHE_FLASH_ATTR lcdInitTask(os_event_t *events) { static uint32_t loopIterations = 0; loopIterations+=1; if (loopIterations < 2) { // I wonder why the calls to initLCD in user_init doesn't 'take' PCD8544_initLCD(&pcd8544_settings); os_delay_us(50000); PCD8544_lcdImage(openhardware_logo); os_printf("Initiating display: %d\n", loopIterations); os_timer_disarm(&lcd_timer); os_timer_arm(&lcd_timer, user_procTaskPeriod, 0); } else if (loopIterations == 2){ PCD8544_lcdClear(); PCD8544_gotoXY(0,0); PCD8544_lcdPrint("mqtt topic:"); PCD8544_gotoXY(0,1); PCD8544_lcdPrint(clientid); } }
void ICACHE_FLASH_ATTR mqttDataCb(uint32_t *args, const char* topic, uint32_t topic_len, const char *data, uint32_t data_len) { char *topicBuf = (char*) os_zalloc(topic_len + 1), *dataBuf = (char*) os_zalloc(data_len + 1); MQTT_Client* client = (MQTT_Client*) args; os_memcpy(topicBuf, topic, topic_len); topicBuf[topic_len] = 0; char *sp = topicBuf; // string pointer accessing internals of topicBuf os_memcpy(dataBuf, data, data_len); dataBuf[data_len] = 0; INFO("Received topic: %s, data: %s [%d]\n", topicBuf, dataBuf, data_len); if (strncmp(sp, clientid, strlen(clientid)) == 0) { sp += strlen(clientid); } if (strcmp(sp, "/lcd0") == 0) { PCD8544_gotoXY(0,0); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if (strcmp(sp, "/lcd1") == 0) { PCD8544_gotoXY(0,1); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if (strcmp(sp, "/lcd2") == 0) { PCD8544_gotoXY(0,2); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if (strcmp(sp, "/lcd3") == 0) { PCD8544_gotoXY(0,3); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if (strcmp(sp, "/lcd4") == 0) { PCD8544_gotoXY(0,4); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if (strcmp(sp, "/lcd5") == 0) { PCD8544_gotoXY(0,5); PCD8544_lcdPrint(dataBuf); PCD8544_lcdPad(PCD8544_LCD_CHARS_PER_LINE-data_len); } else if ( (strcmp(topicBuf, "/lcd/contrast") == 0) || (strcmp(sp, "/contrast") == 0)) { uint8_t contrast = atoi(dataBuf); if (contrast>0){ // atoi("random non-numeric string") will return 0 INFO("Setting contrast to %d\n", contrast); PCD8544_setContrast(contrast); } } else if ((strcmp(topicBuf, "/lcd/clearscreen") == 0) || (strcmp(sp, "/clearscreen") == 0)) { PCD8544_lcdClear(); } os_free(topicBuf); os_free(dataBuf); }
void ICACHE_FLASH_ATTR mb_pcd8544_handler( struct espconn *pConnection, request_method method, char *url, char *data, uint16 data_len, uint32 content_len, char *response, uint16 response_len ) { struct jsonparse_state parser; int type; char tmp_str[20]; mb_pcd8544_config_t *p_config = mb_p_pcd8544_config; bool is_post = (method == POST); int start_cmd = -1; // 0=STOP, 1=START other none uint8 tmp_ret = 0xFF; // post config for INIT if (method == POST && data != NULL && data_len != 0) { jsonparse_setup(&parser, data, data_len); while ((type = jsonparse_next(&parser)) != 0) { if (type == JSON_TYPE_PAIR_NAME) { if (jsonparse_strcmp_value(&parser, "Reset_pin") == 0) { jsonparse_next(&parser);jsonparse_next(&parser); p_config->resetPin = jsonparse_get_value_as_sint(&parser); MB_PCD8544_DEBUG("PCD8544:CFG:Reset_pin:%d\n", p_config->resetPin); } else if (jsonparse_strcmp_value(&parser, "Sce_pin") == 0) { jsonparse_next(&parser);jsonparse_next(&parser); p_config->scePin = jsonparse_get_value_as_sint(&parser); MB_PCD8544_DEBUG("PCD8544:CFG:Sce_pin:%d\n", p_config->scePin); } else if (jsonparse_strcmp_value(&parser, "Dc_pin") == 0) { jsonparse_next(&parser);jsonparse_next(&parser); p_config->dcPin = jsonparse_get_value_as_sint(&parser); MB_PCD8544_DEBUG("PCD8544:CFG:Dc_pin:%d\n", p_config->dcPin); } else if (jsonparse_strcmp_value(&parser, "Sdin_pin") == 0) { jsonparse_next(&parser);jsonparse_next(&parser); p_config->sdinPin = jsonparse_get_value_as_sint(&parser); MB_PCD8544_DEBUG("PCD8544:CFG:Sdin_pin:%d\n", p_config->sdinPin); } else if (jsonparse_strcmp_value(&parser, "Sclk_pin") == 0) { jsonparse_next(&parser);jsonparse_next(&parser); p_config->sclkPin = jsonparse_get_value_as_sint(&parser); MB_PCD8544_DEBUG("PCD8544:CFG:Sclk_pin: %d\n", p_config->sclkPin); } else if (tmp_ret = user_app_config_handler_part(&parser) != 0xFF){ // check for common app commands MB_PCD8544_DEBUG("PCD8544:CFG:APPCONFIG:%d\n", tmp_ret); } else if (jsonparse_strcmp_value(&parser, "Goto_xy") == 0) { // 11,22 is_post = false; jsonparse_next(&parser);jsonparse_next(&parser); char tmp_goto[32]; jsonparse_copy_value(&parser, tmp_goto, 32); char *p_comma = (char *)os_strstr(tmp_goto, ","); if (tmp_goto > 0 && p_comma - tmp_goto < 32) { char tmp_goto_[32]; strncpy(tmp_goto_, tmp_goto, p_comma - tmp_goto - 1); int goto_x = atoi(tmp_goto_); tmp_goto_[0] = 0x00; strncpy(tmp_goto_, p_comma+1, 32); int goto_y = atoi(tmp_goto_); PCD8544_gotoXY(goto_x, goto_y); MB_PCD8544_DEBUG("PCD8544:Goto_x/y:%d/%d\n", goto_x, goto_y); } MB_PCD8544_DEBUG("PCD8544:Goto_x/y:NA\n"); } else if (jsonparse_strcmp_value(&parser, "") == 0) { is_post = false; jsonparse_next(&parser);jsonparse_next(&parser); char tmp_str[128]; jsonparse_copy_value(&parser, tmp_str, MB_VARNAMEMAX); PCD8544_lcdPrint(tmp_str); MB_PCD8544_DEBUG("PCD8544:lcdPrint:%s\n", tmp_str); } } } if (is_post) { mb_pcd8544_hw_init(); } } mb_PCD8544_set_response(response, false, is_post ? MB_REQTYPE_POST : MB_REQTYPE_GET); }