#include <WiFi.h>
#include "common.h"
//----------------------------------------
// #define CHIP_REPORT // Uncomment to enable CHIP_REPORT
#ifdef CHIP_REPORT
#include <chip-debug-report.h>
#endif // CHIP_REPORT
//----------------------------------------
#define MY_SSID1 "Kernel_Panic"
char *mychar = "mychar";
char *char1 = "char1";
char *char2 = new char;
const char *constchar;
// ======================================================================
// setup
void setup() {
#ifdef CHIP_REPORT
printBeforeSetupInfo();
PRINT_DASHED_LINES;
#endif // CHIP_REPORT
Serial.begin(115200);
/*
while (!Serial) {
delay(10);
}
*/
printf("\r\n------ Booting ESP ------------------------------------\r\n");
printf("Arduino IDE : %d.%d.%d \r\n", ARDUINO / 10000, ARDUINO % 10000 / 100, ARDUINO % 100 / 10 ? ARDUINO % 100 : ARDUINO % 10);
printf("Compiler ver. : %s \r\n", __VERSION__); // gcc version
printf("On Board : %s \r\n", ARDUINO_BOARD);
printf("Sketch name : %s \r\n", SKETCH_NAME.c_str());
printf("Sketch ver. : %s \r\n", SKETCH_VERSION);
printf("Build Date : %s \r\n", (__DATE__ ", " __TIME__)); // compilation date, time
printf("Author : Kernel Panic \r\n");
PRINT_DASHED_LINES;
pinMode(BUTTON_1, INPUT_PULLUP);
pinMode(BUTTON_2, INPUT_PULLUP);
for (uint8_t i = 0; i < NUM_OUT; i++) {
pinMode(LEDS[i], OUTPUT);
}
printESPinfo();
PRINT_DASHED_LINES;
#ifdef CHIP_REPORT
printAfterSetupInfo();
PRINT_DASHED_LINES;
#endif // CHIP_REPORT
//8888888888888888888888888888888888888888888888
mychar = char1;
printf("mychar : %s\n", mychar);
constchar = MY_SSID1;
printf("constchar : %s\n", constchar);
constchar = mychar;
printf("constchar : %s\n", constchar);
//8888888888888888888888888888888888888888888888
}
// ======================================================================
// Loop
void loop() {
static uint32_t pastSecs = millis();
static bool StateOut;
bool FlagBtn = isPressed(BUTTON_2);
if (WasPressed(BUTTON_1)) {
digitalWrite(LED_1, !digitalRead(LED_1));
}
if (WasPressed(BUTTON_2)) {
pastSecs = millis();
digitalWrite(LED_2, !digitalRead(LED_2));
}
// isPressedDB(BUTTON_2) ? digitalWrite(LED_3, HIGH) : digitalWrite(LED_3, LOW);
// FlagBtn ? digitalWrite(LED_3, HIGH) : digitalWrite(LED_3, LOW);
while ( FlagBtn && ((millis() - pastSecs) < 2150)) {
FlagBtn = isPressed(BUTTON_2);
yield();
digitalWrite(LED_3, millis() % 500 < 50);
StateOut = true;
}
if (StateOut) {
StateOut = false;
printf("[info] Waiting time : %.2f sec.\r\n", (millis() - pastSecs) / 1000.00);
}
// digitalWrite(LED_3, millis() % 500 < 50);
}
//=======================================================
// Buttons
//=======================================================
bool StableBtnLevel[NBR_BTNS]; //
//=== CheckButton =======================================
bool CheckButton(uint8_t Btn_pin) {
bool prvBtnLevel = StableBtnLevel[Btn_pin]; // the previous steady state from the input pin
bool newLevel = getBtnStableLevel(Btn_pin);
return prvBtnLevel != newLevel;
} //== Close CheckButton ==
bool getBtnStableLevel(uint8_t Btn_pin) {
static bool OLDbtnLevels[NBR_BTNS]; //
static uint32_t BtnPressTime;
// Reads a digital pin and filters it, returning the stable button position
bool pinLevel = digitalRead(Btn_pin);
if (pinLevel != OLDbtnLevels[Btn_pin]) {
BtnPressTime = millis();
OLDbtnLevels[Btn_pin] = pinLevel;
}
// Debounce
if ((millis() - BtnPressTime) > DB_MS) {
StableBtnLevel[Btn_pin] = pinLevel;
}
return StableBtnLevel[Btn_pin];
} //== Close getBtnStableLevel ===
// Read the state input pin
bool ReadThePin(uint8_t Pin) {
return digitalRead(Pin);
}
bool WasPressed(uint8_t Pin) {
return CheckButton(Pin) && !getBtnStableLevel(Pin);
}
bool WasReleased(uint8_t Pin) {
return CheckButton(Pin) && getBtnStableLevel(Pin);
}
// The button is pressed (with debounce)
bool isPressedDB(uint8_t Pin) {
return !getBtnStableLevel(Pin);
}
// The button is released (with debounce)
bool isReleasedDB(uint8_t Pin) {
return getBtnStableLevel(Pin);
}
// The button is pressed (without debounce)
bool isPressed(uint8_t Pin) {
return !ReadThePin(Pin);
}
// The button is released (without debounce)
bool isReleased(uint8_t Pin) {
return ReadThePin(Pin);
} //== End Buttons ===
/*********( END Code )***********/
//=======================================================================
// print informations ESP
void printESPinfo() {
//ESP info url: https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/Esp.h
printf("\n======== i n f o r m a t i o n s ====================\r\n");
printf("\t--- ESP info --- \r\n");
printf("Arduino core ver. : %s \r\n", ESP_ARDUINO_VERSION_STR); //version of this core
printf("ESP-IDF version : %s \r\n", ESP.getSdkVersion()); //version of ESP-IDF
printf("My Board is : %s \r\n", ARDUINO_BOARD);
printf("CPU Temperature : %.1f°C \r\n", temperatureRead());
printf("ESP Chip model : %s \r\n", GetChipModel());
printf("ESP Chip has : %d cores \r\n", ESP.getChipCores());
printf("ESP Chip ID : %d \r\n", GetChipId());
// printf("ESP Mac Address : %s \r\n", WiFi.macAddress().c_str()); //
printf("ESP CPU Frequency : %d MHz \r\n", ESP.getCpuFreqMHz());
printf("ESP Xtal Frequency : %d MHz \r\n", getXtalFrequencyMhz());
printf("ESP Flash chip Speed : %d MHz \r\n", ESP.getFlashChipSpeed() / 1000000UL);
printf("ESP SPI Flash Mode : %s \r\n", FlashChipMode[ESP.getFlashChipMode()]);
// Ram informations
printf("\t--- Ram informations ---\r\n");
printf("Total heap size : %s \r\n", formatBytes(ESP.getHeapSize()));
printf("Available Free Ram : %s \r\n", formatBytes(ESP.getFreeHeap()));
printf("Lowest free heap : %s \r\n", formatBytes(ESP.getMinFreeHeap())); //lowest level of free heap since boot
printf("Largest block heap : %s \r\n", formatBytes(ESP.getMaxAllocHeap())); //largest block of heap that can be allocated at once
printf("ESP Flash chip Size : %d MB \r\n", ESP.getFlashChipSize() / 1000000UL);
if (psramFound()) {
printf("Available Total PsRam : %s \r\n", formatBytes(ESP.getPsramSize()));
printf("Available Free PsRam : %s \r\n", formatBytes(ESP.getFreePsram()));
}
printf("Sketch Size : %s \r\n", formatBytes(ESP.getSketchSize()));
printf("Free Sketch Space : %s \r\n", formatBytes(ESP.getFreeSketchSpace()));
printf("======== END ESP informations =======================\r\n\n");
} //== Close printInfo ===