reorganize

This commit is contained in:
2021-06-23 17:12:40 +02:00
parent 708bb2cda4
commit f323bd4cf9
6 changed files with 199 additions and 211 deletions
+47 -58
View File
@@ -57,6 +57,9 @@ void timerCallback(void *pArg)
void handleNotFound();
HTTPServer httpServer(80, "/");
uint32_t _t=0;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); }
// ===============================================
@@ -87,58 +90,6 @@ void setup_pwm_pca9685() {
}
void setup() {
#ifdef WITH_DEBUGGING_ON
Serial.begin(460800);
gdbstub_init();
#else
Serial.begin(115200);
#endif
Serial.println(F("Booting ...."));
pinMode(NODEMCU_LED, OUTPUT);
pinMode(ESP12_LED, OUTPUT);
Wire.begin(); // Wire must be started first
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
os_timer_setfn(&timer1, timerCallback, &timer_flag);
os_timer_arm(&timer1, 20, true);
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ota_setup();
httpServer.start();
httpServer.onNotFound(handleNotFound);
Serial.println("HTTP server started !");
setup_pwm_pca9685();
Serial.println("PCA9685 connected !");
}
uint32_t t;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("µs")
#define TIMEIF_US(_str,_f, _l) t=micros(); _f; t=micros()-t; if(t > _l) { SP_US(_str, t); }
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval){
/*
@@ -233,13 +184,52 @@ void ledsequence(uint8_t direction, uint8_t onoff){
}
}
uint32_t _t=0;
#define SP_US(_str,_a) Serial.print(_str); Serial.print(" took: "); Serial.print(_a); Serial.println("us")
#define TIMEIF_US(_f, _l, _str) _t=micros(); _f; _t=micros()-_t; if(_t > _l) { SP_US(_str, _t); }
void setup() {
#ifdef WITH_DEBUGGING_ON
Serial.begin(460800);
gdbstub_init();
#else
Serial.begin(115200);
#endif
Serial.println(F("Booting ...."));
pinMode(NODEMCU_LED, OUTPUT);
pinMode(ESP12_LED, OUTPUT);
Wire.begin(); // Wire must be started first
Wire.setClock(1000000); // Supported baud rates are 100kHz, 400kHz, and 1000kHz
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
ota_setup();
httpServer.start();
httpServer.onNotFound(handleNotFound);
Serial.println("HTTP server started !");
setup_pwm_pca9685();
Serial.println("PCA9685 connected !");
os_timer_setfn(&timer1, timerCallback, &timer_flag);
os_timer_arm(&timer1, 20, true);
}
void loop() {
if(millis() > 25000 && onoff == 1 && direction == 1) onoff = 0;
if(millis() > 45000 && direction == 1){
onoff = 1;
@@ -247,5 +237,4 @@ void loop() {
}
TIMEIF_US(ArduinoOTA.handle(), 1000, "OTA");
TIMEIF_US(httpServer.handleClient(), 1000, "HTTP");
}