Add device object

This commit is contained in:
fvanroie 2021-01-29 21:00:19 +01:00
parent e3c129fd37
commit dad89c4224
8 changed files with 236 additions and 42 deletions

9
src/dev/device.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "device.h"
#if defined(LANBONL8)
#warning Lanbon L8
#elif defined(M5STACK)
#warning M5 Stack
#else
dev::BaseDevice haspDevice;
#endif

35
src/dev/device.h Normal file
View File

@ -0,0 +1,35 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_H
#define HASP_DEVICE_H
namespace dev {
class BaseDevice {
public:
virtual void pre_setup()
{}
virtual void post_setup()
{}
virtual void loop()
{}
virtual void loop_5s()
{}
};
} // namespace dev
using dev::BaseDevice;
#include "lanbonl8.h"
#include "m5stackcore2.h"
#if defined(LANBONL8)
#warning Lanbon L8
#elif defined(M5STACK)
#warning M5 Stack
#else
extern dev::BaseDevice haspDevice;
#endif
#endif

73
src/dev/lanbonl8.cpp Normal file
View File

@ -0,0 +1,73 @@
#include "Arduino.h"
#include "lanbonl8.h"
#if defined(LANBONL8)
#include "driver/adc.h"
#include "esp_adc_cal.h"
#define REF_VOLTAGE 1100
esp_adc_cal_characteristics_t * adc_chars =
new esp_adc_cal_characteristics_t; // adc_chars = calloc(1, sizeof(esp_adc_cal_characteristics_t));
namespace dev {
static void check_efuse(void)
{
// Check TP is burned into eFuse
if(esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_TP) == ESP_OK) {
printf("eFuse Two Point: Supported\n");
} else {
printf("eFuse Two Point: NOT supported\n");
}
// Check Vref is burned into eFuse
if(esp_adc_cal_check_efuse(ESP_ADC_CAL_VAL_EFUSE_VREF) == ESP_OK) {
printf("eFuse Vref: Supported\n");
} else {
printf("eFuse Vref: NOT supported\n");
}
}
static void print_char_val_type(esp_adc_cal_value_t val_type)
{
if(val_type == ESP_ADC_CAL_VAL_EFUSE_TP) {
Serial.print("Characterized using Two Point Value\n");
} else if(val_type == ESP_ADC_CAL_VAL_EFUSE_VREF) {
Serial.print("Characterized using eFuse Vref\n");
} else {
Serial.print("Characterized using Default Vref\n");
}
}
void LanbonL8::pre_setup()
{
// Check if Two Point or Vref are burned into eFuse
check_efuse();
// Characterize ADC
adc1_config_width(ADC_WIDTH_12Bit);
adc1_config_channel_atten(ADC1_CHANNEL_3, ADC_ATTEN_0db);
esp_adc_cal_value_t val_type =
esp_adc_cal_characterize(ADC_UNIT_1, ADC_ATTEN_0db, ADC_WIDTH_12Bit, REF_VOLTAGE, adc_chars);
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
dev::LanbonL8 haspDevice;
#endif

28
src/dev/lanbonl8.h Normal file
View File

@ -0,0 +1,28 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_LANBONL8_H
#define HASP_DEVICE_LANBONL8_H
#include "device.h"
#if defined(LANBONL8)
namespace dev {
class LanbonL8 : public BaseDevice {
public:
void pre_setup() override;
void post_setup() override;
void loop() override;
void loop_5s() override;
};
} // namespace dev
extern dev::LanbonL8 haspDevice;
#endif
#endif

53
src/dev/m5stackcore2.cpp Normal file
View File

@ -0,0 +1,53 @@
#include "device.h"
#include "m5stackcore2.h"
#if defined(M5STACK)
#include "AXP192.h" // Power Mgmt
// AXP192 Axp;
namespace dev {
void M5StackCore2::pre_setup(void)
{
AXP192 Axp;
Wire.begin(TOUCH_SDA, TOUCH_SCL);
Axp.begin();
Axp.SetCHGCurrent(AXP192::kCHG_100mA);
Axp.SetLcdVoltage(2800);
Axp.SetBusPowerMode(0);
Axp.SetCHGCurrent(AXP192::kCHG_190mA);
Axp.SetLDOEnable(3, true);
// CoverScrollText("Motor Test", M5.Lcd.color565(SUCCE_COLOR));
delay(150);
Axp.SetLDOEnable(3, false);
Axp.SetLed(1);
// CoverScrollText("LED Test", M5.Lcd.color565(SUCCE_COLOR));
delay(100);
Axp.SetLed(0);
// FastLED.addLeds<SK6812, LEDS_PIN>(ledsBuff, LEDS_NUM);
// for(int i = 0; i < LEDS_NUM; i++) {
// ledsBuff[i].setRGB(20, 20, 20);
// }
// FastLED.show();
Axp.SetLDOVoltage(3, 3300);
Axp.SetLed(1);
}
void M5StackCore2::post_setup(void)
{}
void M5StackCore2::loop(void)
{}
void M5StackCore2::loop_5s(void)
{}
} // namespace dev
dev::M5StackCore2 haspDevice;
#endif

27
src/dev/m5stackcore2.h Normal file
View File

@ -0,0 +1,27 @@
/* MIT License - Copyright (c) 2020 Francis Van Roie
For full license information read the LICENSE file in the project folder */
#ifndef HASP_DEVICE_M5STACKCORE2_H
#define HASP_DEVICE_M5STACKCORE2_H
#if defined(M5STACK)
#include "device.h"
namespace dev {
class M5StackCore2 : public BaseDevice {
public:
void pre_setup() override;
void post_setup() override;
void loop() override;
void loop_5s() override;
};
} // namespace dev
using dev::M5StackCore2;
extern dev::M5StackCore2 haspDevice;
#endif
#endif

View File

@ -1,49 +1,7 @@
#include "hasp_drv_display.h"
#if defined(M5STACK)
#include "AXP192.h" // Power Mgmt
AXP192 Axp;
void m5stack_init()
{
AXP192 Axp;
Wire.begin(TOUCH_SDA, TOUCH_SCL);
Axp.begin();
Axp.SetCHGCurrent(AXP192::kCHG_100mA);
Axp.SetLcdVoltage(2800);
Axp.SetBusPowerMode(0);
Axp.SetCHGCurrent(AXP192::kCHG_190mA);
Axp.SetLDOEnable(3, true);
// CoverScrollText("Motor Test", M5.Lcd.color565(SUCCE_COLOR));
delay(150);
Axp.SetLDOEnable(3, false);
Axp.SetLed(1);
// CoverScrollText("LED Test", M5.Lcd.color565(SUCCE_COLOR));
delay(100);
Axp.SetLed(0);
// FastLED.addLeds<SK6812, LEDS_PIN>(ledsBuff, LEDS_NUM);
// for(int i = 0; i < LEDS_NUM; i++) {
// ledsBuff[i].setRGB(20, 20, 20);
// }
// FastLED.show();
Axp.SetLDOVoltage(3, 3300);
Axp.SetLed(1);
}
#endif
void drv_display_init(lv_disp_drv_t * disp_drv, uint8_t rotation, bool invert_display)
{
#if defined(M5STACK)
m5stack_init(); // Set LCD power first
#endif
/* TFT init */
#if defined(USE_FSMC)
fsmc_ili9341_init(rotation, invert_display);

View File

@ -14,12 +14,16 @@
#include "net/hasp_network.h"
#include "dev/device.h"
bool isConnected;
uint8_t mainLoopCounter = 0;
unsigned long mainLastLoopTime = 0;
void setup()
{
haspDevice.pre_setup();
/****************************
* Storage initializations
***************************/
@ -128,6 +132,7 @@ void loop()
#endif // TELNET
debugLoop(); // Console
haspDevice.loop();
/* Timer Loop */
if(millis() - mainLastLoopTime >= 1000) {
@ -150,6 +155,12 @@ void loop()
#if HASP_USE_MQTT > 0
mqttEvery5Seconds(isConnected);
#endif
#if HASP_USE_GPIO > 0
// gpioEvery5Seconds();
#endif
haspDevice.loop_5s();
}
/* Reset loop counter every 10 seconds */