Skip to content

Commit

Permalink
Fixes for UnitTest and Some tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
GOB52 committed Aug 9, 2024
1 parent 6cd887a commit e868a2b
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 223 deletions.
183 changes: 0 additions & 183 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,186 +2,3 @@

**Work in progress**

**Currently this document is a developer's memo.**

The operation of TwoWire-based and experimental M5HAL-based components can be checked.

The final implementation will only use the M5HAL, but it has also been made to work on a TwoWire-based, so that development and testing can proceed without reliance on the M5HAL.

## For development and checking convenience, including those that are inherently separate repositories

### New repositories to be split in the future.

- lib/M5Utitliy
M5UnitUnified, M5UnitComponent, M5HAL, and other depends it.
- lib/M5UnitComponent
M5UnitUnified depends it.
- lib/M5PaHub
For PaHub
- lib/M5HAL
M5UnitComponent depends it.

### Add to existing libraries in the future

- lib/M5Unit-ENV
UnitComponent for SCD4x, SHT30, QMP6988...


## Implemented

- Similar API configurations as far as possible.
- Additional function
- Fixed and re-implemented problems in existing libraries

|Body \\ Unit|SCD40|SHT30|QMP6988|MAX30100|Vmeter|Ameter|SGP30|PAJ7620U|Kmeter|
|---|---|---|---|---|---|---|---|---|---|
|Core|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|
|Core2|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|
|Core3|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|
|StampS3|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|
|AtomS3|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|
|NanoC6|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|test,example|

## How to try examples (PlatformIO only)

If you want to try it on other devices, edit the ini accordingly.
**lib Once the repositories for each of the libraries below are in place, they can be compiled by ArduinoIDE.**

**Note that the M5HAL experimental version is not up-to-date and may have glitches**

### [env:example\_SCD40\_foo]

[examples/SCD4x/SCD4x.cpp](examples/SCD4x/SCD4x.cpp )

```cpp
#define USING_PAHUB (2) // Connection channel number for use via PaHub.
#define USING_M5HAL // Using M5HAL is defined
```
- Switch between TwoWire and M5HAL versions with and without USING_M5HAL defines
- Switch between directly connected and via PaHub versions with and without USING_PAHUB defines
**Connecting the SCD40 to the USING_PAHUB numbered channel.**
### [env:example\_ENV3\_foo]
[examples/UnitENV\_III/UnitENV\_III.cpp](examples/UnitENV_III/UnitENV_III.cpp)
```cpp
#define USING_SINGLE_SHOT // Using single shot measurement If defined
#define USING_ENV3 // Using combined unit if defined
```
- Switch between single instance versions of each chip and Env3 instance versions
- Switch between periodic and voluntary measurements

## How to try UnitTest (PlatformIO only)
This should be done with a direct connection, not via the Hub.

- env:test_foo
[Advanced]_ - [Test]

### Choose target unit
```ini
;test_filter= embedded/test_sht3x
;test_filter= embedded/test_qmp6988
test_filter= embedded/test_scd4x
```

## M5UnitComponent
- Basically, a unit is created for each chip. (UnitSHT30, UnitQMP6988...)
- When multiple chips are mounted, as in the case of ENVIII, it can be expressed as a form in which ENVIII holds each chip.
See also [unit\_ENV3.hpp](lib/M5Unit-ENV/src/unit/unit_ENV3.hpp)

**Should I create a unit with a product name, even if it is a single chip like a CO2 unit?**


## API Documentation
doxygen and pcregrep required

```.sh
bash docs/doxy.sh
open docs/html/index.html
```
Running the command with the respective current will output the respective document

- M5UnitUnified
- lib/M5UnitComponent
- lib/M5Utility
- lib/M5Unit-ENV



By adding to existing libraries, the reference manual can be developed from the source.
It would be useful to use GitHub Action to automatically generate documentation and publish it on GitHub Pages or m5doc upon master release.

## UnitTest
Create unit tests by googletest that are native (if possible) and embedded in each units.
This is necessary to check operation, isolate problems when they occur and prevent regressions.

The M5UnitUnified test checks for collisions between the unique IDs assigned to the units.
Unit-specific tests will be placed in the respective library repositories.
(Some working test are currently placed in examples for development convenience. Will be moved before release).


### Examples
The example of the UnitUnified itself depends on the connecting unit and will be added to the example in each unit's library.
(Some working examples are currently placed in examples for development convenience. Will be moved before release).


## Questions
### https://github.com/m5stack/M5Template-C-CPP/

.clang-format is much older.
There are items that have been changed in the current version, etc.
Prerequisite version is 13?
What about updating to the latest settings?
The number of column digits is 80, can it be made larger?


---
---
---
## Overview

### SKU:xxx

Description of the product

## Related Link

- [Document & Datasheet](https://docs.m5stack.com/en/unit/product_Link)

## Required Libraries:

- [Adafruit_BMP280_Library](https://github.com/adafruit/Required_Libraries_Link)

## License

- [Product Name- MIT](LICENSE)

## Remaining steps(Editorial Staff Look,After following the steps, remember to delete all the content below)

1. Change [clang format check path](./.github/workflows/clang-format-check.yml#L9-L15).
2. Add License content to [LICENSE](/LICENSE).
3. Change link on line 78 of [bug-report.yml](./.github/ISSUE_TEMPLATE/bug-report.yml#L78).

```cpp
Example
# M5Unit-ENV

## Overview

### SKU:U001 & U001-B & U001-C

Contains M5Stack-**UNIT ENV** series related case programs.ENV is an environmental sensor with integrated SHT30 and QMP6988 internally to detect temperature, humidity, and atmospheric pressure data.

## Related Link

- [Document & Datasheet](https://docs.m5stack.com/en/unit/envIII)

## Required Libraries:

- [Adafruit_BMP280_Library](https://github.com/adafruit/Adafruit_BMP280_Library)

## License

- [M5Unit-ENV - MIT](LICENSE)
```
4 changes: 2 additions & 2 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "M5UnitUnified",
"description": "Library for M5Stack/Core2/Tough/CoreS3, M5StickC/C-Plus, M5CoreInk, M5Paper, M5ATOM, M5STAMP, M5Station",
"description": "Library for M5 Units",
"keywords": "M5UnitUnified",
"authors": {
"name": "M5Stack",
Expand All @@ -19,7 +19,7 @@
}
],
"version": "0.0.0",
"frameworks": ["arduino", "espidf", "*"],
"frameworks": ["arduino", "espidf"],
"platforms": ["espressif32"],
"headers": "M5UnitUnified.h"
}
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name=M5UnitUnified
version=0.0.0
author=M5Stack
maintainer=M5Stack
sentence=Library for M5Stack/Core2/Tough/CoreS3, M5StickC/C-Plus, M5CoreInk, M5Paper, M5ATOM, M5STAMP, M5Station
paragraph=M5Stack, M5Stack Core2, M5Stack CoreInk, M5StickC, M5StickC-Plus, M5Paper, M5Tough, M5ATOM, M5STAMP, M5Station, See more on http://M5Stack.com
sentence=Library for M5 Units
paragraph=
category=Other
url=https://github.com/m5stack/M5UnitUnified.git
architectures=esp32
Expand Down
38 changes: 27 additions & 11 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,34 @@
[platformio]

[env]
build_flags =-Wall -Wextra -Wreturn-local-addr -Werror=format -Werror=return-local-addr
build_flags = -Wall -Wextra -Wreturn-local-addr -Werror=format -Werror=return-local-addr
-I"./src"

lib_ldf_mode = deep
test_framework = googletest
test_build_src = true
lib_deps=m5stack/M5Unified
https://github.com/m5stack/M5Utility#develop
https://github.com/m5stack/M5HAL#develop
https://github.com/boschsensortec/Bosch-BME68x-Library.git

extra_scripts = pre:custom_script.py
custom_exclude_src_files=bme68xLibrary.cpp bsec2.cpp
https://github.com/m5stack/M5Unit-ENV/#develop
https://github.com/m5stack/M5Unit-METER/#develop
https://github.com/m5stack/M5Unit-HEART/#develop
https://github.com/m5stack/M5Unit-HUB/#develop
https://github.com/m5stack/M5Unit-GESTURE/#develop
https://github.com/m5stack/M5Unit-KMeterISO/#develop
https://github.com/m5stack/M5Unit-TVOC/#develop
https://github.com/m5stack/M5Unit-RFID/#develop

; --------------------------------
[m5base]
monitor_speed = 115200
monitor_filters = esp32_exception_decoder, time
upload_speed = 1500000
test_speed = 115200
test_filter= embedded/*
test_filter= embedded/test_update
test_ignore= native/*

;Arduino-esp 2.0.4 (Changed Wire) at 5.1.0
platform = espressif32 @6.6.0
platform = espressif32 @6.8.0
;platform = espressif32 @ 5.0.0
framework = arduino

Expand Down Expand Up @@ -104,7 +109,7 @@ build_flags = -O3 -xc++ -std=c++14 -lSDL2
platform = native
test_filter= native/*
test_ignore= embedded/*
lib_deps = ${env.lib_deps}
lib_deps = ${env.lib_deps}

; --------------------------------
;Choose build options
Expand Down Expand Up @@ -147,59 +152,70 @@ lib_deps = google/[email protected]
; --------------------------------
[env:test_native]
extends = sdl, option_release
build_flags = ${sdl.build_flags} ${option_release.build_flags}
build_flags = ${sdl.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${sdl.lib_deps}
${test_fw.lib_deps}
lib_ignore=https://github.com/boschsensortec/Bosch-BSEC2-Library.git
lib_compat_mode= off
extra_scripts = pre:custom_script.py
custom_exclude_src_files=bme68xLibrary.cpp bsec2.cpp BMP280.cpp DHT12.cpp I2C_Class.cpp SCD4X.cpp SHT3X.cpp QMP6988.cpp SHT4X.cpp utility.cpp /M5UnitKmeterISO.cpp

[env:test_Core]
extends=Core, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${Core.lib_deps}
${test_fw.lib_deps}

[env:test_Core2]
extends=Core2, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${Core2.lib_deps}
${test_fw.lib_deps}

[env:test_CoreS3]
extends=CoreS3, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${CoreS3.lib_deps}
${test_fw.lib_deps}

[env:test_Fire]
extends=Fire, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${Fire.lib_deps}
${test_fw.lib_deps}

[env:test_StampS3]
extends=StampS3, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${StampS3.lib_deps}
${test_fw.lib_deps}

[env:test_Dial]
extends=StampS3, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${StampS3.lib_deps}
${test_fw.lib_deps}
m5stack/M5Dial

[env:test_AtomS3]
extends=AtomS3, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${AtomS3.lib_deps}
${test_fw.lib_deps}

[env:test_NanoC6]
extends=NanoC6, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${NanoC6.lib_deps}
${test_fw.lib_deps}

[env:test_StickCPlus]
extends=StickCPlus, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${StickCPlus.lib_deps}
${test_fw.lib_deps}

[env:test_Paper]
extends=Paper, option_release
build_flags = ${env.build_flags} ${option_release.build_flags} -I${PROJECT_DIR}/.pio/libdeps/test_CoreS3/M5HAL/src
lib_deps = ${Paper.lib_deps}
${test_fw.lib_deps}
2 changes: 1 addition & 1 deletion src/M5UnitUnified.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@file M5UnitUnified.hpp
@brief Main header of M5UnitUnified
@mainpage M5UnitUnfied
@mainpage M5UnitUnified
Library for abstracted M5 units. C++11 or later
*/
#ifndef M5_UNIT_UNIFIED_HPP
Expand Down
2 changes: 1 addition & 1 deletion src/m5_unit_component/adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#ifndef M5_UNIT_COMPONENT_ADAPTER_HPP
#define M5_UNIT_COMPONENT_ADAPTER_HPP

#include <m5_hal/error.hpp> // M5HAL
#include <cstdint>
#include <cstddef>
#include <memory>
#include <m5_hal/error.hpp>

class TwoWire;
namespace m5 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <M5UnitComponent.hpp>
#include <M5UnitUnified.hpp>
#include "unit_dummy.hpp"
#include <Wire.hpp>
#include <Wire.h>

using namespace m5::unit;

TEST(Component, basic) {
TEST(Component, Update) {
UnitUnified units;
UnitDummy u;
EXPECT_FALSE(u.isRegistered());
Expand All @@ -25,6 +25,11 @@ TEST(Component, basic) {

EXPECT_EQ(u.count, 0U);
EXPECT_TRUE(units.add(u, Wire));

units.update(); // Dont call u.update() because unit was not begun.
EXPECT_EQ(u.count, 0U);

EXPECT_TRUE(units.begin());
units.update(); // Call u.update()
EXPECT_EQ(u.count, 1U);

Expand All @@ -35,6 +40,7 @@ TEST(Component, basic) {

units.update(); // Don't call u.update()
EXPECT_EQ(u.count, 1U);

u.update(); // If component_config.iself_update is true, you have to
// call it yourself
EXPECT_EQ(u.count, 2U);
Expand Down
Loading

0 comments on commit e868a2b

Please sign in to comment.