#ifndef __HERMIT_CRAB_H #define __HERMIT_CRAB_H #include #ifndef ESP32 #define ESP32 #endif #define USE_BLE #ifdef USE_BLE #define THIS_DEVICE_TYPE ENUM_DEVICE_TYPE::TYPE_BETA_BLE #define MY_IRAM_ATTR #else #define THIS_DEVICE_TYPE ENUM_DEVICE_TYPE::TYPE_BETA #define MY_IRAM_ATTR IRAM_ATTR #endif // Define DEBUG flag #ifndef DEBUG #define DEBUG 1 // Set to 0 to disable debug output #endif #undef DEBUG //#define BLE_DEBUG #ifdef BLE_DEBUG #ifndef DEBUG #define DEBUG 1 #endif #endif // Debug print macros #if defined(DEBUG) #define DPRINT(...) Serial.print(__VA_ARGS__) #define DPRINTLN(...) Serial.println(__VA_ARGS__) #define DPRINTF(...) Serial.printf(__VA_ARGS__) #else #define DPRINT(...) // Do nothing #define DPRINTLN(...) // Do nothing #define DPRINTF(...) // Do nothing #endif #ifndef SIGNATURE1 #define SIGNATURE1 ((uint16_t) 0xC8AB) #endif #ifndef SIGNATURE2 #define SIGNATURE2 ((uint16_t) 0x4E81) #endif #define KALVIN (273.125f) #define LIGHT_ON HIGH #define LIGHT_OFF LOW #define HUMID_ON HIGH #define HUMID_OFF LOW #define HEATER_ON HIGH #define HEATER_OFF LOW #define LED_ON LOW #define LED_OFF HIGH #define SEGMENT_ON LOW #define SEGMENT_OFF HIGH // ======================= // PIN Definitions // // LEFT #define PIN_NTC 39 // Input Only #define PIN_ZCD_LOAD 34 // Input Only #define PIN_ZCD_AC 35 // Input Only #define PIN_HEATER1 32 #define PIN_HEATER2 33 #define PIN_LIGHT 25 #define PIN_MOTOR 26 #define PIN_FAN 27 #define PIN_MIST 14 // Outputs PWM signal at boot #define PIN_NONE_1 12 // boot fails if pulled high, strapping pin // BOTTOM #define PIN_NONE_2 13 #define PIN_NONE_6 15 // Outputs PWM signal at Boot, strapping pin #define PIN_NONE_5 2 // RIGHT #define PIN_LED_WIFI 0 // pulled up outputs PWM signal at boot, must be LOW to enter flashing mode #define PIN_NONE_4 4 #define PIN_LED_HEATER2 16 #define PIN_LED_HEATER1 17 #define PIN_SW_DOWN 5 #define PIN_SW_UP 18 #define PIN_SW_SET 19 #define PIN_SDA 21 #define PIN_RX 3 #define PIN_TX 1 #define PIN_SCL 22 #define PIN_NONE_3 23 // End of PIN Definition // ======================= // Resolution for all Channels #define PWM_RESOLUTION 10 // 10-bit resolution #define PWM_FULL 1023 #define PWM_OFF 0 // High Speed Group - Motor and Fan (26KHz) #define PWM_MOTOR_CHANNEL 0 #define PWM_FAN_CHANNEL 1 // Medium Speed Group - LED & Heater (1KHz) #define PWM_LIGHT_CHANNEL 2 #define PWM_HEATER1_CHANNEL 3 #define PWM_HEATER2_CHANNEL 4 // Low Speed Group - Mist, WifiLED (1Hz) #define PWM_MIST_CHANNEL 8 #define PWM_WIFI_LED_CHANNEL 9 #define PWM_1HZ_FREQ 1 // 1 Hz #define PWM_1KHZ_FREQ 1221 // 1 kHz #define PWM_26KHZ_FREQ 26042 // 26KHz #define TAG "HC" enum EVENT_TYPE { // Temperature // Humidity // Light // Fan // Connection WiFi_Conneted, WiFi_Disconnected, BT_Connected, BT_Disconnected }; #define FLAG_MANUAL_HEATER1 (0x0001) #define FLAG_MANUAL_HEATER2 (0x0002) #define FLAG_MANUAL_MIST (0x0004) #define FLAG_MANUAL_FAN (0x0008) #define FLAG_MANUAL_MOTOR (0x0010) #define FLAG_MANUAL_LIGHT (0x0020) #define FLAG_ZCD_AC (0x0040) #define FLAG_ZCD_LOAD (0x0080) #define FLAG_ZCD (0x0100) #define FLAG_UPNP (0x0200) #define FLAG_BLE_BATT (0x0400) #define FLAG_BLE_NODATA (0x0800) #define FLAG_BLE_LOST (0x1000) #pragma pack(push) /* push current alignment to stack */ #pragma pack(1) /* set alignment to 1 byte boundary */ typedef struct DEVICE_PARAM_STRUCT { uint8_t nControlType; uint8_t x; uint8_t bDay, bNight; //4 uint16_t dutyMin, dutyMax, dutyStart; //6 + 4 = 10 union { uint16_t dutyDay; uint16_t dutyOn; uint16_t dutyDayOrOn; }; union { uint16_t dutyNight; uint16_t dutyOff; uint16_t dutyNightOrOff; }; //4 + 10 = 14 int16_t tempHigh, tempLow; uint16_t timeBegin, timeEnd; uint16_t periodPeriod, periodOn; uint16_t humidHigh, humidLow; //16 + 14 = 30 uint8_t extra[32 - 30]; } DEVICE_PARAM_TYPE; typedef struct STATUS_STRUCT { // Sensor int16_t nTemp1; int16_t nTemp2; int16_t nTemp3; int16_t nHumid1; int16_t nHumid2; // 10 // Control uint16_t nHeater1Duty; // (0..10000) uint16_t nHeater2Duty; // (0..10000) uint16_t nMistDuty; // uint16_t nFanDuty; // uint16_t nMotorDuty; uint16_t nLightDuty; uint16_t nLightTargetDuty; // 24 // Current Time uint32_t now; // 28 uint16_t nFlags; // 30 // AC status uint8_t zcdAC; uint8_t zcdLoad; // 32 } STATUS_TYPE; #pragma pack(pop) /* restore original alignment from stack */ // ======================================================= char *printStatus(unsigned long tick, bool bLong = false); char *printTime(bool bLong = false); void checkSerial(unsigned long tick); void checkWiFi(unsigned long tick); void checkWiFiHost(unsigned long tick); void core0Task(void *pvParameters); // ======================================================= // Status extern STATUS_TYPE status; // Time extern volatile unsigned short g_nYear, g_nMonth, g_nDay, g_nHour, g_nMinute, g_nSecond; // Environment extern bool bShowSensor; extern const char *COMPANY_NAME; extern const char *SERVICE_NAME; extern const char *HC__VERSION; #endif