Skip to content

Commit babe34f

Browse files
authored
Feature/oneshot adc read all (#162)
* feat(adc): Add new read_all_mv API to OneshotAdc * Update how docs are built * update metadoc * doc: rebuild
1 parent f6a9c21 commit babe34f

File tree

109 files changed

+3595
-3489
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+3595
-3489
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ dependencies.lock
4444
# weird mac folders...
4545
.DS_Store
4646
lib/pc
47+
_build/
48+
__pycache__/

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This is the repository for some c++ components developed for the [ESP-IDF](https://github.com/espressif/esp-idf) farmework.
44

5-
* [Documentation](https://esp-cpp.github.io/espp/) - github hosted version of the documentation found in [./docs](./docs), which is built by running [./doc/build_docs.sh](./doc/build_docs.sh).
5+
* [Documentation](https://esp-cpp.github.io/espp/) - github hosted version of the documentation found in [./docs](./docs), which is built by running [./build_docs.sh](./build_docs.sh). NOTE: to ensure proper build environments, the documentation build now relies on docker, so you'll need to run `docker build -t esp-docs doc` once before running `build_docs.sh`.
66

77
Many components in this repo contain example code (referenced in the documentation above) that shows some basic usage. This example code can be found in that component's `example` directory. NOTE: many component examples also make use of other components (esp. some of the foundational components such as `format`, `logger`, and `task`.
88

build_docs.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
# NOTE: ensure you've built the docker image first by running
3+
# `docker build -t esp-docs doc`
4+
docker run --rm -v $PWD:/project -w /project -u $UID -e HOME=/tmp esp-docs ./docker_build_docs.sh

components/adc/example/main/adc_example.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,26 @@ extern "C" void app_main(void) {
2222
.channels = channels,
2323
});
2424
auto task_fn = [&adc, &channels](std::mutex &m, std::condition_variable &cv) {
25-
for (auto &conf : channels) {
26-
auto maybe_mv = adc.read_mv(conf);
27-
if (maybe_mv.has_value()) {
28-
fmt::print("{}: {} mV\n", conf, maybe_mv.value());
29-
} else {
30-
fmt::print("{}: no value!\n", conf);
25+
static bool use_individual_functions = false;
26+
if (use_individual_functions) {
27+
// this iteration, we'll use the read_mv function for each channel
28+
for (auto &conf : channels) {
29+
auto maybe_mv = adc.read_mv(conf);
30+
if (maybe_mv.has_value()) {
31+
fmt::print("{}: {} mV\n", conf, maybe_mv.value());
32+
} else {
33+
fmt::print("{}: no value!\n", conf);
34+
}
35+
}
36+
} else {
37+
// this iteration, we'll use the read_all_mv function to read all
38+
// configured channels
39+
auto voltages = adc.read_all_mv();
40+
for (const auto &mv : voltages) {
41+
fmt::print("{} mV\n", mv);
3142
}
3243
}
44+
use_individual_functions = !use_individual_functions;
3345
// NOTE: sleeping in this way allows the sleep to exit early when the
3446
// task is being stopped / destroyed
3547
{

components/adc/include/oneshot_adc.hpp

+24
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,30 @@ class OneshotAdc : public BaseComponent {
6565
}
6666
}
6767

68+
/**
69+
* @brief Take a new ADC reading for all configured channels and convert it to
70+
* voltage (mV) if the unit was properly calibrated. If it was not
71+
* properly calibrated, then it will return the same value as \c
72+
* read_raw().
73+
* @return std::vector<float> Voltage in mV for all configured channels (if
74+
* they were configured).
75+
*/
76+
std::vector<int> read_all_mv() {
77+
std::vector<int> values;
78+
values.reserve(configs_.size());
79+
for (const auto &config : configs_) {
80+
int raw = 0;
81+
auto err = adc_oneshot_read(adc_handle_, config.channel, &raw);
82+
if (err != ESP_OK) {
83+
logger_.error("Couldn't read oneshot: {} - '{}'", err, esp_err_to_name(err));
84+
values.push_back(0);
85+
} else {
86+
values.push_back(raw_to_mv(raw));
87+
}
88+
}
89+
return values;
90+
}
91+
6892
/**
6993
* @brief Take a new ADC reading for the provided \p config.
7094
* @param config The channel configuration to take a reading from.

components/adc/src/continuous_adc.cpp

-1
This file was deleted.

doc/Dockerfile

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# esp-docs doesn't currently support 3.12 (see https://github.com/espressif/esp-docs/issues/9)
2+
FROM python:3.11
3+
4+
WORKDIR /usr/src/app
5+
6+
# update apt-get
7+
RUN apt-get update
8+
9+
# install doxygen
10+
RUN apt-get install -y doxygen
11+
12+
COPY requirements.txt ./
13+
14+
RUN pip install --no-cache-dir -r requirements.txt

doc/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ For more information please see [ESP Docs](https://github.com/espressif/esp-docs
99
- [API Documentation Template](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/template.html)
1010
- [ESP-DOCS Add-Ons and Extensions Reference](https://github.com/espressif/esp-docs/blob/master/docs/add-ons-reference.md)
1111

12-
to build the documentation, simply run `./build_docs.sh`.
12+
13+
1. To ensure you can build the documentation, create a docker image for building the documentation `docker build -t esp-docs .` (from within this directory) or `docker build -t esp-docs doc` from within the top-level project / espp directory.
14+
15+
2. To build the documentation, simply run `./build_docs.sh` from within the top-level project / espp directory.

doc/build_docs.sh

-3
This file was deleted.

doc/requirements.txt

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This is a list of python packages used to generate documentation. This file is used with pip:
2+
# pip install --user -r requirements.txt
3+
#
4+
cairosvg
5+
6+
# we have to pin these versions or we get a "this project needs sphinx v5.0" error
7+
# see https://github.com/sphinx-doc/sphinx/issues/11890
8+
sphinxcontrib-applehelp==1.0.4
9+
sphinxcontrib-devhelp==1.0.2
10+
sphinxcontrib-htmlhelp==2.0.1
11+
sphinxcontrib-qthelp==1.0.3
12+
sphinxcontrib-serializinghtml==1.1.5
13+
14+
esp-docs==1.4.0

docker_build_docs.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
# add doc to the python path
3+
export PYTHONPATH=$PYTHONPATH:/project/doc
4+
# ensure we can run git commands
5+
git config --global --add safe.directory /project
6+
# build the docs
7+
build-docs -t esp32 -l en --project-path /project/ --source-dir /project/doc/ --doxyfile_dir /project/doc/
8+
# copy the docs to the docs folder
9+
cp -rf /project/_build/en/esp32/html/* /project/docs/.

docs/adc/adc_types.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
<li><a href="index.html">ADC APIs</a> &raquo;</li>
151151
<li>ADC Types</li>
152152
<li class="wy-breadcrumbs-aside">
153-
<a href="https://github.com/esp-cpp/espp/blob/fb7442bb/docs/en/adc/adc_types.rst" class="fa fa-github"> Edit on GitHub</a>
153+
<a href="https://github.com/esp-cpp/espp/blob/a3878d6f/docs/en/adc/adc_types.rst" class="fa fa-github"> Edit on GitHub</a>
154154
</li>
155155
</ul>
156156
<hr/>
@@ -167,7 +167,7 @@ <h2>API Reference<a class="headerlink" href="#api-reference" title="Permalink to
167167
<section id="header-file">
168168
<h3>Header File<a class="headerlink" href="#header-file" title="Permalink to this headline"></a></h3>
169169
<ul class="simple">
170-
<li><p><a class="reference external" href="https://github.com/esp-cpp/espp/blob/e14a4b5/components/adc/include/adc_types.hpp">components/adc/include/adc_types.hpp</a></p></li>
170+
<li><p><a class="reference external" href="https://github.com/esp-cpp/espp/blob/f6a9c216/components/adc/include/adc_types.hpp">components/adc/include/adc_types.hpp</a></p></li>
171171
</ul>
172172
</section>
173173
</section>

0 commit comments

Comments
 (0)