Skip to content

Commit 2298774

Browse files
committed
initial import
0 parents  commit 2298774

File tree

7 files changed

+225
-0
lines changed

7 files changed

+225
-0
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
CMakeListsPrivate.txt
3+
cmake-build-*/
4+
.idea
5+
*.iml

CMakeLists.txt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# !!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE
2+
# https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
3+
#
4+
# If you need to override existing CMake configuration or add extra,
5+
# please create `CMakeListsUser.txt` in the root of project.
6+
# The `CMakeListsUser.txt` will not be overwritten by PlatformIO.
7+
8+
cmake_minimum_required(VERSION 3.13)
9+
set(CMAKE_SYSTEM_NAME Generic)
10+
set(CMAKE_C_COMPILER_WORKS 1)
11+
set(CMAKE_CXX_COMPILER_WORKS 1)
12+
13+
project("oxyan" C CXX)
14+
15+
include(CMakeListsPrivate.txt)
16+
17+
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/CMakeListsUser.txt)
18+
include(CMakeListsUser.txt)
19+
endif()
20+
21+
add_custom_target(
22+
Production ALL
23+
COMMAND platformio -c clion run "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
24+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
25+
)
26+
27+
add_custom_target(
28+
Debug ALL
29+
COMMAND platformio -c clion debug "$<$<NOT:$<CONFIG:All>>:-e${CMAKE_BUILD_TYPE}>"
30+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
31+
)
32+
33+
add_executable(Z_DUMMY_TARGET ${SRC_LIST})

include/README

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

platformio.ini

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:leonardo]
12+
platform = atmelavr
13+
board = leonardo
14+
framework = arduino
15+
lib_deps =
16+
mathertel/LiquidCrystal_PCF8574 @ ^2.1.0
17+
adafruit/Adafruit ADS1X15 @ ^2.4.0

src/main.cpp

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include <Arduino.h>
2+
#include <SPI.h>
3+
#include <LiquidCrystal_PCF8574.h>
4+
#include <Adafruit_ADS1X15.h>
5+
6+
#define CAL_COUNT 100
7+
#define AIR_PCT 20.9
8+
9+
LiquidCrystal_PCF8574 lcd(0x27);
10+
Adafruit_ADS1115 ads;
11+
bool isError = false;
12+
double airMv = 10;
13+
14+
int cmpint16(const void *a, const void *b) {
15+
return (*(int16_t *) a - *(int16_t *) b);
16+
}
17+
18+
void calibrate() {
19+
int16_t measurements[CAL_COUNT];
20+
for (int &measurement: measurements) {
21+
measurement = ads.readADC_Differential_0_1();
22+
}
23+
24+
qsort(measurements, CAL_COUNT, sizeof(int16_t), cmpint16);
25+
int32_t sum = 0;
26+
int16_t count = 0;
27+
for (int i = CAL_COUNT / 10; i < CAL_COUNT - (CAL_COUNT / 10); i++) {
28+
sum += measurements[i];
29+
count++;
30+
}
31+
32+
auto airAdc = (int16_t)((double)sum / count);
33+
airMv = ads.computeVolts(airAdc) * 1000;
34+
}
35+
36+
void setup() {
37+
lcd.begin(16, 2);
38+
lcd.setBacklight(255);
39+
lcd.home();
40+
lcd.clear();
41+
42+
if (!ads.begin()) {
43+
lcd.print("Error initializing ADS1115");
44+
isError = true;
45+
}
46+
47+
ads.setGain(GAIN_SIXTEEN);
48+
calibrate();
49+
}
50+
51+
void loop() {
52+
if (isError) {
53+
delay(100);
54+
return;
55+
}
56+
57+
int16_t adcSensor = ads.readADC_Differential_0_1();
58+
59+
double nowMv = ads.computeVolts(adcSensor) * 1000;
60+
61+
lcd.clear();
62+
lcd.home();
63+
lcd.print(nowMv);
64+
lcd.print("mV");
65+
66+
double nowPct = (AIR_PCT / airMv) * nowMv;
67+
68+
lcd.setCursor(0, 1);
69+
70+
lcd.print(nowPct);
71+
lcd.print("%");
72+
73+
delay(200);
74+
}

test/README

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Test Runner and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

0 commit comments

Comments
 (0)