void ICACHE_FLASH_ATTR esp8266_resolveCallback(const char* name, ip_addr_t* ip, void* arg)
{
    
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;
    uart0_tx_buffer("get conn\r\n", 10);
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(netConn);

    uart0_tx_buffer("check ip\r\n", 10);
    if(!ip)
    { // failed to lookup the hostname
        uart0_tx_buffer("bad ip\r\n", 8);
        esp8266_destroyConnection(netConn);
        netConn->readCallback(netConn->userData, NULL, 0, net_error);
        return;
    }

    char pageBuffer[20];
    ets_sprintf(pageBuffer, "r: %d.%d.%d.%d\r\n", IP2STR(ip));
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

    uart0_tx_buffer("set tcp callbacks\r\n", 19);
    espconn_regist_connectcb(conn, esp8266_connectCallback);
    espconn_regist_disconcb(conn, esp8266_disconnectCallback);
    espconn_regist_reconcb(conn, esp8266_reconnectCallback);
    uart0_tx_buffer("set callbacks\r\n", 15);
    espconn_regist_recvcb(conn, esp8266_recvCallback);
    espconn_regist_sentcb(conn, esp8266_sendCallback);

    uart0_tx_buffer("set ip\r\n", 8);
    ets_memcpy(&conn->proto.tcp->remote_ip, ip, 4);
    if(driver->secure)
    {
        uart0_tx_buffer("async sconnect\r\n", 16);
        conn->proto.tcp->remote_port = 443;
        
        ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

        sint8 r = espconn_secure_connect(conn);
        ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    }
    else
    {
        uart0_tx_buffer("async connect\r\n", 15);
        conn->proto.tcp->remote_port = 80;
        
        ets_sprintf(pageBuffer, "port: %d\r\n", conn->proto.tcp->remote_port);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));

        sint8 r = espconn_connect(conn);
        ets_sprintf(pageBuffer, "c_conn: %d\r\n", r);
        uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    }
}
//print exception log to Flash
void ICACHE_FLASH_ATTR
stack_dump(struct rst_info *info, uint32 sp)
{
    uint32 i;
	uint8 log_buf[200];
    const char* pad = "    ";
	int len;
    if(info->reason == REASON_WDT_RST || info->reason == REASON_SOFT_WDT_RST
    || info->reason == REASON_EXCEPTION_RST) {

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"stack sp is %08x\n",sp);
    len = os_strlen(log_buf);
	if(len%4!=0) ets_memcpy(log_buf+len,pad, 4 - (len%4));
	ESP_DBG("Stack sp is %08x\n",sp);
    debug_DumpToFlash(log_buf,os_strlen(log_buf));

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"*** stack dump start ***\n");
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
    debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("*** Stack dump start ***\n");

	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"PC = 0x%08x\n",info->epc1);
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
    debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("DBG PC = 0x%08x\n",info->epc1);

    for (i = sp; i < 0x40000000; i+=16) {
        uint32 *val = (uint32 *)i;
		ets_memset(log_buf,0,sizeof(log_buf));
        ets_sprintf(log_buf,"%08x: %08x %08x %08x %08x\n", i, *val, *(val + 1), *(val + 2), *(val + 3));
		len = os_strlen(log_buf);
		if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
		debug_DumpToFlash(log_buf,os_strlen(log_buf));
		ESP_DBG("%08x: %08x %08x %08x %08x\n", i, *val, *(val + 1), *(val + 2), *(val + 3));
    }
	ets_memset(log_buf,0,sizeof(log_buf));
    ets_sprintf(log_buf,"*** stack dump end ***\n");
    len = os_strlen(log_buf);
	if(len%4!=0) os_memcpy(log_buf+len,pad, 4 - (len%4));
	debug_DumpToFlash(log_buf,os_strlen(log_buf));
	ESP_DBG("*** Stack dump end ***\n");
    }
Example #3
0
// Lua: client/server/socket:getaddr()
int net_getaddr( lua_State *L ) {
  lnet_userdata *ud = net_get_udata(L);
  if (!ud) return luaL_error(L, "invalid user data");
  if (!ud->pcb) {
    lua_pushnil(L);
    lua_pushnil(L);
    return 2;
  }
  uint16_t port;
  ip_addr_t addr;
  switch (ud->type) {
    case TYPE_TCP_CLIENT:
    case TYPE_TCP_SERVER:
      addr = ud->tcp_pcb->local_ip;
      port = ud->tcp_pcb->local_port;
      break;
    case TYPE_UDP_SOCKET:
      addr = ud->udp_pcb->local_ip;
      port = ud->udp_pcb->local_port;
      break;
  }
  if (port == 0) {
    lua_pushnil(L);
    lua_pushnil(L);
    return 2;
  }
  char addr_str[16];
  bzero(addr_str, 16);
  ets_sprintf(addr_str, IPSTR, IP2STR(&addr.addr));
  lua_pushinteger(L, port);
  lua_pushstring(L, addr_str);
  return 2;
}
Example #4
0
static void net_recv_cb(lnet_userdata *ud, struct pbuf *p, ip_addr_t *addr, u16_t port) {
  if (ud->client.cb_receive_ref == LUA_NOREF) {
    pbuf_free(p);
    return;
  }

  int num_args = 2;
  char iptmp[16] = { 0, };
  if (ud->type == TYPE_UDP_SOCKET)
  {
    num_args += 2;
    ets_sprintf(iptmp, IPSTR, IP2STR(&addr->addr));
  }

  lua_State *L = lua_getstate();
  struct pbuf *pp = p;
  while (pp)
  {
    lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_receive_ref);
    lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref);
    lua_pushlstring(L, pp->payload, pp->len);
    if (ud->type == TYPE_UDP_SOCKET) {
      lua_pushinteger(L, port);
      lua_pushstring(L, iptmp);
    }
    lua_call(L, num_args, 0);
    pp = pp->next;
  }
  pbuf_free(p);
}
Example #5
0
static void net_dns_cb(const char *name, ip_addr_t *ipaddr, void *arg) {
  ip_addr_t addr;
  if (ipaddr != NULL) addr = *ipaddr;
  else addr.addr = 0xFFFFFFFF;
  lnet_userdata *ud = (lnet_userdata*)arg;
  if (!ud) return;
  lua_State *L = lua_getstate();
  if (ud->self_ref != LUA_NOREF && ud->client.cb_dns_ref != LUA_NOREF) {
    lua_rawgeti(L, LUA_REGISTRYINDEX, ud->client.cb_dns_ref);
    lua_rawgeti(L, LUA_REGISTRYINDEX, ud->self_ref);
    if (addr.addr != 0xFFFFFFFF) {
      char iptmp[16];
      bzero(iptmp, 16);
      ets_sprintf(iptmp, IPSTR, IP2STR(&addr.addr));
      lua_pushstring(L, iptmp);
    } else {
      lua_pushnil(L);
    }
    lua_call(L, 2, 0);
  }
  ud->client.wait_dns --;
  if (ud->pcb && ud->type == TYPE_TCP_CLIENT && ud->tcp_pcb->state == CLOSED) {
    tcp_connect(ud->tcp_pcb, &addr, ud->tcp_pcb->remote_port, net_connected_cb);
  } else if (!ud->pcb && ud->client.wait_dns == 0) {
    lua_gc(L, LUA_GCSTOP, 0);
    luaL_unref(L, LUA_REGISTRYINDEX, ud->self_ref);
    ud->self_ref = LUA_NOREF;
    lua_gc(L, LUA_GCRESTART, 0);
  }
}
Example #6
0
void Tcp::loadEspconn(struct espconn* pconn) {
	_conn = pconn;
	if (pconn) {
		ets_sprintf(_host, "%d.%d.%d.%d", pconn->proto.tcp->remote_ip[0],
				pconn->proto.tcp->remote_ip[1], pconn->proto.tcp->remote_ip[2],
				pconn->proto.tcp->remote_ip[3]);
		_remote_port = pconn->proto.tcp->remote_port;
		os_memcpy(&_remote_ip, pconn->proto.tcp->remote_ip, 4);
	}
}
Example #7
0
void microrl_set_prompt(char* prompt)
{
	if (strlen(prompt) + 4 > CONFIG_PROMPT_BUF) {
		console_printf("error: prompt too long - inrease CONFIG_PROMPT_BUF\n");
		return;
	}	

	ets_sprintf(current_prompt, "\n%s > ", prompt);
	current_prompt_len = strlen(prompt) + 3;
}
void ICACHE_FLASH_ATTR esp8266_recvCallback(void* arg, char* buffer, unsigned short size)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "rx: %d\r\n", size);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    netConn->readCallback(netConn->userData, buffer, size, net_ok);
}
void ICACHE_FLASH_ATTR esp8266_reconnectCallback(void* arg, sint8 err)
{
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "recon: %d\r\n", err);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    struct espconn* conn = (struct espconn*)arg;
    NetConnection* netConn = (NetConnection*)conn->reverse;

    esp8266_destroyConnection(netConn);
    netConn->readCallback(netConn->userData, NULL, 0, net_error);
}
Example #10
0
static void ICACHE_FLASH_ATTR
procTask(os_event_t *events)
{
	system_os_post(procTaskPrio, 0, 0 );

	CSTick( 0 );
	TickAVRSoftSPI(0);

	if( events->sig == 0 && events->par == 0 )
	{
		//Idle Event.
		struct station_config wcfg;
		char stret[256];
		char *stt = &stret[0];
		struct ip_info ipi;

		int stat = wifi_station_get_connect_status();

//		printf( "STAT: %d\n", stat );

		if( stat == STATION_WRONG_PASSWORD || stat == STATION_NO_AP_FOUND || stat == STATION_CONNECT_FAIL )
		{
			wifi_set_opmode_current( 2 );
			stt += ets_sprintf( stt, "Connection failed: %d\n", stat );
			uart0_sendStr(stret);
		}

		if( stat == STATION_GOT_IP && !printed_ip )
		{
			wifi_station_get_config( &wcfg );
			wifi_get_ip_info(0, &ipi);
			stt += ets_sprintf( stt, "STAT: %d\n", stat );
			stt += ets_sprintf( stt, "IP: %d.%d.%d.%d\n", (ipi.ip.addr>>0)&0xff,(ipi.ip.addr>>8)&0xff,(ipi.ip.addr>>16)&0xff,(ipi.ip.addr>>24)&0xff );
			stt += ets_sprintf( stt, "NM: %d.%d.%d.%d\n", (ipi.netmask.addr>>0)&0xff,(ipi.netmask.addr>>8)&0xff,(ipi.netmask.addr>>16)&0xff,(ipi.netmask.addr>>24)&0xff );
			stt += ets_sprintf( stt, "GW: %d.%d.%d.%d\n", (ipi.gw.addr>>0)&0xff,(ipi.gw.addr>>8)&0xff,(ipi.gw.addr>>16)&0xff,(ipi.gw.addr>>24)&0xff );
			stt += ets_sprintf( stt, "WCFG: /%s/%s/\n", wcfg.ssid, wcfg.password );
			uart0_sendStr(stret);
			printed_ip = 1;
		}
	}
void ICACHE_FLASH_ATTR net_asyncWrite(NetConnection* conn, const void* data, size_t size)
{   
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "tx: %d\r\n", size);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    HTTPESP8266ConnectionData* driver = esp8266_getConnection(conn);
    uint16 writeSize = size <= 65535 ? size : 65535;
    driver->writeData = data + writeSize;
    driver->writeDataSize = size - writeSize;
    if(driver->secure)
        espconn_secure_sent(&driver->connection, (uint8*)data, writeSize);
    else
        espconn_sent(&driver->connection, (uint8*)data, writeSize);
}
int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len)
{
	char * buffend = buffer;

	switch( pusrdata[1] )
	{
	case 'C': case 'c': //Custom command test
	{
		buffend += ets_sprintf( buffend, "CC" );
		return buffend-buffer;
	}

	case 'l': case 'L': //LEDs
	{
		int i, it = 0;
		buffend += ets_sprintf( buffend, "CL:%d:", last_led_count );
		uint16_t toledsvals = last_led_count*3;
		if( toledsvals > 600 ) toledsvals = 600;
		for( i = 0; i < toledsvals; i++ )
		{
			uint8_t samp = last_leds[it++];
			*(buffend++) = tohex1( samp>>4 );
			*(buffend++) = tohex1( samp&0x0f );
		}
		return buffend-buffer;
	}
	case 'm': case 'M': //Mode
	{
		light_mode = pusrdata[2]-'0';
		buffend += ets_sprintf(buffend, "CM:%d",light_mode );
		return buffend-buffer;
	}


	}
	return -1;
}
void ICACHE_FLASH_ATTR net_asyncConnect(NetConnection* conn, const char* hostname)
{
    uart0_tx_buffer("connect\r\n", 9);
    HTTPESP8266ConnectionData* driver = esp8266_createConnection(conn);
    driver->secure = 1;
    char pageBuffer[20];
    ets_sprintf(pageBuffer, "r: %s\r\n", hostname);
    uart0_tx_buffer(pageBuffer, strlen(pageBuffer));
    err_t e = espconn_gethostbyname(&driver->connection, hostname, &driver->ip, esp8266_resolveCallback);
    switch(e)
    {
    case ESPCONN_OK: // dns cached, no async call
        esp8266_resolveCallback(hostname, &driver->ip, &driver->connection);
    case ESPCONN_INPROGRESS: // dns request queued, let callback happen
        return;
    default: // error fetching hostname
        esp8266_resolveCallback(hostname, NULL, &driver->connection);
    };
}
Example #14
0
// Lua: client:getpeer()
int net_getpeer( lua_State *L ) {
  lnet_userdata *ud = net_get_udata(L);
  if (!ud || ud->type != TYPE_TCP_CLIENT)
    return luaL_error(L, "invalid user data");
  if (!ud->pcb) {
    lua_pushnil(L);
    lua_pushnil(L);
    return 2;
  }
  uint16_t port = ud->tcp_pcb->remote_port;
  ip_addr_t addr = ud->tcp_pcb->remote_ip;
  if (port == 0) {
    lua_pushnil(L);
    lua_pushnil(L);
    return 2;
  }
  char addr_str[16];
  bzero(addr_str, 16);
  ets_sprintf(addr_str, IPSTR, IP2STR(&addr.addr));
  lua_pushinteger(L, port);
  lua_pushstring(L, addr_str);
  return 2;
}
void ICACHE_FLASH_ATTR user_init(void){
	DBG("user_init() started\n");
	//
	//prepare test vars and buffers
	wlcd_text_draw_settings_struct S;
	//
	char* Str = os_malloc(256);
	uint8_t* ImgData = os_malloc(11000); //arrays allocated by os_malloc() are also always 4-bytes aligned (at least on ESP8266 SDK). Make sure that the buffer is big enough
	if((Str==NULL)||(ImgData==NULL)) return; //os_malloc() failed => abort
	uint16_t W, H;
	uint32_t t, t2;
	uint16_t i;
	uint16_t DoneXOffs;
	uint16_t DoneYOffs;
	//
	//init display
	wlcd_init();
	//
#if(WLCD_BPP==WLCD_16BPP)
	wfof_get_file_data_fast(WFOF_IDX_WLCD_DEMO_16BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_WLCD_DEMO_16BPP);
#else
	wfof_get_file_data_fast(WFOF_IDX_WLCD_DEMO_24BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_WLCD_DEMO_24BPP);
#endif
	//
	while(1){
		//
		//---- WLCD test / demo intro (countdown)
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		//demo image
		wlcd_img_draw(ImgData, (WLCD_WIDTH-wlcd_img_get_width(ImgData))/2, ((WLCD_HEIGHT-wlcd_img_get_height(ImgData))/2)-10);
		//
		//test countdown
		S.X = 10;
		S.Y = 10;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0x5C, 0x20);
		S.FontIdx = 2;
		S.FontZoomAdd = 0;
		S.BoldAdd = 0;
		S.HSpc = 0;
		S.VSpc = 0;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = 40;
		S.WrapStyle = WLCD_WRAP_NONE;
		//
		wlcd_text_measure("DONE", &S, &W, &H);
		DoneXOffs = (WLCD_WIDTH-W)/2;
		DoneYOffs = (WLCD_HEIGHT-H)/2;
		//
#if(WLCD_DISPLAY==WLCD_ILI9341)
		ets_sprintf(Str, "WLCD %s, ILI9341, %d bpp", wlcd_get_version(), WLCD_BPP);
#elif(WLCD_DISPLAY==WLCD_ILI9488_KDv4_HACK)
		ets_sprintf(Str, "WLCD %s, ILI9488_KDv4_HACK, %d bpp", wlcd_get_version(), WLCD_BPP);
#elif(WLCD_DISPLAY==WLCD_ILI9488)
		ets_sprintf(Str, "WLCD %s, ILI9488, %d bpp", wlcd_get_version(), WLCD_BPP);
#endif
		wlcd_text_draw(Str, &S);
		//
		S.X = 10;
		S.Y = 25;
#ifdef WLCD_USE_HSPI
		ets_sprintf(Str, "HW mode, HSPI CLK = %d kHz", ((uint32_t)system_get_cpu_freq()*1000) / WLCD_SPI_CLK_PREDIV / WLCD_SPI_CLK_CNTDIV);
#else
		ets_sprintf(Str, "SW mode");
#endif
		wlcd_text_draw(Str, &S);
		//
		S.X = 10;
		S.Y = WLCD_HEIGHT - 10 - wlcd_text_nrows_height(1, &S) - 3;
		ets_sprintf(Str, "Test starts in ");
		wlcd_text_measure(Str, &S, &W, &H);
		wlcd_text_draw(Str, &S);
		//wlcd_text_draw_or_measure(Str, &S, 0, &W, &H); //this is also possible instead of two lines above
		//
		S.FontZoomAdd = 1;
		S.X = 10 + W;
		S.Y = WLCD_HEIGHT - 10 - wlcd_text_nrows_height(1, &S);
		S.MaxW = WLCD_WIDTH - 10 - S.X;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0xFF, 0xFF);
		for(i=50;i>0;i--){
			wlcd_rect_fill(S.X, S.Y, wlcd_text_nchars_width(5, &S), wlcd_text_nrows_height(1, &S), 0);
			//
			ets_sprintf(Str, "%d.%d s", i/10, i%10);
			wlcd_text_draw(Str, &S);
			//
			OS_DELAY_MS(100);
		}
		S.FontZoomAdd = 0;
		//
		//---- random lines / line speed test
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		//draw 1000 random lines
		t = system_get_time();
		for(i=0;i<1000;i++){
			wlcd_line_draw(
				RAND_0_TO_X(WLCD_WIDTH-1), RAND_0_TO_X(WLCD_HEIGHT-1),
				RAND_0_TO_X(WLCD_WIDTH-1), RAND_0_TO_X(WLCD_HEIGHT-1),
				WLCD_RGB_TO_COLOR(0b00111000, 0b00111100, 0b01111000));
			//
			if(i%50==0) system_soft_wdt_feed(); //prevent rebooting if this loop takes too long
		}
		t = system_get_time() - t;
		//
		//compensate for "rand()" calculation
		t2 = system_get_time();
		volatile uint16_t Tmp;
		for(i=0;i<1000;i++){
			Tmp = RAND_0_TO_X(WLCD_WIDTH-1);
			Tmp = RAND_0_TO_X(WLCD_HEIGHT-1);
			Tmp = RAND_0_TO_X(WLCD_WIDTH-1);
			Tmp = RAND_0_TO_X(WLCD_HEIGHT-1);
		}
		t2 = system_get_time() - t2;
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0xFF, 0xFF);
		S.X = DoneXOffs;
		S.Y = DoneYOffs;
		wlcd_text_draw("DONE", &S);
		//
		OS_DELAY_MS(1000);
		//
		//clear whole display (black) and show stats
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b01111000, 0b01111100, 0b11111000);
		S.X = 10;
		S.Y = 10;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = WLCD_HEIGHT-20;
		S.WrapStyle = WLCD_WRAP_WORDS;
		ets_sprintf(Str, "1000 random lines on display %dx%d took %d ms (compensated for \"rand()\" calculation)", WLCD_WIDTH, WLCD_HEIGHT, (t-t2)/1000);
		wlcd_text_draw(Str, &S);
		OS_DELAY_MS(5000);
		//
		//---- image draw / image speed test
		//
#if(WLCD_BPP==WLCD_16BPP)
		wfof_get_file_data_fast(WFOF_IDX_SMILEY_50X50_U16BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_SMILEY_50X50_U16BPP);
#else
		wfof_get_file_data_fast(WFOF_IDX_SMILEY_50X50_U24BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_SMILEY_50X50_U24BPP);
#endif
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		t = system_get_time();
		for(i=0;i<1000;i++){
			wlcd_img_draw(ImgData, RAND_0_TO_X(WLCD_WIDTH-1-50), RAND_0_TO_X(WLCD_HEIGHT-1-50));
			//
			if(i%50==0) system_soft_wdt_feed(); //prevent rebooting if this loop takes too long
		}
		t = system_get_time() - t;
		//
		S.Color.u32t = 0;
		S.X = DoneXOffs;
		S.Y = DoneYOffs;
		wlcd_text_draw("DONE", &S);
		//
		OS_DELAY_MS(1000);
		//
		//clear whole display (black) and show stats
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b11111000, 0b01111100, 0b01111000);
		S.X = 10;
		S.Y = 10;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = WLCD_HEIGHT-20;
		S.WrapStyle = WLCD_WRAP_WORDS;
		ets_sprintf(Str, "1000 images (50x50 pixels, uncompressed image) took %d ms", t/1000);
		wlcd_text_draw(Str, &S);
		OS_DELAY_MS(5000);
		//
		//---- text draw / text speed test
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		ets_sprintf(Str, "This is a test of text drawing of 60 chars and with wrapping");
		t = system_get_time();
		for(i=0;i<100;i++){
			S.X = 10 + RAND_0_TO_X(10);
			S.Y = 10 + RAND_0_TO_X(100);
			S.MaxW = WLCD_WIDTH - 10 - S.X;
			S.MaxH = WLCD_HEIGHT - 10 - S.Y;
			S.Color.u32t = RAND_0_TO_X(0xFFFFFF);
			wlcd_text_draw(Str, &S);
			//
			if(i%50==0) system_soft_wdt_feed(); //prevent rebooting if this loop takes too long
		}
		t = system_get_time() - t;
		//
		S.Color.u32t = 0;
		S.X = DoneXOffs;
		S.Y = DoneYOffs;
		wlcd_text_draw("DONE", &S);
		//
		OS_DELAY_MS(1000);
		//
		//clear whole display (black) and show stats
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b11111000, 0b01111100, 0b11111000);
		S.X = 10;
		S.Y = 10;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = WLCD_HEIGHT-20;
		S.WrapStyle = WLCD_WRAP_WORDS;
		ets_sprintf(Str, "100 text sentences of 60 letters with word wrapping took %d ms", t/1000);
		wlcd_text_draw(Str, &S);
		OS_DELAY_MS(5000);
		//
		//---- text / font test - code page 1250 test
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0x5C, 0x20);
		S.X = 10;
		S.Y = 10;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = WLCD_HEIGHT-20;
		S.WrapStyle = WLCD_WRAP_WORDS;
		wlcd_text_draw("This is a test of code page 1250 font text output:\n\nP°эЪernь ЮluЭouшk¤ k∙Є ·pьl ясbelskщ єdy.", &S);
		//
		OS_DELAY_MS(4000);
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0xFF, 0x00);
		S.FontZoomAdd = 1;
		wlcd_text_draw("P°эЪernь ЮluЭouшk¤ k∙Є ·pьl ясbelskщ єdy.", &S);
		//
		OS_DELAY_MS(3000);
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		S.Y = 10;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0x00, 0xFF, 0);
		S.FontZoomAdd = 0;
		S.FontIdx = 0;
		wlcd_text_draw("This is some text.", &S);
		//
		S.Y = 30;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0x00, 0xFF, 0xFF);
		S.BoldAdd = 1;
		wlcd_text_draw("And this is the same font bolder.", &S);
		//
		S.Y = 50;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b11000000, 0b00111100, 0b11111000);
		S.HSpc = 5;
		wlcd_text_draw("We can also add horiz./vert. spacing.", &S);
		//
		S.Y = 75;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b11111000, 0b00111100, 0b01111000);
		S.FontZoomAdd = 1;
		S.BoldAdd = 0;
		S.HSpc = 0;
		wlcd_text_draw("Or zoom ...", &S);
		//
		S.Y = 105;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b10010000, 0b11111100, 0b01111000);
		S.FontZoomAdd = 2;
		S.HSpc = 0;
		wlcd_text_draw("ZOOM", &S);
		//
		S.Y = 140;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b01000000, 0b10000000, 0b11111000);
		S.FontZoomAdd = 0;
		S.FontIdx = 3;
		wlcd_text_draw("Different font\n0123456789", &S);
		//
		S.Y = 180;
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0xFF, 0x00);
		S.FontIdx = 2;
		wlcd_text_draw("And another different font (you can generate your own fonts)", &S);
		//
		OS_DELAY_MS(6000);
		//
		//---- read display data RAM back into buffer as WLCD image and use it to draw many copies of that image
		//
#ifndef WLCD_NO_READ
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		for(i=0;i<50;i++){
			wlcd_line_draw(
				RAND_0_TO_X(WLCD_WIDTH-1), RAND_0_TO_X(WLCD_HEIGHT-1),
				RAND_0_TO_X(WLCD_WIDTH-1), RAND_0_TO_X(WLCD_HEIGHT-1),
				WLCD_RGB_TO_COLOR(0b01111000, 0b01111100, 0b01111000));
		}
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0b00001000, 0b11110100, 0b01111000);
		S.X = 10;
		S.Y = 10;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = WLCD_HEIGHT-20;
		S.WrapStyle = WLCD_WRAP_WORDS;
		wlcd_text_draw("It's also possible to read LCD memory into buffer - creating a WLCD image (uncompressed stream of pixels) and re-use this image", &S);
		//
		wlcd_line_draw(10   , 10   , 10+29, 10   , 0xFFFFFF);
		wlcd_line_draw(10+29, 10   , 10+29, 10+29, 0xFFFFFF);
		wlcd_line_draw(10+29, 10+29, 10   , 10+29, 0xFFFFFF);
		wlcd_line_draw(10   , 10+29, 10   , 10   , 0xFFFFFF);
		//
		uint32_t Ret = wlcd_img_get((uint32_t*)ImgData, 10, 10, 30, 30);
		for(i=0;i<WLCD_WIDTH-30;i+=35){
			wlcd_img_draw(ImgData, i, 100);
		}
		//
		OS_DELAY_MS(8000);
#endif
		//
		//---- logo, github address
		//
		//clear whole display (black)
		wlcd_rect_fill(0,0, WLCD_WIDTH, WLCD_HEIGHT, 0);
		//
		//demo image
#if(WLCD_BPP==WLCD_16BPP)
		wfof_get_file_data_fast(WFOF_IDX_WLCD_DEMO_16BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_WLCD_DEMO_16BPP);
#else
		wfof_get_file_data_fast(WFOF_IDX_WLCD_DEMO_24BPP, (uint32_t*)ImgData, 0, WFOF_SIZE_WLCD_DEMO_24BPP);
#endif
		wlcd_img_draw(ImgData, (WLCD_WIDTH-wlcd_img_get_width(ImgData))/2, ((WLCD_HEIGHT-wlcd_img_get_height(ImgData))/2)-20);
		//
		S.Color.u32t = WLCD_RGB_TO_COLOR(0xFF, 0x5C, 0x58);
		S.FontIdx = 1;
		S.X = 10;
		S.Y = WLCD_HEIGHT-40;
		S.MaxW = WLCD_WIDTH-20;
		S.MaxH = 40;
		S.VSpc = 4;
		S.WrapStyle = WLCD_WRAP_WORDS;
		wlcd_text_draw("https://github.com/wdim0/esp8266_fast_lcd_driver_hspi", &S);
		//
		OS_DELAY_MS(6000);
		//
		//----
		//
	}
	//
	//clean-up (yes, we never get here .. but it's always good to keep things structured)
	os_free(Str);
	os_free(ImgData);
}
Example #16
0
int ICACHE_FLASH_ATTR CustomCommand(char * buffer, int retsize, char *pusrdata, unsigned short len)
{
	char * buffend = buffer;

	switch( pusrdata[1] )
	{
	case 'C': case 'c': //Custom command test
	{
		buffend += ets_sprintf( buffend, "CC\n" );
		return buffend-buffer;
	}
	case 'A': case 'a': //AVR Commands
	{
		switch( pusrdata[2] )
		{
		case 'R': case 'r': 
		{
			buffend += ets_sprintf( buffend, "AR\n" );
			return buffend-buffer;
		}
		case 'F': case 'f': 
		{
			int i;
			char     md5h[48];
			char     md5hraw[48];
			MD5_CTX md5ctx;
			char * colon = (char *) ets_strstr( (char*)&pusrdata[3], "\t" );
			char * colon2 = (colon)?((char *)ets_strstr( (char*)(colon+1), "\t" )):0;

			if( !colon || !colon2 ) break;

			*colon = 0; colon++;
			*colon2 = 0; colon2++;


			uint32_t from = my_atoi( &pusrdata[3] );
			uint32_t len = my_atoi( colon );
			char * md5 = colon2;

			printf( "caffer %d %d %s\n", from, len, md5 );
			MD5Init( &md5ctx );
			if( keylen )
				MD5Update( &md5ctx, key, keylen );
			SafeMD5Update( &md5ctx, (uint8_t*)0x40200000 + from, len );
			MD5Final( md5hraw, &md5ctx );

			for( i = 0; i < 16; i++ )
			{
				ets_sprintf( md5h+i*2, "%02x", md5hraw[i] );
			}

			printf( "AVR Program MD5s: %s == %s\n", md5h, md5 );
			for( i = 0; i < 32; i++ )
			{
				if( md5[i] != md5h[i] )
				{
					break;
				}
			}

			if( i != 32 ) break;

			int r = ProgramAVRFlash( (uint8_t*)0x40200000+from, len );

			if( r )
			{
				buffend += ets_sprintf( buffend, "!CAF\t%d\r\n", r );
			}
			else
			{
				buffend += ets_sprintf( buffend, "CAF\r\n" );
			}

			return buffend-buffer;
		}
		default: break;
		}
		buffend += ets_sprintf( buffend, "!CA%c\t-99\r\n", pusrdata[2] );
		return buffend-buffer;
	}

	}
	return -1;
}