mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 13:46:36 +00:00
Extended device classes for ESP32 and ESP8266
This commit is contained in:
parent
8156e8ca33
commit
5692bb8b90
@ -1,9 +1,9 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
#warning Lanbon L8
|
#warning Lanbon L8
|
||||||
#elif defined(M5STACK)
|
#elif defined(M5STACK)
|
||||||
#warning M5 Stack
|
#warning M5 Stack
|
||||||
#else
|
#else
|
||||||
dev::BaseDevice haspDevice;
|
#warning Generic Device
|
||||||
#endif
|
#endif
|
@ -4,10 +4,19 @@
|
|||||||
#ifndef HASP_DEVICE_H
|
#ifndef HASP_DEVICE_H
|
||||||
#define HASP_DEVICE_H
|
#define HASP_DEVICE_H
|
||||||
|
|
||||||
|
#ifdef ARDUINO
|
||||||
|
#include "Arduino.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
class BaseDevice {
|
class BaseDevice {
|
||||||
public:
|
public:
|
||||||
|
bool has_battery = false;
|
||||||
|
bool has_backligth_control = true;
|
||||||
|
|
||||||
|
virtual void reboot()
|
||||||
|
{}
|
||||||
virtual void pre_setup()
|
virtual void pre_setup()
|
||||||
{}
|
{}
|
||||||
virtual void post_setup()
|
virtual void post_setup()
|
||||||
@ -16,19 +25,37 @@ class BaseDevice {
|
|||||||
{}
|
{}
|
||||||
virtual void loop_5s()
|
virtual void loop_5s()
|
||||||
{}
|
{}
|
||||||
|
virtual void set_backlight_pin(uint8_t pin)
|
||||||
|
{}
|
||||||
|
virtual void set_backlight_level(uint8_t level)
|
||||||
|
{}
|
||||||
|
virtual uint8_t get_backlight_level()
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
virtual void set_backlight_power(bool power)
|
||||||
|
{}
|
||||||
|
virtual bool get_backlight_power()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
#warning Building for ESP32 Devices
|
||||||
|
#include "dev/esp32/esp32.h"
|
||||||
|
#elif defined(ESP8266)
|
||||||
|
#warning Building for ESP8266 Devices
|
||||||
|
#include "dev/esp8266/esp8266.h"
|
||||||
|
#elif defined(STM32F4)
|
||||||
|
#warning Building for STM32F4xx Devices
|
||||||
|
#include "dev/stm32f4.h"
|
||||||
|
#else
|
||||||
|
#warning Building for Generic Devices
|
||||||
using dev::BaseDevice;
|
using dev::BaseDevice;
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
|
||||||
#warning Lanbon L8
|
|
||||||
#include "lanbonl8.h"
|
|
||||||
#elif defined(M5STACK)
|
|
||||||
#warning M5 Stack
|
|
||||||
#include "m5stackcore2.h"
|
|
||||||
#else
|
|
||||||
extern dev::BaseDevice haspDevice;
|
extern dev::BaseDevice haspDevice;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
84
src/dev/esp32/esp32.cpp
Normal file
84
src/dev/esp32/esp32.cpp
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include <Esp.h>
|
||||||
|
#include "esp_system.h"
|
||||||
|
|
||||||
|
#include "dev/device.h"
|
||||||
|
#include "dev/esp32/esp32.h"
|
||||||
|
|
||||||
|
#include "driver/adc.h"
|
||||||
|
#include "esp_adc_cal.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
#include "hasp_debug.h"
|
||||||
|
|
||||||
|
#define BACKLIGHT_CHANNEL 0
|
||||||
|
|
||||||
|
namespace dev {
|
||||||
|
|
||||||
|
void Esp32Device::reboot()
|
||||||
|
{
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32Device::set_backlight_pin(uint8_t pin)
|
||||||
|
{
|
||||||
|
Esp32Device::backlight_pin = pin;
|
||||||
|
/* Setup Backlight Control Pin */
|
||||||
|
if(pin >= 0) {
|
||||||
|
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||||
|
|
||||||
|
ledcSetup(BACKLIGHT_CHANNEL, 20000, 12);
|
||||||
|
ledcAttachPin(pin, BACKLIGHT_CHANNEL);
|
||||||
|
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32Device::set_backlight_level(uint8_t level)
|
||||||
|
{
|
||||||
|
backlight_level = level >= 0 ? level : 0;
|
||||||
|
backlight_level = backlight_level <= 100 ? backlight_level : 100;
|
||||||
|
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Esp32Device::get_backlight_level()
|
||||||
|
{
|
||||||
|
return backlight_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32Device::set_backlight_power(bool power)
|
||||||
|
{
|
||||||
|
backlight_power = power;
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Esp32Device::get_backlight_power()
|
||||||
|
{
|
||||||
|
return backlight_power != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp32Device::update_backlight()
|
||||||
|
{
|
||||||
|
if(backlight_pin == -1) return;
|
||||||
|
|
||||||
|
if(backlight_power) { // The backlight is ON
|
||||||
|
ledcWrite(BACKLIGHT_CHANNEL, map(backlight_level, 0, 100, 0, 4095)); // ledChannel and value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dev
|
||||||
|
|
||||||
|
#if defined(LANBONL8)
|
||||||
|
#warning Building for Lanbon L8
|
||||||
|
#include "dev/esp32/lanbonl8.h"
|
||||||
|
#elif defined(M5STACK)
|
||||||
|
#warning Building for M5Stack core2
|
||||||
|
#include "dev/esp32/m5stackcore2.h"
|
||||||
|
#else
|
||||||
|
dev::Esp32Device haspDevice;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // ESP32
|
51
src/dev/esp32/esp32.h
Normal file
51
src/dev/esp32/esp32.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
#ifndef HASP_DEVICE_ESP32_H
|
||||||
|
#define HASP_DEVICE_ESP32_H
|
||||||
|
|
||||||
|
#include "dev/device.h"
|
||||||
|
|
||||||
|
#if defined(ESP32)
|
||||||
|
|
||||||
|
namespace dev {
|
||||||
|
|
||||||
|
class Esp32Device : public BaseDevice {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void reboot() override;
|
||||||
|
|
||||||
|
void set_backlight_pin(uint8_t pin) override;
|
||||||
|
|
||||||
|
void set_backlight_level(uint8_t val) override;
|
||||||
|
|
||||||
|
uint8_t get_backlight_level() override;
|
||||||
|
|
||||||
|
void set_backlight_power(bool power) override;
|
||||||
|
|
||||||
|
bool get_backlight_power() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t backlight_pin;
|
||||||
|
uint8_t backlight_level;
|
||||||
|
uint8_t backlight_power;
|
||||||
|
|
||||||
|
void update_backlight();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dev
|
||||||
|
|
||||||
|
using dev::Esp32Device;
|
||||||
|
|
||||||
|
#if defined(LANBONL8)
|
||||||
|
#warning Building for Lanbon L8
|
||||||
|
#include "dev/esp32/lanbonl8.h"
|
||||||
|
#elif defined(M5STACK)
|
||||||
|
#warning Building for M5Stack core2
|
||||||
|
#include "dev/esp32/m5stackcore2.h"
|
||||||
|
#else
|
||||||
|
extern dev::Esp32Device haspDevice;
|
||||||
|
#endif
|
||||||
|
#endif // ESP32
|
||||||
|
|
||||||
|
#endif // HASP_DEVICE_ESP32_H
|
@ -1,13 +1,19 @@
|
|||||||
#include "lanbonl8.h"
|
#include "lanbonl8.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
#include "Arduino.h"
|
|
||||||
#include "../device.h"
|
|
||||||
|
|
||||||
#include "driver/adc.h"
|
#include "Arduino.h"
|
||||||
#include "esp_adc_cal.h"
|
#include "dev/esp32/esp32.h"
|
||||||
|
|
||||||
#define REF_VOLTAGE 1100
|
#include "driver/adc.h"
|
||||||
|
#include "esp_adc_cal.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
#include "hasp_debug.h"
|
||||||
|
|
||||||
|
#define BACKLIGHT_CHANNEL 0
|
||||||
|
|
||||||
|
#define REF_VOLTAGE 1100
|
||||||
esp_adc_cal_characteristics_t * adc_chars =
|
esp_adc_cal_characteristics_t * adc_chars =
|
||||||
new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
|
||||||
|
|
||||||
@ -55,19 +61,6 @@ void LanbonL8::pre_setup()
|
|||||||
print_char_val_type(val_type);
|
print_char_val_type(val_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LanbonL8::post_setup()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void LanbonL8::loop()
|
|
||||||
{}
|
|
||||||
|
|
||||||
void LanbonL8::loop_5s()
|
|
||||||
{
|
|
||||||
double voltage = esp_adc_cal_raw_to_voltage(analogRead(39), adc_chars);
|
|
||||||
Serial.print(adc1_get_raw(ADC1_CHANNEL_3));
|
|
||||||
Serial.print(" - ");
|
|
||||||
Serial.println(voltage);
|
|
||||||
}
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
dev::LanbonL8 haspDevice;
|
dev::LanbonL8 haspDevice;
|
@ -4,22 +4,17 @@
|
|||||||
#ifndef HASP_DEVICE_LANBONL8_H
|
#ifndef HASP_DEVICE_LANBONL8_H
|
||||||
#define HASP_DEVICE_LANBONL8_H
|
#define HASP_DEVICE_LANBONL8_H
|
||||||
|
|
||||||
#include "../device.h"
|
#include "dev/esp32/esp32.h"
|
||||||
|
|
||||||
#if defined(LANBONL8)
|
#if defined(LANBONL8)
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
class LanbonL8 : public BaseDevice {
|
class LanbonL8 : public Esp32Device {
|
||||||
public:
|
public:
|
||||||
void pre_setup() override;
|
void pre_setup();
|
||||||
|
|
||||||
void post_setup() override;
|
|
||||||
|
|
||||||
void loop() override;
|
|
||||||
|
|
||||||
void loop_5s() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
extern dev::LanbonL8 haspDevice;
|
extern dev::LanbonL8 haspDevice;
|
@ -1,8 +1,9 @@
|
|||||||
#include "m5stackcore2.h"
|
#include "m5stackcore2.h"
|
||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
#include "AXP192.h" // Power Mgmt
|
|
||||||
#include "../device.h"
|
#include "AXP192.h" // Power Mgmt
|
||||||
|
#include "dev/esp32/esp32.h"
|
||||||
|
|
||||||
// AXP192 Axp;
|
// AXP192 Axp;
|
||||||
namespace dev {
|
namespace dev {
|
||||||
@ -39,14 +40,6 @@ void M5StackCore2::pre_setup(void)
|
|||||||
Axp.SetLed(1);
|
Axp.SetLed(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void M5StackCore2::post_setup(void)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void M5StackCore2::loop(void)
|
|
||||||
{}
|
|
||||||
|
|
||||||
void M5StackCore2::loop_5s(void)
|
|
||||||
{}
|
|
||||||
} // namespace dev
|
} // namespace dev
|
||||||
|
|
||||||
dev::M5StackCore2 haspDevice;
|
dev::M5StackCore2 haspDevice;
|
@ -6,16 +6,13 @@
|
|||||||
|
|
||||||
#if defined(M5STACK)
|
#if defined(M5STACK)
|
||||||
|
|
||||||
#include "../device.h"
|
#include "dev/esp32/esp32.h"
|
||||||
|
|
||||||
namespace dev {
|
namespace dev {
|
||||||
|
|
||||||
class M5StackCore2 : public BaseDevice {
|
class M5StackCore2 : public Esp32Device {
|
||||||
public:
|
public:
|
||||||
void pre_setup() override;
|
void pre_setup() override;
|
||||||
void post_setup() override;
|
|
||||||
void loop() override;
|
|
||||||
void loop_5s() override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dev
|
} // namespace dev
|
66
src/dev/esp8266/esp8266.cpp
Normal file
66
src/dev/esp8266/esp8266.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#if defined(ESP8266)
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include <Esp.h>
|
||||||
|
|
||||||
|
#include "dev/esp8266/esp8266.h"
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
#include "hasp_debug.h"
|
||||||
|
|
||||||
|
#define BACKLIGHT_CHANNEL 0
|
||||||
|
|
||||||
|
namespace dev {
|
||||||
|
|
||||||
|
void Esp8266Device::reboot()
|
||||||
|
{
|
||||||
|
ESP.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp8266Device::set_backlight_pin(uint8_t pin)
|
||||||
|
{
|
||||||
|
Esp8266Device::backlight_pin = pin;
|
||||||
|
/* Setup Backlight Control Pin */
|
||||||
|
if(pin >= 0) {
|
||||||
|
LOG_VERBOSE(TAG_GUI, F("Backlight : Pin %d"), pin);
|
||||||
|
pinMode(backlight_pin, OUTPUT);
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp8266Device::set_backlight_level(uint8_t level)
|
||||||
|
{
|
||||||
|
backlight_level = level >= 0 ? level : 0;
|
||||||
|
backlight_level = backlight_level <= 100 ? backlight_level : 100;
|
||||||
|
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Esp8266Device::get_backlight_level()
|
||||||
|
{
|
||||||
|
return backlight_level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp8266Device::set_backlight_power(bool power)
|
||||||
|
{
|
||||||
|
backlight_power = power;
|
||||||
|
update_backlight();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Esp8266Device::get_backlight_power()
|
||||||
|
{
|
||||||
|
return backlight_power != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Esp8266Device::update_backlight()
|
||||||
|
{
|
||||||
|
if(backlight_pin == -1) return;
|
||||||
|
|
||||||
|
analogWrite(backlight_pin, backlight_power ? map(backlight_level, 0, 100, 0, 1023) : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace dev
|
||||||
|
|
||||||
|
dev::Esp8266Device haspDevice;
|
||||||
|
|
||||||
|
#endif // ESP8266
|
45
src/dev/esp8266/esp8266.h
Normal file
45
src/dev/esp8266/esp8266.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/* MIT License - Copyright (c) 2020 Francis Van Roie
|
||||||
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
|
#ifndef HASP_DEVICE_ESP8266_H
|
||||||
|
#define HASP_DEVICE_ESP8266_H
|
||||||
|
|
||||||
|
#include "hasp_conf.h"
|
||||||
|
#include "dev/device.h"
|
||||||
|
|
||||||
|
#if defined(ESP8266)
|
||||||
|
|
||||||
|
namespace dev {
|
||||||
|
|
||||||
|
class Esp8266Device : public BaseDevice {
|
||||||
|
|
||||||
|
public:
|
||||||
|
void reboot() override;
|
||||||
|
|
||||||
|
void set_backlight_pin(uint8_t pin) override;
|
||||||
|
|
||||||
|
void set_backlight_level(uint8_t val) override;
|
||||||
|
|
||||||
|
uint8_t get_backlight_level() override;
|
||||||
|
|
||||||
|
void set_backlight_power(bool power) override;
|
||||||
|
|
||||||
|
bool get_backlight_power() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint8_t backlight_pin;
|
||||||
|
uint8_t backlight_level;
|
||||||
|
uint8_t backlight_power;
|
||||||
|
|
||||||
|
void update_backlight();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace dev
|
||||||
|
|
||||||
|
using dev::Esp8266Device;
|
||||||
|
|
||||||
|
extern dev::Esp8266Device haspDevice;
|
||||||
|
|
||||||
|
#endif // ESP8266
|
||||||
|
|
||||||
|
#endif // HASP_DEVICE_ESP8266_H
|
@ -5,18 +5,18 @@
|
|||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#if defined(ESP8266)
|
#if defined(ESP8266)
|
||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#include "esp_system.h"
|
#include "esp_system.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <rom/rtc.h> // needed to get the ResetInfo
|
#include <rom/rtc.h> // needed to get the ResetInfo
|
||||||
|
|
||||||
// Compatibility function for ESP8266 getRestInfo
|
// Compatibility function for ESP8266 getRestInfo
|
||||||
String esp32ResetReason(uint8_t cpuid)
|
String esp32ResetReason(uint8_t cpuid)
|
||||||
@ -152,11 +152,11 @@ String halGetChipModel()
|
|||||||
case CHIP_ESP32:
|
case CHIP_ESP32:
|
||||||
model += F("ESP32");
|
model += F("ESP32");
|
||||||
break;
|
break;
|
||||||
#ifdef CHIP_ESP32S2
|
#ifdef CHIP_ESP32S2
|
||||||
case CHIP_ESP32S2:
|
case CHIP_ESP32S2:
|
||||||
model += F("ESP32-S2");
|
model += F("ESP32-S2");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
model = F("Unknown ESP32");
|
model = F("Unknown ESP32");
|
||||||
}
|
}
|
||||||
@ -174,19 +174,19 @@ String halGetChipModel()
|
|||||||
/* Memory Management Functions */
|
/* Memory Management Functions */
|
||||||
|
|
||||||
#if defined(STM32F4xx)
|
#if defined(STM32F4xx)
|
||||||
#include <malloc.h> // for mallinfo()
|
#include <malloc.h> // for mallinfo()
|
||||||
#include <unistd.h> // for sbrk()
|
#include <unistd.h> // for sbrk()
|
||||||
|
|
||||||
int freeHighMemory()
|
int freeHighMemory()
|
||||||
{
|
{
|
||||||
char top;
|
char top;
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
return &top - reinterpret_cast<char *>(sbrk(0));
|
return &top - reinterpret_cast<char *>(sbrk(0));
|
||||||
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
|
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
|
||||||
return &top - __brkval;
|
return &top - __brkval;
|
||||||
#else // __arm__
|
#else // __arm__
|
||||||
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
return __brkval ? &top - __brkval : &top - __malloc_heap_start;
|
||||||
#endif // __arm__
|
#endif // __arm__
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -260,14 +260,14 @@ String halGetMacAddress(int start, const char * seperator)
|
|||||||
|
|
||||||
#if defined(STM32F4xx)
|
#if defined(STM32F4xx)
|
||||||
uint8_t * mac_p = nullptr;
|
uint8_t * mac_p = nullptr;
|
||||||
#if HASP_USE_ETHERNET > 0
|
#if HASP_USE_ETHERNET > 0
|
||||||
#if USE_BUILTIN_ETHERNET > 0
|
#if USE_BUILTIN_ETHERNET > 0
|
||||||
mac_p = Ethernet.MACAddress();
|
mac_p = Ethernet.MACAddress();
|
||||||
for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i);
|
for(int i = 0; i < 6; i++) mac[i] = *(mac_p + i);
|
||||||
#else
|
#else
|
||||||
Ethernet.macAddress(mac);
|
Ethernet.macAddress(mac);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
#endif
|
#endif
|
||||||
@ -293,8 +293,6 @@ uint16_t halGetCpuFreqMHz()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String halDisplayDriverName()
|
String halDisplayDriverName()
|
||||||
{
|
{
|
||||||
#if defined(ILI9341_DRIVER)
|
#if defined(ILI9341_DRIVER)
|
||||||
@ -342,56 +340,56 @@ String halGpioName(uint8_t gpio)
|
|||||||
case PortName::PortB:
|
case PortName::PortB:
|
||||||
ioName = F("PB");
|
ioName = F("PB");
|
||||||
break;
|
break;
|
||||||
#if defined GPIOC_BASE
|
#if defined GPIOC_BASE
|
||||||
case PortName::PortC:
|
case PortName::PortC:
|
||||||
ioName = F("PC");
|
ioName = F("PC");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOD_BASE
|
#if defined GPIOD_BASE
|
||||||
case PortName::PortD:
|
case PortName::PortD:
|
||||||
ioName = F("PD");
|
ioName = F("PD");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOE_BASE
|
#if defined GPIOE_BASE
|
||||||
case PortName::PortE:
|
case PortName::PortE:
|
||||||
ioName = F("PE");
|
ioName = F("PE");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOF_BASE
|
#if defined GPIOF_BASE
|
||||||
case PortName::PortF:
|
case PortName::PortF:
|
||||||
ioName = F("PF");
|
ioName = F("PF");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOG_BASE
|
#if defined GPIOG_BASE
|
||||||
case PortName::PortG:
|
case PortName::PortG:
|
||||||
ioName = F("PG");
|
ioName = F("PG");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOH_BASE
|
#if defined GPIOH_BASE
|
||||||
case PortName::PortH:
|
case PortName::PortH:
|
||||||
ioName = F("PH");
|
ioName = F("PH");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOI_BASE
|
#if defined GPIOI_BASE
|
||||||
case PortName::PortI:
|
case PortName::PortI:
|
||||||
ioName = F("PI");
|
ioName = F("PI");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOJ_BASE
|
#if defined GPIOJ_BASE
|
||||||
case PortName::PortJ:
|
case PortName::PortJ:
|
||||||
ioName = F("PJ");
|
ioName = F("PJ");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOK_BASE
|
#if defined GPIOK_BASE
|
||||||
case PortName::PortK:
|
case PortName::PortK:
|
||||||
ioName = F("PK");
|
ioName = F("PK");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
#if defined GPIOZ_BASE
|
#if defined GPIOZ_BASE
|
||||||
case PortName::PortZ:
|
case PortName::PortZ:
|
||||||
ioName = F("PZ");
|
ioName = F("PZ");
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
ioName = F("P?");
|
ioName = F("P?");
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@
|
|||||||
For full license information read the LICENSE file in the project folder */
|
For full license information read the LICENSE file in the project folder */
|
||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
#include "StreamUtils.h" // For EEPromStream
|
#include "StreamUtils.h" // For EEPromStream
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "lvgl.h"
|
#include "lvgl.h"
|
||||||
@ -17,13 +17,13 @@
|
|||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#if HASP_USE_DEBUG > 0
|
#if HASP_USE_DEBUG > 0
|
||||||
#include "../hasp_debug.h"
|
#include "../hasp_debug.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
#include "lv_fs_if.h"
|
#include "lv_fs_if.h"
|
||||||
#include "hasp_gui.h"
|
#include "hasp_gui.h"
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
//#include "hasp_filesystem.h" included in hasp_conf.h
|
//#include "hasp_filesystem.h" included in hasp_conf.h
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -32,10 +32,11 @@
|
|||||||
|
|
||||||
#include "hasp_attribute.h"
|
#include "hasp_attribute.h"
|
||||||
#include "hasp.h"
|
#include "hasp.h"
|
||||||
|
#include "dev/device.h"
|
||||||
#include "lv_theme_hasp.h"
|
#include "lv_theme_hasp.h"
|
||||||
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
#include "EEPROM.h"
|
#include "EEPROM.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#if LV_USE_HASP
|
//#if LV_USE_HASP
|
||||||
@ -298,7 +299,7 @@ void haspProgressMsg(const char * msg)
|
|||||||
|
|
||||||
#ifdef ARDUINO
|
#ifdef ARDUINO
|
||||||
// Sets the value string of the global progress bar
|
// Sets the value string of the global progress bar
|
||||||
void haspProgressMsg(const __FlashStringHelper *msg)
|
void haspProgressMsg(const __FlashStringHelper * msg)
|
||||||
{
|
{
|
||||||
haspProgressMsg(String(msg).c_str());
|
haspProgressMsg(String(msg).c_str());
|
||||||
}
|
}
|
||||||
@ -322,7 +323,7 @@ static void custom_font_apply_cb(lv_theme_t * th, lv_obj_t * obj, lv_theme_style
|
|||||||
*/
|
*/
|
||||||
void haspSetup(void)
|
void haspSetup(void)
|
||||||
{
|
{
|
||||||
guiSetDim(haspStartDim);
|
haspDevice.set_backlight_level(haspStartDim);
|
||||||
|
|
||||||
/******* File System Test ********************************************************************/
|
/******* File System Test ********************************************************************/
|
||||||
// lv_fs_file_t f;
|
// lv_fs_file_t f;
|
||||||
@ -355,7 +356,7 @@ void haspSetup(void)
|
|||||||
/* ********** Font Initializations ********** */
|
/* ********** Font Initializations ********** */
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
#if HASP_USE_SPIFFS > 0 || HASP_USE_LITTLEFS > 0
|
||||||
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP32) || defined(ARDUINO_ARCH_ESP8266)
|
||||||
lv_zifont_init();
|
lv_zifont_init();
|
||||||
|
|
||||||
if(lv_zifont_font_init(&haspFonts[1], haspZiFontPath, 32) != 0) {
|
if(lv_zifont_font_init(&haspFonts[1], haspZiFontPath, 32) != 0) {
|
||||||
@ -364,7 +365,7 @@ void haspSetup(void)
|
|||||||
} else {
|
} else {
|
||||||
// defaultFont = haspFonts[0];
|
// defaultFont = haspFonts[0];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// haspFonts[0] = lv_font_load("E:/font_1.fnt");
|
// haspFonts[0] = lv_font_load("E:/font_1.fnt");
|
||||||
@ -589,12 +590,12 @@ void haspLoadPage(const char * pagesfile)
|
|||||||
LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile);
|
LOG_INFO(TAG_HASP, F("File %s loaded"), pagesfile);
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if HASP_USE_EEPROM > 0
|
#if HASP_USE_EEPROM > 0
|
||||||
LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM..."));
|
LOG_TRACE(TAG_HASP, F("Loading jsonl from EEPROM..."));
|
||||||
EepromStream eepromStream(4096, 1024);
|
EepromStream eepromStream(4096, 1024);
|
||||||
dispatch_parse_jsonl(eepromStream);
|
dispatch_parse_jsonl(eepromStream);
|
||||||
LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM"));
|
LOG_INFO(TAG_HASP, F("Loaded jsonl from EEPROM"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -13,33 +13,35 @@
|
|||||||
#include "hasp_parser.h"
|
#include "hasp_parser.h"
|
||||||
#include "hasp_attribute.h"
|
#include "hasp_attribute.h"
|
||||||
|
|
||||||
|
#include "dev/device.h"
|
||||||
|
|
||||||
//#include "hasp_gui.h"
|
//#include "hasp_gui.h"
|
||||||
|
|
||||||
#if HASP_USE_DEBUG > 0
|
#if HASP_USE_DEBUG > 0
|
||||||
#include "../hasp_debug.h"
|
#include "../hasp_debug.h"
|
||||||
|
|
||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "../mqtt/hasp_mqtt.h"
|
#include "../mqtt/hasp_mqtt.h"
|
||||||
#else
|
#else
|
||||||
#include "StringStream.h"
|
#include "StringStream.h"
|
||||||
#include "CharStream.h"
|
#include "CharStream.h"
|
||||||
|
|
||||||
#include "hasp_oobe.h"
|
#include "hasp_oobe.h"
|
||||||
#include "hasp_gui.h" // for screenshot
|
#include "hasp_gui.h" // for screenshot
|
||||||
#include "sys/gpio/hasp_gpio.h"
|
#include "sys/gpio/hasp_gpio.h"
|
||||||
#include "hal/hasp_hal.h"
|
#include "hal/hasp_hal.h"
|
||||||
|
|
||||||
#include "svc/hasp_ota.h"
|
#include "svc/hasp_ota.h"
|
||||||
#include "mqtt/hasp_mqtt.h"
|
#include "mqtt/hasp_mqtt.h"
|
||||||
#include "sys/net/hasp_network.h" // for network_get_status()
|
#include "sys/net/hasp_network.h" // for network_get_status()
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
#include "hasp_config.h"
|
#include "hasp_config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern uint8_t hasp_sleep_state;
|
extern uint8_t hasp_sleep_state;
|
||||||
@ -227,14 +229,14 @@ void dispatch_command(const char * topic, const char * payload)
|
|||||||
|
|
||||||
#if HASP_USE_CONFIG > 0
|
#if HASP_USE_CONFIG > 0
|
||||||
|
|
||||||
#if HASP_USE_WIFI > 0
|
#if HASP_USE_WIFI > 0
|
||||||
} else if(!strcmp_P(topic, FP_CONFIG_SSID) || !strcmp_P(topic, FP_CONFIG_PASS)) {
|
} else if(!strcmp_P(topic, FP_CONFIG_SSID) || !strcmp_P(topic, FP_CONFIG_PASS)) {
|
||||||
StaticJsonDocument<64> settings;
|
StaticJsonDocument<64> settings;
|
||||||
settings[topic] = payload;
|
settings[topic] = payload;
|
||||||
wifiSetConfig(settings.as<JsonObject>());
|
wifiSetConfig(settings.as<JsonObject>());
|
||||||
#endif // HASP_USE_WIFI
|
#endif // HASP_USE_WIFI
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
} else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) ||
|
} else if(!strcmp_P(topic, PSTR("mqtthost")) || !strcmp_P(topic, PSTR("mqttport")) ||
|
||||||
!strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) ||
|
!strcmp_P(topic, PSTR("mqttport")) || !strcmp_P(topic, PSTR("mqttuser")) ||
|
||||||
!strcmp_P(topic, PSTR("hostname"))) {
|
!strcmp_P(topic, PSTR("hostname"))) {
|
||||||
@ -245,7 +247,7 @@ void dispatch_command(const char * topic, const char * payload)
|
|||||||
StaticJsonDocument<64> settings;
|
StaticJsonDocument<64> settings;
|
||||||
settings[topic + 4] = payload;
|
settings[topic + 4] = payload;
|
||||||
mqttSetConfig(settings.as<JsonObject>());
|
mqttSetConfig(settings.as<JsonObject>());
|
||||||
#endif // HASP_USE_MQTT
|
#endif // HASP_USE_MQTT
|
||||||
|
|
||||||
#endif // HASP_USE_CONFIG
|
#endif // HASP_USE_CONFIG
|
||||||
|
|
||||||
@ -425,42 +427,42 @@ static void dispatch_config(const char * topic, const char * payload)
|
|||||||
haspGetConfig(settings);
|
haspGetConfig(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if HASP_USE_WIFI > 0
|
#if HASP_USE_WIFI > 0
|
||||||
else if(strcasecmp_P(topic, PSTR("wifi")) == 0) {
|
else if(strcasecmp_P(topic, PSTR("wifi")) == 0) {
|
||||||
if(update)
|
if(update)
|
||||||
wifiSetConfig(settings);
|
wifiSetConfig(settings);
|
||||||
else
|
else
|
||||||
wifiGetConfig(settings);
|
wifiGetConfig(settings);
|
||||||
}
|
}
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
else if(strcasecmp_P(topic, PSTR("mqtt")) == 0) {
|
else if(strcasecmp_P(topic, PSTR("mqtt")) == 0) {
|
||||||
if(update)
|
if(update)
|
||||||
mqttSetConfig(settings);
|
mqttSetConfig(settings);
|
||||||
else
|
else
|
||||||
mqttGetConfig(settings);
|
mqttGetConfig(settings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_TELNET > 0
|
#if HASP_USE_TELNET > 0
|
||||||
// else if(strcasecmp_P(topic, PSTR("telnet")) == 0)
|
// else if(strcasecmp_P(topic, PSTR("telnet")) == 0)
|
||||||
// telnetGetConfig(settings[F("telnet")]);
|
// telnetGetConfig(settings[F("telnet")]);
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_MDNS > 0
|
#if HASP_USE_MDNS > 0
|
||||||
else if(strcasecmp_P(topic, PSTR("mdns")) == 0) {
|
else if(strcasecmp_P(topic, PSTR("mdns")) == 0) {
|
||||||
if(update)
|
if(update)
|
||||||
mdnsSetConfig(settings);
|
mdnsSetConfig(settings);
|
||||||
else
|
else
|
||||||
mdnsGetConfig(settings);
|
mdnsGetConfig(settings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_HTTP > 0
|
#if HASP_USE_HTTP > 0
|
||||||
else if(strcasecmp_P(topic, PSTR("http")) == 0) {
|
else if(strcasecmp_P(topic, PSTR("http")) == 0) {
|
||||||
if(update)
|
if(update)
|
||||||
httpSetConfig(settings);
|
httpSetConfig(settings);
|
||||||
else
|
else
|
||||||
httpGetConfig(settings);
|
httpGetConfig(settings);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Send output
|
// Send output
|
||||||
if(!update) {
|
if(!update) {
|
||||||
@ -532,9 +534,9 @@ void dispatch_gpio_input_event(uint8_t pin, uint8_t group, uint8_t eventid)
|
|||||||
dispatch_get_event_name(eventid, event, sizeof(event));
|
dispatch_get_event_name(eventid, event, sizeof(event));
|
||||||
snprintf_P(payload, sizeof(payload), PSTR("{\"pin\":%d,\"group\":%d,\"event\":\"%s\"}"), pin, group, event);
|
snprintf_P(payload, sizeof(payload), PSTR("{\"pin\":%d,\"group\":%d,\"event\":\"%s\"}"), pin, group, event);
|
||||||
|
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqtt_send_state(F("input"), payload);
|
mqtt_send_state(F("input"), payload);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// update outputstates
|
// update outputstates
|
||||||
// dispatch_group_onoff(group, dispatch_get_event_state(eventid), NULL);
|
// dispatch_group_onoff(group, dispatch_get_event_state(eventid), NULL);
|
||||||
@ -572,12 +574,12 @@ static inline void dispatch_state_msg(const __FlashStringHelper * subtopic, cons
|
|||||||
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE)
|
#if !defined(HASP_USE_MQTT) && !defined(HASP_USE_TASMOTA_SLAVE)
|
||||||
LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload);
|
LOG_TRACE(TAG_MSGR, F("%s => %s"), String(subtopic).c_str(), payload);
|
||||||
#else
|
#else
|
||||||
#if HASP_USE_MQTT > 0
|
#if HASP_USE_MQTT > 0
|
||||||
mqtt_send_state(subtopic, payload);
|
mqtt_send_state(subtopic, payload);
|
||||||
#endif
|
#endif
|
||||||
#if HASP_USE_TASMOTA_SLAVE > 0
|
#if HASP_USE_TASMOTA_SLAVE > 0
|
||||||
slave_send_state(subtopic, payload);
|
slave_send_state(subtopic, payload);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -774,10 +776,10 @@ void dispatch_clear_page(const char *, const char * page)
|
|||||||
void dispatch_dim(const char *, const char * level)
|
void dispatch_dim(const char *, const char * level)
|
||||||
{
|
{
|
||||||
// Set the current state
|
// Set the current state
|
||||||
if(strlen(level) != 0) guiSetDim(atoi(level));
|
if(strlen(level) != 0) haspDevice.set_backlight_level(atoi(level));
|
||||||
|
|
||||||
char payload[5];
|
char payload[5];
|
||||||
itoa(guiGetDim(), payload, DEC);
|
itoa(haspDevice.get_backlight_level(), payload, DEC);
|
||||||
dispatch_state_msg(F("dim"), payload);
|
dispatch_state_msg(F("dim"), payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -833,11 +835,11 @@ void dispatch_moodlight(const char * topic, const char * payload)
|
|||||||
void dispatch_backlight(const char *, const char * payload)
|
void dispatch_backlight(const char *, const char * payload)
|
||||||
{
|
{
|
||||||
// Set the current state
|
// Set the current state
|
||||||
if(strlen(payload) != 0) guiSetBacklight(Utilities::is_true(payload));
|
if(strlen(payload) != 0) haspDevice.set_backlight_power(Utilities::is_true(payload));
|
||||||
|
|
||||||
// Return the current state
|
// Return the current state
|
||||||
char buffer[4];
|
char buffer[4];
|
||||||
memcpy_P(buffer, guiGetBacklight() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer));
|
memcpy_P(buffer, haspDevice.get_backlight_power() ? PSTR("ON") : PSTR("OFF"), sizeof(buffer));
|
||||||
dispatch_state_msg(F("light"), buffer);
|
dispatch_state_msg(F("light"), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1012,7 +1014,7 @@ void everySecond()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
|
||||||
void everySecond()
|
void everySecond()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user