Ejemplo n.º 1
0
bool ICACHE_FLASH_ATTR EOJProfile::getRouting(Response& r,uint8_t eoj1,uint8_t eoj2,uint8_t eoj3,uint8_t epc,uint8_t pdc,uint8_t* edt){
	if(eoj1 != 0x0e){
		return false;
	}
	uint8_t resp;

	switch(epc){
	case 0x8a://getManufacturerCode(r,pdc,edt);
		ets_uart_printf("EOJProfile::getManufacturerCode\n");
		r.set(3,(uint8_t*)MANUFACTURER);
		return true;
	case 0x9d://getStatusChangeAnnouncementPropertyMap(r,pdc,edt);
		ets_uart_printf("EOJProfile::getStatusChangeAnnouncementPropertyMap\n");
		resp=0;
		r.set(1,&resp);
		return true;
	case 0x9e://getSetPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJProfile::getSetPropertyMap\n");
		uint8_t res[128];
		r.set((res[0]=getSetPropertyMap(res+1,pdc,edt))+1,(uint8_t*)res);
		return true;
	case 0x9f://getGetPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJProfile::getGetPropertyMap\n");
		r.set((res[0]=getGetPropertyMap(res+1,pdc,edt))+1,(uint8_t*)res);
		return true;
	default:
		return false;
	}
}
Ejemplo n.º 2
0
void ICACHE_FLASH_ATTR serverInit(const char *name, ip_addr_t *ip, void *arg) {
	int result;
	int i;
	static esp_tcp tcp;
	if (ip==NULL) {
#ifdef Debug
		ets_uart_printf("Nslookup failed :/ Trying again...\n");
#endif
		//network_start();
	}

	for (i = 0; i < MAX_CONN; i++) {
		connData[i].conn = NULL;
		connData[i].txbuffer = txbuffer[i];
		connData[i].txbufferlen = 0;
		connData[i].readytosend = true;
	}

	serverConn.type=ESPCONN_TCP;
	serverConn.state=ESPCONN_NONE;
	serverConn.proto.tcp=&serverTcp;
	serverConn.proto.tcp->local_port=espconn_port();
	serverConn.proto.tcp->remote_port=8080;
	os_memcpy(serverConn.proto.tcp->remote_ip, &ip->addr, 4);
	espconn_regist_connectcb(&serverConn, serverConnectCb);
	espconn_regist_recvcb(&serverConn, serverRecvCb);
	espconn_regist_reconcb(&serverConn, serverReconCb);
	espconn_regist_disconcb(&serverConn, serverDisconCb);
	result = espconn_connect(&serverConn); // Start connection
#ifdef Debug
	ets_uart_printf("Resultado da tentativa de conexa: %d\n",result);
#endif
}
Ejemplo n.º 3
0
static void ICACHE_FLASH_ATTR
senddata()
{
	char info[150];
	char tcpserverip[15];
	struct espconn *pCon = (struct espconn *)os_zalloc(sizeof(struct espconn));
	if (pCon == NULL)
	{
		#ifdef PLATFORM_DEBUG
		ets_uart_printf("TCP connect failed\r\n");
		#endif
		return;
	}
	pCon->type = ESPCONN_TCP;
	pCon->state = ESPCONN_NONE;
	os_sprintf(tcpserverip, "%s", TCPSERVERIP);
	uint32_t ip = ipaddr_addr(tcpserverip);
	pCon->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
	pCon->proto.tcp->local_port = espconn_port();
	pCon->proto.tcp->remote_port = TCPSERVERPORT;
	os_memcpy(pCon->proto.tcp->remote_ip, &ip, 4);
	espconn_regist_connectcb(pCon, at_tcpclient_connect_cb);
	//espconn_regist_reconcb(pCon, at_tcpclient_recon_cb);
	#ifdef PLATFORM_DEBUG
	os_sprintf(info,"Start espconn_connect to " IPSTR ":%d\r\n",
		   IP2STR(pCon->proto.tcp->remote_ip),
		   pCon->proto.tcp->remote_port);
	ets_uart_printf(info);
	#endif
	espconn_connect(pCon);
}
Ejemplo n.º 4
0
static void ICACHE_FLASH_ATTR tcpserver_reconnect_cb(void *arg, sint8 err)
{
	DEBUG("enter tcpserver_reconnect_cb");
	ets_uart_printf("Reconnect: err = %d\n", err);
	ets_uart_printf("\n");
	DEBUG("exit tcpserver_reconnect_cb");
}
Ejemplo n.º 5
0
// Status check function
void check_timerfunc(void *arg) {
    struct ip_info ipConfig;
    wifi_get_ip_info(STATION_IF, &ipConfig);
    if (ipConfig.ip.addr != 0) {
        connection_status = CONNECTION_CONNECTED;
        //ets_uart_printf("[check_timerfunc] Connected? ");
        ets_uart_printf("C %d.%d.%d.%d\r\n", IP2STR(&ipConfig.ip));
        //ets_uart_printf("C");

        if (mode == MODE_AP) {
            // Just Station and no AP
            setup_stationmode();
            // Turn off HTTP server
            stop_server();
        }

    } else if (connection_status == CONNECTION_CONNECTING) {
        ets_uart_printf("X");
        //print("[check_timerfunc] No IP");
    } else {
        ets_uart_printf("U");
        if (mode != MODE_AP) {
            // Setup AP and Server
            setup_ap();
            setup_server();
        }
    }
}
Ejemplo n.º 6
0
//============================================================================================================================
void setup_wifi_ap_mode(void)
{
	wifi_set_opmode((wifi_get_opmode()|STATIONAP_MODE)&STATIONAP_MODE);
	struct softap_config apconfig;
	if(wifi_softap_get_config(&apconfig))
	{
		wifi_softap_dhcps_stop();
		os_memset(apconfig.ssid, 0, sizeof(apconfig.ssid));
		os_memset(apconfig.password, 0, sizeof(apconfig.password));
		apconfig.ssid_len = os_sprintf(apconfig.ssid, configs.hwSettings.wifi.SSID);//"HA-HA-HA");
		os_sprintf(apconfig.password, "%s", configs.hwSettings.wifi.SSID_PASS);//"qwertyuiop");
		apconfig.authmode = configs.hwSettings.wifi.auth;//AUTH_OPEN;//AUTH_WPA_WPA2_PSK;
		apconfig.ssid_hidden = 0;
		apconfig.channel = 7;
		apconfig.max_connection = 4;
		if(!wifi_softap_set_config(&apconfig))
		{
			//#if DEBUG_LEVEL > 0
			ets_uart_printf("ESP8266 not set AP config!\r\n");
			//#endif
		};
		struct ip_info ipinfo;
		wifi_get_ip_info(SOFTAP_IF, &ipinfo);
		IP4_ADDR(&ipinfo.ip, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.gw, 192, 168, 4, 100);
		IP4_ADDR(&ipinfo.netmask, 255, 255, 255, 0);
		wifi_set_ip_info(SOFTAP_IF, &ipinfo);
		wifi_softap_dhcps_start();
	}
	//#if DEBUG_LEVEL > 0
	ets_uart_printf("ESP8266 in AP mode configured.\r\n");
	//#endif
}
void dump_ethernet_raw_packet(uint8 bInput, char* szMessage, uint8 *payload, int32 len)
{
	extern int g_modePacketDump;
	extern int g_modePacketInfo;
	extern uint8_t g_macFilterUse;
	extern uint8_t g_macFilter1[6];
	extern uint8_t g_macFilter2[6];

	if ( g_macFilterUse )
	{
		if ( memcmp(payload, g_macFilter1, 6)==0 && memcmp(payload+6, g_macFilter1, 6)==0 && memcmp(payload+6, g_macFilter2, 6)==0 && memcmp(payload+6, g_macFilter2, 6)==0 )
		{
			return;
		}
	}

	if ( g_modePacketDump==1 )
	{
		ets_uart_printf(szMessage);
		ets_uart_printf(" (%d)\r\n", len);
		wdump(payload, len);
	}

	if ( g_modePacketInfo==1 )
	{
		void packet_handler(uint32_t packet_length, const uint8_t *packet);
		packet_handler(len, payload);
	}
}
Ejemplo n.º 8
0
void IRAM_ATTR SystemClass::internalApplyFirmwareUpdate(uint32_t readFlashOffset, uint32_t targetFlashOffset, int firmwareSize, bool outputDebug)
{
	uint32_t to = targetFlashOffset;
	uint32_t from = readFlashOffset;
	int size = firmwareSize;

	const int unit = INTERNAL_FLASH_SECTOR_SIZE;
	char buf[unit];

	while (size > 0)
	{
		int sect = to / unit;
		if (outputDebug) ets_uart_printf("write: 0x%X -> 0x%X (sect: %d), %d\n", from, to, sect, size);
		spi_flash_erase_sector(sect);
		//ets_uart_printf("ers.");
		spi_flash_read(from, (uint32*)buf, unit);
		//ets_uart_printf("read.");
		spi_flash_write(to, (uint32*)buf, unit);
		//ets_uart_printf("wr.\r\n");
		from += unit;
		to += unit;
		size -= unit;
	}

	if (outputDebug) ets_uart_printf("Firmware upgrade finished\n");

	((void (*)(void))0x40000080)(); // Hardcore reset vector

	ets_wdt_enable();
	while (1)
		; // Reboot anyway!
}
Ejemplo n.º 9
0
void user_init(void)
{
    //Init uart
    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    os_delay_us(1000);

    ets_uart_printf("Booting...\r\n");

    // i2c
    i2c_init();

    if(!eeprom_writeByte(0x78,0x01,0x00))
    	ets_uart_printf("Write failed\n\r");

    //Disarm timer
    os_timer_disarm(&sensor_timer);

    //Setup timer
    os_timer_setfn(&sensor_timer, (os_timer_func_t *)sensor_timerfunc, NULL);

    //Arm timer for every 10 sec.
    os_timer_arm(&sensor_timer, 5000, 1);

    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Ejemplo n.º 10
0
bool ICACHE_FLASH_ATTR EOJDevice::getRouting(Response& r,uint8_t eoj1,uint8_t eoj2,uint8_t eoj3,uint8_t epc,uint8_t pdc,uint8_t* edt){
	if( eoj1 > 0x06 ){
		return false;
	}
	uint8_t resp;

	switch(epc){
	case 0x80://getOperationStatus(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getOperationStatus\n");
		resp=operating?0x30:0x31;
		r.set(1,&resp);
		return true;
	case 0x81://getInstallationLocation(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getInstallationLocation\n");
		resp=location;
		r.set(1,&resp);
		return true;
	case 0x82://getStandardVersionInformation(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getStandardVersionInformation\n");
		r.set(sizeof(getStandardVersionInformation),getStandardVersionInformation);
		return true;
	case 0x88://getFaultStatus(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getFaultStatus\n");
		resp=fault?0x41:0x42;
		r.set(1,&resp);
		return true;
	case 0x8a://getManufacturerCode(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getManufacturerCode\n");
		r.set(3,(uint8_t*)MANUFACTURER);
		return true;
	case 0x9b://getSetMPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getSetMPropertyMap\n");
		resp=0;
		r.set(1,&resp);
		return true;
	case 0x9c://getGetMPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getGetMPropertyMap\n");
		resp=0;
		r.set(1,&resp);
		return true;
	case 0x9d://getStatusChangeAnnouncementPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getStatusChangeAnnouncementPropertyMap\n");
		resp=0;
		r.set(1,&resp);
		return true;
	case 0x9e://getSetPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getSetPropertyMap\n");
		uint8_t res[128];
		r.set((res[0]=getSetPropertyMap(res+1,pdc,edt))+1,(uint8_t*)res);
		return true;
	case 0x9f://getGetPropertyMap(Response& r,uint8_t pdc,uint8_t* edt){
		ets_uart_printf("EOJDevice::getGetPropertyMap\n");
		r.set((res[0]=getGetPropertyMap(res+1,pdc,edt))+1,(uint8_t*)res);
		return true;
	default:
		return false;
	}
}
void analyze_sniff_udp(const struct sniff_udp *udp)
{
	char buffer[80];
	ets_uart_printf("+..............................................................+\r\n");
	ets_uart_printf("| UDP                                                          |\r\n");
	ets_uart_printf("+..............................................................+\r\n");
	os_sprintf(buffer,"| Source Port : %5d     Dest Port : %5d     Length : %5d |\r\n",htons(udp->uh_sport),htons(udp->uh_dport),htons(udp->uh_len));
	ets_uart_printf(buffer);
}
Ejemplo n.º 12
0
LOCAL void ICACHE_FLASH_ATTR hello_cb(void *arg)
{
	static int counter = 0;
	//ets_uart_printf("Hello World #%d!\r\n", counter++);
	//a.print();

	if (mySwitch.available()) {
		ets_uart_printf("going to read the value\n");
		int value = mySwitch.getReceivedValue();

		if (value == 0) {
			ets_uart_printf("Unknown encoding");
		} else {
			ets_uart_printf("Received ");
			ets_uart_printf("%d ", mySwitch.getReceivedValue() );
			ets_uart_printf(" / ");
			ets_uart_printf("%d ",  mySwitch.getReceivedBitlength() );
			ets_uart_printf("bit ");
			ets_uart_printf("Protocol: ");
			ets_uart_printf("%d\n",  mySwitch.getReceivedProtocol() );
		}

		mySwitch.resetAvailable();
	}
}
void analyze_sniff_icmp(const struct sniff_icmp *icmp)
{
	char buffer[80];
	ets_uart_printf("+..............................................................+\r\n");
	ets_uart_printf("| ICMP                                                         |\r\n");
	ets_uart_printf("+..............................................................+\r\n");
	os_sprintf(buffer,"| Type    %2d : %s                         |\r\n",icmp->icmp_type,analyze_icmp_type(icmp->icmp_type,icmp->icmp_code));
	ets_uart_printf(buffer);
	os_sprintf(buffer,"+ Identifier : %5d              Seq number : %5d           |\r\n",icmp->icmp_id,icmp->icmp_seq);
	ets_uart_printf(buffer);
}
Ejemplo n.º 14
0
void sensor_timerfunc(void *arg)
{
    uint8 data;
    char temp[80];
    data = eeprom_readByte(0x50,0x01);
    os_sprintf(temp, "Byte: %x \n\r",data);
    ets_uart_printf(temp);
    data = data + 1;
    if(!eeprom_writeByte(0x50,0x01,data))
        ets_uart_printf("Write failed\n\r");
}
Ejemplo n.º 15
0
static void ICACHE_FLASH_ATTR led(bool onOff) {

	if(onOff) {gpio_output_set(0, 1 << 12, 1 << 12, 0);ets_uart_printf("LED on\r\n");}
	else  {gpio_output_set(1 << 12, 0, 1 << 12, 0);ets_uart_printf("LED off\r\n");}

	if(LedState != onOff) {
		CoAP_NotifyResourceObservers(pLed_Res); //Notify all observers of change
		LedState = onOff;
	}

}
void analyze_sniff_ether(const struct sniff_ethernet *ethernet, uint32_t packet_length)
{
	char buffer[80];

	os_sprintf(buffer,"| ETHERNET                                         %5d bytes |\r\n", packet_length);
	ets_uart_printf(buffer);
	ets_uart_printf("+..............................................................+\r\n");
	os_sprintf(buffer,"| MAC Source : %02x-%02x-%02x-%02x-%02x-%02x  ->  Dest : %02x-%02x-%02x-%02x-%02x-%02x |\r\n",ethernet->ether_shost[0],ethernet->ether_shost[1],ethernet->ether_shost[2],ethernet->ether_shost[3],ethernet->ether_shost[4],ethernet->ether_shost[5],ethernet->ether_dhost[0],ethernet->ether_dhost[1],ethernet->ether_dhost[2],ethernet->ether_dhost[3],ethernet->ether_dhost[4],ethernet->ether_dhost[5]);
	ets_uart_printf(buffer);
	os_sprintf(buffer,"| Ether Type : 0x%04x %s                                |\r\n", ntohs(ethernet->ether_type),analyze_ether_type(ntohs(ethernet->ether_type)));
	ets_uart_printf(buffer);
}
Ejemplo n.º 17
0
void SystemClass::applyFirmwareUpdate(uint32_t readFlashOffset, uint32_t targetFlashOffset, int firmwareSize)
{
	ets_wdt_disable();
	noInterrupts();

	bool outputDebug = true; // For future

	if (outputDebug)
	{
		ets_uart_printf("Firmware upgrade started\n");
		ets_uart_printf("start write: 0x%X -> 0x%X %d\n", readFlashOffset, targetFlashOffset, firmwareSize);
	}
	internalApplyFirmwareUpdate(readFlashOffset, targetFlashOffset, firmwareSize, outputDebug);
}
Ejemplo n.º 18
0
static void ICACHE_FLASH_ATTR udpserver_sent_cb(void *arg)
{
	DEBUG("enter udpserver_sent_cb");
	uint32 remote_ip;
	int remote_port;

	ets_uart_printf("udpserver_sent_cb\n");
	remote_port = ((struct espconn *)arg)->proto.tcp->remote_port;
	remote_ip = *(uint32 *)((struct espconn *)arg)->proto.tcp->remote_ip;
	ets_uart_printf("Sent data to %s:%d!\n",
			inet_ntoa(remote_ip), remote_port);
	ets_uart_printf("\n");
	DEBUG("exit udpserver_sent_cb");
}
Ejemplo n.º 19
0
void ICACHE_FLASH_ATTR uplink_sendMessage(char* message)
{
  txPayload = message;

  sint8 sentStatus = espconn_sent(&connection, txPayload, os_strlen(txPayload));
  if (sentStatus == ESPCONN_OK) {
    connState = TCP_SENDING;
    ets_uart_printf("TCP sending message: %s\r\n", txPayload);
  } else {
    connState = TCP_SEND_ERROR;
    ets_uart_printf("ERROR: TCP send failed, disconnecting ...\r\n");
    espconn_disconnect(&connection);
  }
}
Ejemplo n.º 20
0
LOCAL void ICACHE_FLASH_ATTR clientDisconnectedCallback(void *arg)
{
  struct espconn *pespconn = arg;
  connState = TCP_DISCONNECTED;

  ets_uart_printf("TCP connection terminated\r\n");

  if (pespconn == NULL)
  {
    ets_uart_printf("ERROR: TCP connection is NULL!\r\n");
  }

  // trigger disconnect processing
  comProcessing();
}
Ejemplo n.º 21
0
/**
 * Simple logging function.
 *
 * Would be nice the add TCP client logging later and/or formatting of the
 * timestamp.
 */
void ICACHE_FLASH_ATTR console(char *fmt, ...)
{
	uint32 timestamp;

	timestamp = sntp_get_current_timestamp();

	va_list argp;
	va_start(argp, fmt);

	ets_uart_printf("%10.10u:", timestamp);
	ets_uart_printf(fmt, argp);
	// syslog(LOG_DEBUG | LOG_LOCAL0, fmt, argp);

	va_end(argp);
}
Ejemplo n.º 22
0
static void ICACHE_FLASH_ATTR tcpserver_connect_cb(void *arg)
{
	DEBUG("enter tcpserver_connect_cb");
	uint32 remote_ip;
	int remote_port;

	ets_uart_printf("tcpserver_connect_cb\n");
	remote_port = ((struct espconn *)arg)->proto.tcp->remote_port;
	remote_ip = *(uint32 *)((struct espconn *)arg)->proto.tcp->remote_ip;
	ets_uart_printf("New connection from %s:%d!\n",
			inet_ntoa(remote_ip), remote_port);

	ets_uart_printf("\n");
	DEBUG("exit tcpserver_connect_cb");
}
Ejemplo n.º 23
0
/**
 * open valve
 */
LOCAL void ICACHE_FLASH_ATTR valveOpen(SleeperStateT* sleeperState)
{
  // discharge capacitor as much as possible while powering up generator (this may also close valve if still open)
  GPIO_OUTPUT_SET(CLOSE_VALVE_GPIO, 1);

  // start generator
  GPIO_OUTPUT_SET(GENERATOR_GPIO, 1);
  os_delay_us(50000); // 50 ms -> us

  // stop discharging capacitor
  GPIO_OUTPUT_SET(CLOSE_VALVE_GPIO, 0);
  os_delay_us(20); // 20 us

  // open latching valve by charing capacitor
  GPIO_OUTPUT_SET(OPEN_VALVE_GPIO, 0);
  os_delay_us(VALVE_OPEN_PULSE_DURATION); // (250 ms) -> us

  // disable power to valve and disable generator
  GPIO_DIS_OUTPUT(OPEN_VALVE_GPIO);
  GPIO_OUTPUT_SET(GENERATOR_GPIO, 0);

  // update state
  if (!sleeperState->rtcMem.valveOpen)
  {
    sleeperState->rtcMem.valveOpen = true;
    sleeperState->rtcMem.totalOpenCount++;
  }
  sleeperState->rtcMem.valveOpenTime = now;
  ets_uart_printf("valveOpen\r\n");
}
Ejemplo n.º 24
0
/**
 * close valve
 */
LOCAL void ICACHE_FLASH_ATTR valveClose(SleeperStateT* sleeperState)
{
  // start generator, preset valve direction to close and wait for generator voltage to stablelize
  GPIO_OUTPUT_SET(GENERATOR_GPIO,  1);
  GPIO_OUTPUT_SET(OPEN_VALVE_GPIO, 1); // 1 -> VOUT2 = H
  os_delay_us(5000); // 5 ms -> us

  // close valve by enabling H-bridge
  GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 1);
  os_delay_us(62500); // 62.5 ms -> us

  // short circuit valve current
  GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 0);
  os_delay_us(1000); // 1 ms -> us

  // done, go to passive state
  valveDriverShutdown();

  // update state
  sleeperState->rtcMem.valveOpen = false;
  if (now > sleeperState->rtcMem.valveOpenTime)
  {
    sleeperState->rtcMem.totalOpenDuration += (now - sleeperState->rtcMem.valveOpenTime)/1000;
  }
  ets_uart_printf("valveClose\r\n");
}
Ejemplo n.º 25
0
/**
 * open valve
 */
LOCAL void ICACHE_FLASH_ATTR valveOpen(SleeperStateT* sleeperState)
{
  // start generator, preset valve direction to open and wait for generator voltage to stablelize
  GPIO_OUTPUT_SET(GENERATOR_GPIO,  1);
  GPIO_OUTPUT_SET(OPEN_VALVE_GPIO, 0);  // 0 -> VOUT1 = H
  os_delay_us(5000); // 5 ms -> us

  // open valve by enabling H-bridge
  GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 1);
  os_delay_us(VALVE_OPEN_PULSE_DURATION); // (250 ms) -> us

  // short circuit valve current
  GPIO_OUTPUT_SET(OPERATE_VALVE_GPIO, 0);
  os_delay_us(1000); // 1 ms -> us

  // done, go to passive state
  valveDriverShutdown();

  // update state
  if (!sleeperState->rtcMem.valveOpen)
  {
    sleeperState->rtcMem.valveOpen = true;
    sleeperState->rtcMem.totalOpenCount++;
  }
  sleeperState->rtcMem.valveOpenTime = now;
  ets_uart_printf("valveOpen\r\n");
}
Ejemplo n.º 26
0
/// @brief  Read parameters on SPI bus ILI9341 displays 
/// For those displays that do not have the EXTC pin asserted.
/// This undocumented command overrides the restriction for reading 
/// command parameters.
/// Notes:
/// SPI configurations
/// See M:[0-3] control bits in ILI9341 documenation
///      - Refer to interface I and II modes. 
///        Most ILI9341 displays are using interface I,
///        (Rather the interface II mode)
/// @param[in] command: command whose parameters we want to read 
/// @param[in] parameter: parameter number
/// @return 16bit value
MEMSPACE
uint32_t tft_readRegister(uint8_t command, uint8_t parameter)
{
    uint32_t result;

	tft_spi_begin();

	// Send Undocumented ILI9341 0xd9 as COMMAND
    tft_Cmd(0xd9);

	// We do not know what the 0x10 offset implies, undocumented, but is required.
	// Send ILI9341 parameter as DATA
	tft_Data(0x10 + parameter);

	// The real ILI9341 Command whose parameters we want to read
	// Send ILI9341 command as COMMAND
	tft_Cmd(command);

	// Read Result
	result=tft_Data(0);

	tft_spi_end();


#if ILI9341_DEBUG & 1
ets_uart_printf("cmd:%02x, par:%02x, read: %02x\n",
	0xff & command, 
	0xff & parameter, 
	0xff & result);
#endif

    return (result);
}
Ejemplo n.º 27
0
/**
 * close valve
 */
LOCAL void ICACHE_FLASH_ATTR valveClose(SleeperStateT* sleeperState)
{
  // start generator
  GPIO_OUTPUT_SET(GENERATOR_GPIO, 1);
  os_delay_us(1000); // 1 ms -> us

  // recharge capacitor while bypassing valve
  GPIO_OUTPUT_SET(CAPACITOR_GPIO, 0);
  os_delay_us(50000); // 50 ms -> us

  // stop capacitor charging and disable generator
  GPIO_DIS_OUTPUT(CAPACITOR_GPIO);
  os_delay_us(20); // 20 us
  GPIO_OUTPUT_SET(GENERATOR_GPIO, 0);

  // close latching valve by discharging capacitor
  GPIO_OUTPUT_SET(CLOSE_VALVE_GPIO, 1);
  os_delay_us(62500); // 62.5 ms -> us

  // continue discharging capacitor until os shutdown

  // update state
  sleeperState->rtcMem.valveOpen = false;
  if (now > sleeperState->rtcMem.valveOpenTime)
  {
    sleeperState->rtcMem.totalOpenDuration += (now - sleeperState->rtcMem.valveOpenTime)/1000;
  }
  ets_uart_printf("valveClose\r\n");
}
Ejemplo n.º 28
0
static  __attribute__ ((section(".iram0.text"))) void uart0_rx_intr_handler(void *para)
{
    /* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
     * uart1 and uart0 respectively
     */
    //RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
    char RcvChar;

    if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST)) {
        return;
    }

    WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);

    while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
	    RcvChar = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
	    /* you can add your handle code below.*/
	    system_os_post(1, 0, RcvChar);

	    if (RcvChar == 114)
	    {
	    	ets_uart_printf("RcvChar \r\n");
	    }
    }

}
Ejemplo n.º 29
0
static void ICACHE_FLASH_ATTR serverReconCb(void *arg, sint8 err) {
	serverConnData *conn=serverFindConnData(arg);
#ifdef Debug
	ets_uart_printf("ReconCb\n");
#endif
	if (conn==NULL) return;
	//Yeah... No idea what to do here. ToDo: figure something out.
}
Ejemplo n.º 30
0
void sensor_timerfunc(void *arg)
{

    BME280_readSensorData();

	signed long int temp;
	temp = BME280_GetTemperature();
	unsigned long int press;
	press = BME280_GetPressure();
	unsigned long int hum;
	hum = BME280_GetHumidity();

	ets_uart_printf("Temp: %d.%d DegC, ", (int)(temp/100), (int)(temp%100));
  ets_uart_printf("Pres: %d.%d hPa, ", (int)(press/100), (int)(press%100));
  ets_uart_printf("Hum: %d.%d pct \r\n", (int)(hum/1024), (int)(hum%1024));

}