summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--.vscode/extensions.json10
-rw-r--r--include/README37
-rw-r--r--lib/README46
-rw-r--r--min_part.csv3
-rw-r--r--platformio.ini28
-rw-r--r--src/main.cpp107
-rw-r--r--test/README11
8 files changed, 247 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..89cc49c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.pio
+.vscode/.browse.c_cpp.db*
+.vscode/c_cpp_properties.json
+.vscode/launch.json
+.vscode/ipch
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 0000000..080e70d
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,10 @@
+{
+ // See http://go.microsoft.com/fwlink/?LinkId=827846
+ // for the documentation about the extensions.json format
+ "recommendations": [
+ "platformio.platformio-ide"
+ ],
+ "unwantedRecommendations": [
+ "ms-vscode.cpptools-extension-pack"
+ ]
+}
diff --git a/include/README b/include/README
new file mode 100644
index 0000000..49819c0
--- /dev/null
+++ b/include/README
@@ -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
diff --git a/lib/README b/lib/README
new file mode 100644
index 0000000..9379397
--- /dev/null
+++ b/lib/README
@@ -0,0 +1,46 @@
+
+This directory is intended for project specific (private) libraries.
+PlatformIO will compile them to static libraries and link into the executable file.
+
+The source code of each library should be placed in a separate directory
+("lib/your_library_name/[Code]").
+
+For example, see the structure of the following example libraries `Foo` and `Bar`:
+
+|--lib
+| |
+| |--Bar
+| | |--docs
+| | |--examples
+| | |--src
+| | |- Bar.c
+| | |- Bar.h
+| | |- library.json (optional. for 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
+
+Example contents of `src/main.c` using Foo and Bar:
+```
+#include <Foo.h>
+#include <Bar.h>
+
+int main (void)
+{
+ ...
+}
+
+```
+
+The PlatformIO Library Dependency Finder will find automatically dependent
+libraries by scanning project source files.
+
+More information about PlatformIO Library Dependency Finder
+- https://docs.platformio.org/page/librarymanager/ldf.html
diff --git a/min_part.csv b/min_part.csv
new file mode 100644
index 0000000..290745e
--- /dev/null
+++ b/min_part.csv
@@ -0,0 +1,3 @@
+# Name, Type, SubType, Offset, Size, Flags
+nvs, data, nvs, 36K, 20K,
+factory, app, factory, 64K, 1900K, \ No newline at end of file
diff --git a/platformio.ini b/platformio.ini
new file mode 100644
index 0000000..92c0256
--- /dev/null
+++ b/platformio.ini
@@ -0,0 +1,28 @@
+; 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.partitions = min_part.csv
+lib_deps =
+ zinggjm/GxEPD2@^1.6.4
+ h2zero/NimBLE-Arduino@^2.3.2
+
+[env:esp32_ota]
+extends = env:esp32dev
+upload_protocol = espota
+upload_port = 172.16.8.1
+#upload_flags = --auth=xxx
+
+[platformio]
+build_cache_dir = ~/.cache/pio-ccache
diff --git a/src/main.cpp b/src/main.cpp
new file mode 100644
index 0000000..3613e36
--- /dev/null
+++ b/src/main.cpp
@@ -0,0 +1,107 @@
+#include <Arduino.h>
+
+#define GxEPD2_DISPLAY_CLASS GxEPD2_BW
+
+#include <GxEPD2_BW.h>
+#include <GxEPD2_3C.h>
+#include <Fonts/FreeMonoBold9pt7b.h>
+#include <Fonts/FreeMonoBold24pt7b.h>
+#include <NimBLEDevice.h>
+
+NimBLEServer *server;
+// HINT: Update the library code, set budy timeout to 30 or 60 seconds!
+// Small color
+// GxEPD2_3C<GxEPD2_213_Z19c, GxEPD2_213_Z19c::HEIGHT> display(GxEPD2_213_Z19c(22, 21, 17, 16));
+// latger b/w
+GxEPD2_BW<GxEPD2_290_T5, GxEPD2_290_T5::HEIGHT> display(GxEPD2_290_T5(22, 21, 17, 16));
+
+unsigned long pressedTime = 0;
+unsigned long releasedTime = 0;
+#define BUTTON_PIN 0
+#define LONG_PRESS_TIME 3000
+#define SLEEP_TIME 10000
+NimBLEAdvertising *pAdvertising;
+
+void display_helloWorld();
+
+void setup()
+{
+ Serial.begin(115200);
+ Serial.println("Yes, it works!");
+
+ NimBLEDevice::init("Espadge");
+ server = NimBLEDevice::createServer();
+ NimBLEService *service = new NimBLEService("ca260000-b4bb-46b2-bd06-b7b7a61ea990");
+ auto c = service->createCharacteristic("ca260001-b4bb-46b2-bd06-b7b7a61ea990");
+ service->start();
+ c->setValue("1");
+
+ server->addService(service);
+
+ pAdvertising = NimBLEDevice::getAdvertising();
+ pAdvertising->setName("NimBLE");
+ Serial.println("Init display...");
+ display.init(115200, true, 2, false); // USE THIS for Waveshare boards with "clever" reset circuit, 2ms reset pulse
+ display_helloWorld();
+ display.hibernate();
+ Serial.println("Display done.");
+
+ // doesn't work as expected?
+ // gpio_wakeup_enable(GPIO_NUM_0, GPIO_INTR_LOW_LEVEL);
+ // esp_sleep_enable_gpio_wakeup();
+ // esp_light_sleep_start();
+}
+
+void loop()
+{
+ static int lastState = HIGH;
+ int buttonState = digitalRead(BUTTON_PIN);
+ if (lastState == HIGH && buttonState == LOW)
+ {
+ Serial.println("``\\__");
+ pressedTime = millis();
+ lastState = LOW;
+ }
+ else if (lastState == LOW && buttonState == HIGH)
+ {
+ lastState = HIGH;
+ Serial.println("__/``");
+ releasedTime = millis();
+ long pressDuration = releasedTime - pressedTime;
+
+ if (pressDuration > LONG_PRESS_TIME && !pAdvertising->isAdvertising())
+ {
+ Serial.println("Long press detected. Starting advertising...");
+ pAdvertising->start(10000);
+ }
+
+ // if (millis() - releasedTime > SLEEP_TIME && !pAdvertising->isAdvertising())
+ // {
+ // Serial.println("Go to sleep...");
+ // esp_light_sleep_start();
+ // }
+ };
+}
+
+void display_helloWorld()
+{
+ // display.clearScreen();
+ static const char HelloWorld[] = "Hello World!";
+ display.setRotation(1);
+ display.setFont(&FreeMonoBold24pt7b);
+ display.setTextColor(GxEPD_BLACK);
+ int16_t tbx, tby;
+ uint16_t tbw, tbh;
+ display.getTextBounds(HelloWorld, 0, 0, &tbx, &tby, &tbw, &tbh);
+ // center the bounding box by transposition of the origin:
+ uint16_t x = ((display.width() - tbw) / 2) - tbx;
+ uint16_t y = ((display.height() - tbh) / 2) - tby;
+ display.setFullWindow();
+ display.firstPage();
+ do
+ {
+ display.fillScreen(GxEPD_YELLOW);
+ display.setCursor(x, y);
+ display.print(HelloWorld);
+ } while (display.nextPage());
+} \ No newline at end of file
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..9b1e87b
--- /dev/null
+++ b/test/README
@@ -0,0 +1,11 @@
+
+This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html