void ICACHE_FLASH_ATTR supla_esp_gpio_init(void) { switch_cfgbtn_state_check = 0; switch_cfgbtn_last_state = -1; switch_cfgbtn_counter = 0; #if defined(USE_GPIO3) || defined(UART_SWAP) system_uart_swap (); #endif ETS_GPIO_INTR_DISABLE(); GPIO_PORT_INIT; #ifdef USE_GPIO16_INPUT gpio16_input_conf(); #endif #ifdef USE_GPIO16_OUTPUT gpio16_output_conf(); #endif #ifdef USE_GPIO3 PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3); PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U); #endif #ifdef BTN_PULLUP #if CFG_PORT == 0 PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U); #elif CFG_PORT == 2 PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U); #elif CFG_PORT == 4 PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U); #elif CFG_PORT == 12 PIN_PULLUP_EN(PERIPHS_IO_MUX_MTDI_U); #elif CFG_PORT == 13 PIN_PULLUP_EN(PERIPHS_IO_MUX_MTCK_U); #elif CFG_PORT == 14 PIN_PULLUP_EN(PERIPHS_IO_MUX_MTMS_U); #endif #endif #ifdef LED_RED_PORT #if LED_RED_PORT != 16 gpio_pin_intr_state_set(GPIO_ID_PIN(LED_RED_PORT), GPIO_PIN_INTR_DISABLE); #endif #endif #ifdef LED_GREEN_PORT gpio_pin_intr_state_set(GPIO_ID_PIN(LED_GREEN_PORT), GPIO_PIN_INTR_DISABLE); #endif #ifdef LED_BLUE_PORT gpio_pin_intr_state_set(GPIO_ID_PIN(LED_BLUE_PORT), GPIO_PIN_INTR_DISABLE); #endif #ifdef RELAY1_PORT gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY1_PORT), GPIO_PIN_INTR_DISABLE); #endif #ifdef RELAY2_PORT gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY2_PORT), GPIO_PIN_INTR_DISABLE); #endif #ifdef ZAM_INPUT1 supla_esp_gpio_enable_input_port(ZAM_INPUT1); #endif #ifdef ZAM_INPUT2 supla_esp_gpio_enable_input_port(ZAM_INPUT2); #endif ETS_GPIO_INTR_ENABLE(); keys.key_num = 0; single_key[0] = key_init_single(CFG_PORT, supla_esg_gpio_cfg_pressed, supla_esg_gpio_manual_pressed); keys.key_num++; #if defined(BUTTON1_PORT) && defined(RELAY1_PORT) single_key[keys.key_num] = key_init_single(BUTTON1_PORT, NULL, supla_esg_gpio_button1_pressed); keys.key_num++; #endif #if defined(BUTTON1_PORT) && defined(RELAY1_PORT) single_key[keys.key_num] = key_init_single(BUTTON2_PORT, NULL, supla_esg_gpio_button2_pressed); keys.key_num++; #endif keys.single_key = single_key; keys.handler = supla_esp_key_intr_handler; #ifdef RELAY_STATE_RESTORE struct rst_info *rtc_info = system_get_rst_info(); #ifdef RELAY1_PORT if ( rtc_info->reason == 0 ) { supla_esp_gpio_relay1_hi(supla_esp_state.Relay1); } #endif #ifdef RELAY2_PORT if ( rtc_info->reason == 0 ) { supla_esp_gpio_relay2_hi(supla_esp_state.Relay2); } #endif #elif defined(RESET_RELAY_PORT) #ifdef RELAY1_PORT supla_esp_gpio_relay1_hi(RELAY_INIT_VALUE); #endif #ifdef RELAY2_PORT supla_esp_gpio_relay2_hi(RELAY_INIT_VALUE); #endif #endif key_init(&keys); GPIO_PORT_POST_INIT; supla_esp_gpio_init_time = system_get_time(); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { system_init_done_cb(user_init_done); // wifi_set_phy_mode(PHY_MODE_11N); // wifi_set_sleep_type(MODEM_SLEEP_T); #if UART0_SWAP stdout_disable(); system_uart_swap(); #endif #if UART1_ENABLE stdout_init(UART1); #endif // UART Devices #if DEVICE == PLUG user_plug_init(); #endif #if DEVICE == SWITCH1 user_switch1_init(); #endif #if DEVICE == SWITCH2 user_switch2_init(); #endif #if MOD_RFID_ENABLE mod_rfid_init(); #endif #if MOD_FINGER_ENABLE mod_finger_init(); #endif #if MOD_EMTR_ENABLE mod_emtr_init(); #endif devices_init(); debug("\n\nSDK version: %s\n", system_get_sdk_version()); debug("Firmware: %s\n", config_firmware_bin()); memory_info(); user_config_init(); user_config_load(); #if SSL_ENABLE user_config_load_private_key(); user_config_load_certificate(); #endif user_events_init(); // Scan webserver_register_handler_callback(DEVICES_URL, devices_handler); webserver_register_handler_callback(WIFI_SCAN_URL, wifi_scan_handler); // Native Devices #if BUTTON_ENABLE user_button_init(); #endif #if RELAY_ENABLE user_relay_init(); #endif #if ADC_ENABLE user_adc_init(); #endif #if BATTERY_ENABLE user_battery_init(); #endif #if I2C_ENABLE // I2C Devices i2c_master_gpio_init(); #if MOD_RGB_ENABLE mod_rgb_init(); #endif #if MOD_TC_MK2_ENABLE mod_tc_mk2_init(); #endif #if MOD_IO2_ENABLE mod_io2_init(); #endif #if MOD_IRDA_ENABLE mod_irda_init(); #endif #if DEVICE == DIMMER user_dimmer_init(); #endif #endif // SPI Devices #if MOD_LED_8x8_RGB_ENABLE mod_led_8x8_rgb_init(); #endif #if DEVICE == BADGE badge_init(); #endif key_init(); webserver_init(); }
void connectOk(IPAddress ip, IPAddress mask, IPAddress gateway) { //void connectOk() { String ipString = WifiStation.getIP().toString(); Serial.println("I'm CONNECTED to AP_SSID=" + wifi_sid.get(currWifiIndex) + " IP: " + ipString); //String ipString = ip.toString(); Serial.println("IP: " + ipString); startWebServer(); if (ipString.equals("192.168.1.115") || ipString.equals("192.168.1.110")) { // distance sensor Serial.println("MODE: LEUZE Distance sensor"); udp.listen(udpServerPort); Serial.begin(57600); deltat = 100000; system_uart_swap(); delegateDemoClass.begin(); reportTimer.initializeMs(100, reportAnalogue).start(); } else if (ipString.equals("192.168.1.113") || ipString.equals("192.168.1.112") || ipString.equals("192.168.1.21") || ipString.equals("192.168.43.154")) { // // 4 axis stepper driver Serial.setCallback(serialCallBack); Serial.println("MODE: 4 Axis Stepper driver"); Serial.println("Init ended."); Serial.println("Type 'help' and press enter for instructions."); Serial.println(); deltat = 2000; if (ipString.equals("192.168.1.112")) parseGcode("reassign x=0 y=3 e=1 z=2"); else if (ipString.equals("192.168.1.113")) parseGcode("reassign x=0 y=1 e=3 z=2"); reportTimer.initializeMs(300, reportStatus).start(); hardwareTimer.initializeUs(deltat, StepperTimerInt); hardwareTimer.startOnce(); } else if (ipString.equals("192.168.1.116")) { Serial.println("MODE: Encoder driver"); pinMode(encoder0PinA, INPUT); digitalWrite(encoder0PinA, HIGH); // turn on pullup resistor pinMode(encoder0PinB, INPUT); digitalWrite(encoder0PinB, HIGH); // turn on pullup resistor attachInterrupt(encoder0PinA, doEncoderA, GPIO_PIN_INTR_ANYEDGE); attachInterrupt(encoder0PinB, doEncoderB, GPIO_PIN_INTR_ANYEDGE); reportTimer.initializeMs(100, reportEncoderPosition).start(); } else if (ipString.equals("192.168.1.117")) { Ltc2400Spi = new SPISoft(PIN_DO, PIN_DI, PIN_CK, PIN_SS); Ltc2400Spi->begin(); reportTimer.initializeMs(300, readFromLTC2400).startOnce(); } else { Serial.setCallback(serialCallBack); } }