init
This commit is contained in:
commit
1d7af0615e
15 files changed
+942
No files matched your search
@@ -0,0 +1,37 @@
|
||||
|
||||
This directory is intended for project header files.
|
||||
|
||||
A header file is a file containing C declarations and macro definitions
|
||||
to be shared between several project source files. You request the use of a
|
||||
header file in your project source file (C, C++, etc) located in `src` folder
|
||||
by including it, with the C preprocessing directive `#include'.
|
||||
|
||||
```src/main.c
|
||||
|
||||
#include "header.h"
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
Including a header file produces the same results as copying the header file
|
||||
into each source file that needs it. Such copying would be time-consuming
|
||||
and error-prone. With a header file, the related declarations appear
|
||||
in only one place. If they need to be changed, they can be changed in one
|
||||
place, and programs that include the header file will automatically use the
|
||||
new version when next recompiled. The header file eliminates the labor of
|
||||
finding and changing all the copies as well as the risk that a failure to
|
||||
find one copy will result in inconsistencies within a program.
|
||||
|
||||
In C, the convention is to give header files names that end with `.h'.
|
||||
|
||||
Read more about using header files in official GCC documentation:
|
||||
|
||||
* Include Syntax
|
||||
* Include Operation
|
||||
* Once-Only Headers
|
||||
* Computed Includes
|
||||
|
||||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
|
||||
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <freertos/semphr.h>
|
||||
|
||||
enum class CmdType : uint8_t {
|
||||
VolumeDelta, // value: signed change in %
|
||||
VolumeSet, // value: absolute 0..100
|
||||
RelayToggle,
|
||||
RelaySet, // value: 0 / 1
|
||||
};
|
||||
|
||||
struct Command {
|
||||
CmdType type;
|
||||
int16_t value;
|
||||
};
|
||||
|
||||
struct AppState {
|
||||
uint8_t volume; // 0..100
|
||||
bool relay;
|
||||
};
|
||||
|
||||
// Created in main.cpp
|
||||
extern QueueHandle_t cmdQueue;
|
||||
|
||||
bool sendCommand(CmdType type, int16_t value = 0);
|
||||
AppState getState();
|
||||
void setState(const AppState &s);
|
||||
|
||||
void controlTask(void *arg);
|
||||
void encoderTask(void *arg);
|
||||
void webTask(void *arg);
|
||||
void displayTask(void *arg);
|
||||
@@ -0,0 +1,48 @@
|
||||
#pragma once
|
||||
|
||||
// ---------- Wi-Fi ----------
|
||||
#define WIFI_SSID "your_ssid"
|
||||
#define WIFI_PASSWORD "your_password"
|
||||
#define WIFI_CONNECT_TIMEOUT_MS 15000
|
||||
|
||||
// If the station connection fails, the ESP32 starts its own access point
|
||||
#define AP_SSID "VolumeControl"
|
||||
#define AP_PASSWORD "12345678" // min 8 chars
|
||||
|
||||
#define MDNS_HOSTNAME "volume" // http://volume.local
|
||||
|
||||
// ---------- Pins (chosen to not clash with the TFT pins in platformio.ini) ----------
|
||||
#define PIN_ENC_CLK 32
|
||||
#define PIN_ENC_DT 33
|
||||
#define PIN_ENC_SW 25
|
||||
#define PIN_SERVO 13
|
||||
#define PIN_RELAY 26
|
||||
|
||||
// ---------- Encoder ----------
|
||||
#define ENCODER_REVERSE 0 // set to 1 if rotation direction is inverted
|
||||
#define ENCODER_STEPS_PER_DETENT 4
|
||||
#define VOLUME_STEP 2 // % per encoder detent
|
||||
#define BUTTON_DEBOUNCE_MS 30
|
||||
|
||||
// ---------- Servo ----------
|
||||
// Pulse widths for volume 0% and 100%. Tune to the real travel of the pot.
|
||||
#define SERVO_MIN_US 500
|
||||
#define SERVO_MAX_US 2400
|
||||
#define SERVO_SPEED_US_PER_STEP 20 // smoothing: max pulse change per update
|
||||
#define SERVO_UPDATE_MS 10
|
||||
#define SERVO_DETACH_IDLE_MS 1000 // release servo when idle to avoid hum/jitter
|
||||
|
||||
// ---------- Relay ----------
|
||||
#define RELAY_ACTIVE_LEVEL HIGH // many relay modules are active LOW
|
||||
|
||||
// ---------- Display ----------
|
||||
#define DISPLAY_UPDATE_MS 20 // also the touch polling period
|
||||
|
||||
// ---------- Touch ----------
|
||||
#define TOUCH_VOLUME_STEP 1 // % per tap on -/+
|
||||
#define TOUCH_REPEAT_DELAY_MS 400 // hold -/+ this long to start auto-repeat
|
||||
#define TOUCH_REPEAT_MS 80
|
||||
#define TOUCH_RECAL_PRESSURE 400 // touch at power-up stronger than this -> recalibrate
|
||||
|
||||
// ---------- Persistence ----------
|
||||
#define SAVE_DELAY_MS 2000 // write to NVS after values stop changing
|
||||
Reference in new issue
Block a user