Adds simple display, uss and imu service
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#define SCREEN_WIDTH 128
|
||||||
|
#define SCREEN_HEIGHT 64
|
||||||
|
|
||||||
|
class DisplayService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DisplayService() : display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1) {};
|
||||||
|
|
||||||
|
bool begin()
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> guard(displayMutex);
|
||||||
|
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
display.clearDisplay();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
void clear() {
|
||||||
|
std::lock_guard<std::mutex> guard(displayMutex);
|
||||||
|
display.clearDisplay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||||
|
std::lock_guard<std::mutex> guard(displayMutex);
|
||||||
|
display.drawPixel(x, y, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void displayMessage(const String &message, int x, int y) {
|
||||||
|
std::lock_guard<std::mutex> lock(displayMutex);
|
||||||
|
display.setCursor(x, y);
|
||||||
|
display.clearDisplay();
|
||||||
|
display.println(message);
|
||||||
|
display.display();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Adafruit_SSD1306 display;
|
||||||
|
std::mutex displayMutex;
|
||||||
|
};
|
||||||
@@ -37,6 +37,7 @@
|
|||||||
#include <RestartService.h>
|
#include <RestartService.h>
|
||||||
#include <SecuritySettingsService.h>
|
#include <SecuritySettingsService.h>
|
||||||
#include <SleepService.h>
|
#include <SleepService.h>
|
||||||
|
#include <Wire.h>
|
||||||
#include <SystemStatus.h>
|
#include <SystemStatus.h>
|
||||||
#include <WiFiScanner.h>
|
#include <WiFiScanner.h>
|
||||||
#include <WiFiSettingsService.h>
|
#include <WiFiSettingsService.h>
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <MPU6050_light.h>
|
||||||
|
|
||||||
|
#define IMU_INTERVAL 2000
|
||||||
|
|
||||||
|
class IMUService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IMUService():_imu(Wire){};
|
||||||
|
|
||||||
|
void begin()
|
||||||
|
{
|
||||||
|
byte status = _imu.begin();
|
||||||
|
if(status != 0) {
|
||||||
|
ESP_LOGE("IMUService", "MPU initialize failed");
|
||||||
|
vTaskDelete(NULL);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
xTaskCreatePinnedToCore(this->_loopImpl, "IMU Service", 4096, this, tskIDLE_PRIORITY, NULL, ESP32SVELTEKIT_RUNNING_CORE);
|
||||||
|
};
|
||||||
|
|
||||||
|
float getTemp() {
|
||||||
|
return _imu.getTemp();
|
||||||
|
}
|
||||||
|
|
||||||
|
float getAngleX() {
|
||||||
|
return _imu.getAngleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
float getAngleY() {
|
||||||
|
return _imu.getAngleX();
|
||||||
|
}
|
||||||
|
|
||||||
|
float getAngleZ() {
|
||||||
|
return _imu.getAngleZ();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _loopImpl(void *_this) { static_cast<IMUService *>(_this)->_loop(); }
|
||||||
|
void _loop()
|
||||||
|
{
|
||||||
|
vTaskDelay(100);
|
||||||
|
_imu.calcOffsets(true,true);
|
||||||
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
_imu.update();
|
||||||
|
vTaskDelayUntil(&xLastWakeTime, IMU_INTERVAL / portTICK_PERIOD_MS);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
MPU6050 _imu;
|
||||||
|
};
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <NewPing.h>
|
||||||
|
#include <mutex>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#define USS_INTERVAL 500
|
||||||
|
|
||||||
|
#define MAX_DISTANCE 200
|
||||||
|
|
||||||
|
#define LEFT_TRIG 12
|
||||||
|
#define RIGHT_TRIG 13
|
||||||
|
|
||||||
|
class USSService
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
USSService(const std::vector<uint8_t>& triggerPins, unsigned int maxDistance = MAX_DISTANCE)
|
||||||
|
: distances(triggerPins.size(), 0) {
|
||||||
|
for (size_t i = 0; i < triggerPins.size(); i++) {
|
||||||
|
sensors.emplace_back(triggerPins[i], triggerPins[i], maxDistance);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void begin()
|
||||||
|
{
|
||||||
|
xTaskCreatePinnedToCore(this->_loopImpl, "USS Service", 4096, this, tskIDLE_PRIORITY, NULL, ESP32SVELTEKIT_RUNNING_CORE);
|
||||||
|
};
|
||||||
|
|
||||||
|
unsigned int getDistance(size_t index) {
|
||||||
|
if (index >= distances.size()) return 0;
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
return distances[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _loopImpl(void *_this) { static_cast<USSService *>(_this)->_loop(); }
|
||||||
|
void _loop()
|
||||||
|
{
|
||||||
|
const TickType_t xFrequency = pdMS_TO_TICKS(USS_INTERVAL);
|
||||||
|
TickType_t xLastWakeTime = xTaskGetTickCount();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < sensors.size(); i++) {
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
|
distances[i] = sensors[i].ping_cm();
|
||||||
|
vTaskDelay(50);
|
||||||
|
}
|
||||||
|
vTaskDelayUntil(&xLastWakeTime, xFrequency);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<NewPing> sensors;
|
||||||
|
std::vector<unsigned int> distances;
|
||||||
|
std::mutex mutex_;
|
||||||
|
};
|
||||||
@@ -39,17 +39,17 @@ lib_deps =
|
|||||||
bblanchon/ArduinoJson@^6.21.2
|
bblanchon/ArduinoJson@^6.21.2
|
||||||
https://github.com/theelims/PsychicMqttClient.git#0.1.1
|
https://github.com/theelims/PsychicMqttClient.git#0.1.1
|
||||||
; thomasfredericks/Bounce2@ ^2.7.0
|
; thomasfredericks/Bounce2@ ^2.7.0
|
||||||
; teckel12/NewPing@^1.9.7
|
teckel12/NewPing@^1.9.7
|
||||||
; adafruit/Adafruit SSD1306@^2.5.7
|
adafruit/Adafruit SSD1306@^2.5.7
|
||||||
; adafruit/Adafruit GFX Library@^1.11.5
|
adafruit/Adafruit GFX Library@^1.11.5
|
||||||
; adafruit/Adafruit BusIO@^1.9.3
|
adafruit/Adafruit BusIO@^1.9.3
|
||||||
; adafruit/Adafruit PWM Servo Driver Library@^2.4.1
|
; adafruit/Adafruit PWM Servo Driver Library@^2.4.1
|
||||||
; adafruit/Adafruit ADS1X15@^2.4.0
|
; adafruit/Adafruit ADS1X15@^2.4.0
|
||||||
; adafruit/Adafruit HMC5883 Unified@^1.2.1
|
; adafruit/Adafruit HMC5883 Unified@^1.2.1
|
||||||
; adafruit/Adafruit Unified Sensor@^1.1.11
|
; adafruit/Adafruit Unified Sensor@^1.1.11
|
||||||
; plageoj/UrlEncode@ ^1.0.1
|
; plageoj/UrlEncode@ ^1.0.1
|
||||||
; rfetick/MPU6050_light@^1.1.0
|
rfetick/MPU6050_light@^1.1.0
|
||||||
; SPI
|
SPI
|
||||||
; board_build.partitions = config/no_oat.csv
|
; board_build.partitions = config/no_oat.csv
|
||||||
extra_scripts =
|
extra_scripts =
|
||||||
pre:scripts/build_app.py
|
pre:scripts/build_app.py
|
||||||
|
|||||||
@@ -21,12 +21,41 @@ LightStateService lightStateService = LightStateService(&server,
|
|||||||
esp32sveltekit.getMqttClient(),
|
esp32sveltekit.getMqttClient(),
|
||||||
&lightMqttSettingsService);
|
&lightMqttSettingsService);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Camera settings service
|
||||||
|
* Camera state service
|
||||||
|
* Initialize the camera
|
||||||
|
*
|
||||||
|
* Idle task for calculating usage - CPU usage
|
||||||
|
* Place to define the task priorities
|
||||||
|
* General setting like metric or imperial
|
||||||
|
* Global definitions
|
||||||
|
* Global connection manager - SDA, SCL, BUTTON, SCREEN, USS, SERVO, CAMERA
|
||||||
|
*
|
||||||
|
* Servo Service
|
||||||
|
* Servo Settings Service
|
||||||
|
*
|
||||||
|
* JSON serializable - PsRamAllocator
|
||||||
|
* Buffered JSON reader / writer
|
||||||
|
*
|
||||||
|
* FT for PSRAM
|
||||||
|
* FT for bluetooth
|
||||||
|
* FT for ESPNOW controller
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Button input service - Add callback for button press
|
||||||
|
* */
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(SERIAL_BAUD_RATE);
|
Serial.begin(SERIAL_BAUD_RATE);
|
||||||
|
|
||||||
esp32sveltekit.begin();
|
esp32sveltekit.begin();
|
||||||
|
|
||||||
|
// Wire.begin(SDA, SCL);
|
||||||
|
|
||||||
|
// InitializeCamera();
|
||||||
|
|
||||||
lightStateService.begin();
|
lightStateService.begin();
|
||||||
|
|
||||||
lightMqttSettingsService.begin();
|
lightMqttSettingsService.begin();
|
||||||
|
|||||||
Reference in New Issue
Block a user