first
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||||
+46
@@ -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
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[env:adalogger]
|
||||||
|
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||||
|
board = adafruit_feather
|
||||||
|
framework = arduino
|
||||||
|
board_build.core = earlephilhower
|
||||||
|
monitor_speed = 115200
|
||||||
|
build_flags =
|
||||||
|
-DUSE_TINYUSB
|
||||||
|
lib_deps =
|
||||||
|
adafruit/Adafruit SSD1306
|
||||||
|
adafruit/Adafruit GFX Library
|
||||||
|
adafruit/Adafruit TinyUSB Library
|
||||||
|
adafruit/SdFat - Adafruit Fork
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
pio run -t upload
|
||||||
|
|
||||||
|
~/PlatformIO/Projects/Player
|
||||||
+103
@@ -0,0 +1,103 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include <SPI.h>
|
||||||
|
#include <Adafruit_GFX.h>
|
||||||
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
|
// OLED on SPI1 (SCK = GP14, MOSI = GP15)
|
||||||
|
// If your display worked with other pins, change these three lines.
|
||||||
|
#define OLED_CS 9
|
||||||
|
#define OLED_DC 6
|
||||||
|
#define OLED_RST 5
|
||||||
|
|
||||||
|
|
||||||
|
#define BAT_PIN A3 // GP29, battery voltage / 2
|
||||||
|
#define SAMPLES 16
|
||||||
|
|
||||||
|
Adafruit_SSD1306 display(128, 64, &SPI1, OLED_DC, OLED_RST, OLED_CS);
|
||||||
|
|
||||||
|
struct BatPoint { float v; int pct; };
|
||||||
|
const BatPoint CURVE[] = {
|
||||||
|
{4.20f, 100}, {4.10f, 90}, {4.00f, 80}, {3.92f, 70}, {3.87f, 60},
|
||||||
|
{3.82f, 50}, {3.79f, 40}, {3.75f, 30}, {3.70f, 20}, {3.60f, 10},
|
||||||
|
{3.50f, 5}, {3.30f, 0}
|
||||||
|
};
|
||||||
|
const int CURVE_N = sizeof(CURVE) / sizeof(CURVE[0]);
|
||||||
|
|
||||||
|
float readVolts() {
|
||||||
|
uint32_t sum = 0;
|
||||||
|
for (int i = 0; i < SAMPLES; i++) sum += analogRead(BAT_PIN);
|
||||||
|
return (sum / (float)SAMPLES) * 3.3f / 4095.0f * 3.55f;
|
||||||
|
}
|
||||||
|
|
||||||
|
int voltsToPercent(float v) {
|
||||||
|
if (v >= CURVE[0].v) return 100;
|
||||||
|
if (v <= CURVE[CURVE_N - 1].v) return 0;
|
||||||
|
for (int i = 0; i < CURVE_N - 1; i++) {
|
||||||
|
if (v <= CURVE[i].v && v > CURVE[i + 1].v) {
|
||||||
|
float frac = (v - CURVE[i + 1].v) / (CURVE[i].v - CURVE[i + 1].v);
|
||||||
|
return CURVE[i + 1].pct + (int)(frac * (CURVE[i].pct - CURVE[i + 1].pct) + 0.5f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawBatteryIcon(int x, int y, int pct) {
|
||||||
|
display.drawRect(x, y, 26, 12, SSD1306_WHITE);
|
||||||
|
display.fillRect(x + 26, y + 3, 3, 6, SSD1306_WHITE);
|
||||||
|
int w = map(constrain(pct, 0, 100), 0, 100, 0, 22);
|
||||||
|
display.fillRect(x + 2, y + 2, w, 8, SSD1306_WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
analogReadResolution(12);
|
||||||
|
|
||||||
|
|
||||||
|
SPI1.setSCK(14);
|
||||||
|
SPI1.setTX(15);
|
||||||
|
if (!display.begin(SSD1306_SWITCHCAPVCC)) {
|
||||||
|
Serial.println("OLED init failed");
|
||||||
|
while (true);
|
||||||
|
}
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
display.setTextSize(2);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.print("Hello");
|
||||||
|
display.display();
|
||||||
|
delay(1500);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
float volts = readVolts();
|
||||||
|
int pct = voltsToPercent(volts);
|
||||||
|
|
||||||
|
Serial.print(volts, 2);
|
||||||
|
Serial.print(" V ");
|
||||||
|
Serial.print(pct);
|
||||||
|
Serial.println(" %");
|
||||||
|
|
||||||
|
display.clearDisplay();
|
||||||
|
display.setTextColor(SSD1306_WHITE);
|
||||||
|
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 0);
|
||||||
|
display.print("Battery");
|
||||||
|
|
||||||
|
display.setTextSize(3);
|
||||||
|
display.setCursor(0, 18);
|
||||||
|
display.print(pct);
|
||||||
|
display.print('%');
|
||||||
|
|
||||||
|
display.setTextSize(1);
|
||||||
|
display.setCursor(0, 54);
|
||||||
|
display.print(volts, 2);
|
||||||
|
display.print(" V");
|
||||||
|
|
||||||
|
drawBatteryIcon(96, 52, pct);
|
||||||
|
|
||||||
|
display.display();
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
+11
@@ -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
|
||||||
Reference in New Issue
Block a user