init repo
This commit is contained in:
commit
d1297960d5
6 changed files with 309 additions and 0 deletions
1
README.md
Normal file
1
README.md
Normal file
|
@ -0,0 +1 @@
|
|||
# esp32 armchair
|
39
include/README
Normal file
39
include/README
Normal file
|
@ -0,0 +1,39 @@
|
|||
|
||||
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 usual convention is to give header files names that end with `.h'.
|
||||
It is most portable to use only letters, digits, dashes, and underscores in
|
||||
header file names, and at most one dot.
|
||||
|
||||
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
|
46
lib/README
Normal file
46
lib/README
Normal file
|
@ -0,0 +1,46 @@
|
|||
|
||||
This directory is intended for project specific (private) libraries.
|
||||
PlatformIO will compile them to static libraries and link into executable file.
|
||||
|
||||
The source code of each library should be placed in a an own separate directory
|
||||
("lib/your_library_name/[here are source files]").
|
||||
|
||||
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||
|
||||
|--lib
|
||||
| |
|
||||
| |--Bar
|
||||
| | |--docs
|
||||
| | |--examples
|
||||
| | |--src
|
||||
| | |- Bar.c
|
||||
| | |- Bar.h
|
||||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|
||||
| |
|
||||
| |--Foo
|
||||
| | |- Foo.c
|
||||
| | |- Foo.h
|
||||
| |
|
||||
| |- README --> THIS FILE
|
||||
|
|
||||
|- platformio.ini
|
||||
|--src
|
||||
|- main.c
|
||||
|
||||
and a contents of `src/main.c`:
|
||||
```
|
||||
#include <Foo.h>
|
||||
#include <Bar.h>
|
||||
|
||||
int main (void)
|
||||
{
|
||||
...
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
PlatformIO Library Dependency Finder will find automatically dependent
|
||||
libraries scanning project source files.
|
||||
|
||||
More information about PlatformIO Library Dependency Finder
|
||||
- https://docs.platformio.org/page/librarymanager/ldf.html
|
24
platformio.ini
Normal file
24
platformio.ini
Normal file
|
@ -0,0 +1,24 @@
|
|||
; PlatformIO Project Configuration File
|
||||
;
|
||||
; Build options: build flags, source filter
|
||||
; Upload options: custom upload port, speed and extra flags
|
||||
; Library options: dependencies, extra library storages
|
||||
; Advanced options: extra scripting
|
||||
;
|
||||
; Please visit documentation for the other options and examples
|
||||
; https://docs.platformio.org/page/projectconf.html
|
||||
|
||||
[env:esp32dev]
|
||||
platform = espressif32
|
||||
board = esp32dev
|
||||
framework = arduino
|
||||
monitor_speed = 115200
|
||||
board_build.f_cpu = 240000000L
|
||||
board_build.f_flash = 80000000L
|
||||
board_build.flash_mode = qio
|
||||
board_build.partitions = huge_app.csv
|
||||
lib_deps =
|
||||
cnmat/OSC
|
||||
bogde/HX711
|
||||
adafruit/Adafruit VS1053 Library
|
||||
SD(esp32)
|
188
src/main.cpp
Normal file
188
src/main.cpp
Normal file
|
@ -0,0 +1,188 @@
|
|||
#include "Arduino.h"
|
||||
#include "WiFi.h"
|
||||
#include "WiFiUdp.h"
|
||||
#include "OSCMessage.h"
|
||||
#include "OSCBundle.h"
|
||||
#include "SPI.h"
|
||||
#include "SD.h"
|
||||
#include "Adafruit_VS1053.h"
|
||||
#include "HX711.h"
|
||||
|
||||
#define BL_ON 0
|
||||
|
||||
#if BL_ON
|
||||
#include "BLEDevice.h"
|
||||
#include "BLEScan.h"
|
||||
|
||||
#define blName "Sessel"
|
||||
#endif
|
||||
|
||||
|
||||
// WiFi stuff
|
||||
#define ssid ""
|
||||
#define pwd ""
|
||||
|
||||
// OSC
|
||||
#define host "192.168.20.105"
|
||||
#define port 3030
|
||||
#define localPort 4040
|
||||
|
||||
// feather music maker
|
||||
#define maxFileNameLength 20
|
||||
#define VS1053_RESET -1 // VS1053 reset pin (not used!)
|
||||
#define VS1053_CS 32 // VS1053 chip select pin (output)
|
||||
#define VS1053_DCS 33 // VS1053 Data/command select pin (output)
|
||||
#define CARDCS 14 // Card chip select pin
|
||||
#define VS1053_DREQ 15 // VS1053 Data request, ideally an Interrupt pin
|
||||
/*
|
||||
Miso --------> IO19
|
||||
Mosi --------> IO23
|
||||
Sck --------> IO18
|
||||
|
||||
Sd Cs -------> IO14
|
||||
MP3 Cs ----> IO32
|
||||
DReq -------> IO15
|
||||
XdCs -------> IO33
|
||||
*/
|
||||
|
||||
|
||||
// load sensors
|
||||
#define DOUT 21
|
||||
#define CLK 22
|
||||
|
||||
WiFiUDP Udp;
|
||||
OSCErrorCode error;
|
||||
HX711 scale;
|
||||
float calibration_factor = -10380;
|
||||
const float threshold = 0.1;
|
||||
|
||||
Adafruit_VS1053_FilePlayer musicPlayer =
|
||||
Adafruit_VS1053_FilePlayer(VS1053_RESET, VS1053_CS, VS1053_DCS, VS1053_DREQ, CARDCS);
|
||||
|
||||
void bgTask(void * parameter ) {
|
||||
scale.begin(DOUT, CLK);
|
||||
scale.set_scale(calibration_factor);
|
||||
scale.tare(); //Reset the scale to 0
|
||||
float w = scale.get_units(4);
|
||||
|
||||
while(true){
|
||||
float wNew = scale.get_units(4);
|
||||
if (abs(w-wNew) > threshold){
|
||||
OSCMessage msgOut("/sessel/gewicht");
|
||||
msgOut.add(w);
|
||||
Udp.beginPacket(host, port);
|
||||
msgOut.send(Udp);
|
||||
Udp.endPacket();
|
||||
w = wNew;
|
||||
}
|
||||
vTaskDelay(100);}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(500);
|
||||
|
||||
if (! musicPlayer.begin()) { // initialise the music player
|
||||
Serial.println(F("Couldn't find VS1053"));
|
||||
}
|
||||
Serial.println(F("VS1053 found"));
|
||||
|
||||
if (!SD.begin(CARDCS)) {
|
||||
Serial.println(F("SD failed, or not present"));
|
||||
}
|
||||
|
||||
Serial.println("SD OK!");
|
||||
musicPlayer.setVolume(10,10);
|
||||
|
||||
|
||||
|
||||
#if BL_ON
|
||||
BLEDevice::init(blName);
|
||||
#endif
|
||||
|
||||
WiFi.begin(ssid, pwd);
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
Serial.print(".");
|
||||
delay(500);
|
||||
}
|
||||
Serial.print("WiFi connected, IP = ");
|
||||
Serial.println(WiFi.localIP());
|
||||
delay(1500);
|
||||
|
||||
|
||||
Udp.begin(localPort);
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
bgTask,
|
||||
"background task",
|
||||
4000,
|
||||
NULL,
|
||||
1,
|
||||
NULL,
|
||||
0 );
|
||||
|
||||
}
|
||||
|
||||
void play(OSCMessage & msg){
|
||||
char fileName[maxFileNameLength];
|
||||
char * file = fileName;
|
||||
msg.getString(0, file, maxFileNameLength);
|
||||
Serial.println(file);
|
||||
musicPlayer.startPlayingFile(file);
|
||||
}
|
||||
|
||||
void stop(OSCMessage & msg){
|
||||
Serial.println("stop");
|
||||
musicPlayer.stopPlaying();
|
||||
}
|
||||
|
||||
void pause(OSCMessage & msg){
|
||||
bool state = msg.getInt(0);
|
||||
Serial.print("pause ");
|
||||
Serial.println(state);
|
||||
musicPlayer.pausePlaying(state);
|
||||
}
|
||||
|
||||
void togglePause(OSCMessage & msg){
|
||||
Serial.println("togglePause");
|
||||
if (! musicPlayer.paused()) {
|
||||
musicPlayer.pausePlaying(true);
|
||||
} else {
|
||||
musicPlayer.pausePlaying(false);
|
||||
}
|
||||
}
|
||||
|
||||
void setVolume(OSCMessage & msg){
|
||||
int vol = msg.getInt(0);
|
||||
Serial.print("set Volume to ");
|
||||
Serial.println(vol);
|
||||
musicPlayer.setVolume(vol,vol);
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
musicPlayer.feedBuffer();
|
||||
OSCMessage msg;
|
||||
int size = Udp.parsePacket();
|
||||
|
||||
if (size > 0) {
|
||||
while (size--) {
|
||||
msg.fill(Udp.read());
|
||||
}
|
||||
if (!msg.hasError()) {
|
||||
msg.dispatch("/play", play);
|
||||
msg.dispatch("/stop", stop);
|
||||
msg.dispatch("/pause", pause);
|
||||
msg.dispatch("/togglePause", togglePause);
|
||||
msg.dispatch("/setVolume", setVolume);
|
||||
} else {
|
||||
error = msg.getError();
|
||||
Serial.print("error: ");
|
||||
Serial.println(error);
|
||||
}
|
||||
}
|
||||
delay(10);
|
||||
|
||||
|
||||
}
|
11
test/README
Normal file
11
test/README
Normal file
|
@ -0,0 +1,11 @@
|
|||
|
||||
This directory is intended for PlatformIO Unit Testing and project tests.
|
||||
|
||||
Unit Testing is a software testing method by which individual units of
|
||||
source code, sets of one or more MCU program modules together with associated
|
||||
control data, usage procedures, and operating procedures, are tested to
|
||||
determine whether they are fit for use. Unit testing finds problems early
|
||||
in the development cycle.
|
||||
|
||||
More information about PlatformIO Unit Testing:
|
||||
- https://docs.platformio.org/page/plus/unit-testing.html
|
Loading…
Reference in a new issue