initcode
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
.pio
|
||||||
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
||||||
39
include/README
Normal file
39
include/README
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
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 usual convention is to give header files names that end with `.h'.
|
||||||
|
It is most portable to use only letters, digits, dashes, and underscores in
|
||||||
|
header file names, and at most one dot.
|
||||||
|
|
||||||
|
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
lib/README
Normal file
46
lib/README
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
This directory is intended for project specific (private) libraries.
|
||||||
|
PlatformIO will compile them to static libraries and link into executable file.
|
||||||
|
|
||||||
|
The source code of each library should be placed in a an own separate directory
|
||||||
|
("lib/your_library_name/[here are source files]").
|
||||||
|
|
||||||
|
For example, see a structure of the following two libraries `Foo` and `Bar`:
|
||||||
|
|
||||||
|
|--lib
|
||||||
|
| |
|
||||||
|
| |--Bar
|
||||||
|
| | |--docs
|
||||||
|
| | |--examples
|
||||||
|
| | |--src
|
||||||
|
| | |- Bar.c
|
||||||
|
| | |- Bar.h
|
||||||
|
| | |- library.json (optional, 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
|
||||||
|
|
||||||
|
and a contents of `src/main.c`:
|
||||||
|
```
|
||||||
|
#include <Foo.h>
|
||||||
|
#include <Bar.h>
|
||||||
|
|
||||||
|
int main (void)
|
||||||
|
{
|
||||||
|
...
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
PlatformIO Library Dependency Finder will find automatically dependent
|
||||||
|
libraries scanning project source files.
|
||||||
|
|
||||||
|
More information about PlatformIO Library Dependency Finder
|
||||||
|
- https://docs.platformio.org/page/librarymanager/ldf.html
|
||||||
15
platformio.ini
Normal file
15
platformio.ini
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
; 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
|
||||||
|
lib_deps = erropix/ESP32 AnalogWrite@^0.2
|
||||||
195
src/main.cpp
Normal file
195
src/main.cpp
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#include "analogWrite.h"
|
||||||
|
|
||||||
|
#define DIM_FL 18 //
|
||||||
|
#define DIM_FR 27 //
|
||||||
|
#define BLINK_FL 4
|
||||||
|
#define BLINK_FR 17 //
|
||||||
|
#define DIM_RL 14
|
||||||
|
#define DIM_RR 26 //
|
||||||
|
#define INTERIOUR 5 //
|
||||||
|
|
||||||
|
#define BLINKSPEED 400
|
||||||
|
|
||||||
|
#define NUM_LEDS 7
|
||||||
|
#define DIM_TIME 1000
|
||||||
|
#define DIM_RES 1024
|
||||||
|
#define DIM_STEP 255
|
||||||
|
#define DIM_STEPMS (DIM_TIME / DIM_STEP)
|
||||||
|
|
||||||
|
uint64_t lastmillis = 0;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
Dim_FL,
|
||||||
|
Dim_FR,
|
||||||
|
Dim_RL,
|
||||||
|
Dim_RR,
|
||||||
|
Blink_FL,
|
||||||
|
Blink_FR,
|
||||||
|
Interiour
|
||||||
|
} e_leds;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
led_off,
|
||||||
|
led_dim_on,
|
||||||
|
led_on,
|
||||||
|
led_dim_off,
|
||||||
|
led_blink
|
||||||
|
} e_ledstate;
|
||||||
|
|
||||||
|
class c_led
|
||||||
|
{
|
||||||
|
//const e_leds _led;
|
||||||
|
const uint8_t _pin;
|
||||||
|
e_ledstate _state;
|
||||||
|
uint64_t _timer;
|
||||||
|
uint32_t _dimmer;
|
||||||
|
bool _newstate;
|
||||||
|
uint64_t _dimstepms;
|
||||||
|
uint32_t _dimstep;
|
||||||
|
|
||||||
|
public:
|
||||||
|
c_led(uint8_t pin) : _pin(pin)
|
||||||
|
{
|
||||||
|
if (DIM_STEP == 0 || DIM_TIME < DIM_STEP)
|
||||||
|
{
|
||||||
|
_dimstepms = 1;
|
||||||
|
_dimstep = 10;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dimstepms = DIM_TIME / DIM_STEP;
|
||||||
|
_dimstep = DIM_RES / DIM_STEP;
|
||||||
|
}
|
||||||
|
_dimmer = 0;
|
||||||
|
_timer = 0;
|
||||||
|
_state = led_off;
|
||||||
|
_newstate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void begin(void)
|
||||||
|
{
|
||||||
|
pinMode(_pin, OUTPUT);
|
||||||
|
digitalWrite(_pin, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void update(void)
|
||||||
|
{
|
||||||
|
switch (_state)
|
||||||
|
{
|
||||||
|
case led_off:
|
||||||
|
{
|
||||||
|
digitalWrite(_pin, false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case led_dim_on:
|
||||||
|
{
|
||||||
|
if (_newstate)
|
||||||
|
{
|
||||||
|
_dimmer = 0;
|
||||||
|
_timer = millis();
|
||||||
|
}
|
||||||
|
uint64_t currentmillis = millis();
|
||||||
|
if (currentmillis - _timer > _dimstepms)
|
||||||
|
{
|
||||||
|
_timer = currentmillis;
|
||||||
|
analogWrite(_pin, _dimmer, DIM_RES);
|
||||||
|
_dimmer += _dimstep;
|
||||||
|
}
|
||||||
|
if (_dimmer > DIM_RES)
|
||||||
|
{
|
||||||
|
setState(led_on);
|
||||||
|
}
|
||||||
|
_newstate = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case led_on:
|
||||||
|
{
|
||||||
|
digitalWrite(_pin, true);
|
||||||
|
_newstate = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void setState(e_ledstate newstate)
|
||||||
|
{
|
||||||
|
_state = newstate;
|
||||||
|
_newstate = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void toggle(void)
|
||||||
|
{
|
||||||
|
switch (_state)
|
||||||
|
{
|
||||||
|
|
||||||
|
case led_on:
|
||||||
|
setState(led_off);
|
||||||
|
break;
|
||||||
|
case led_dim_on:
|
||||||
|
setState(led_off);
|
||||||
|
break;
|
||||||
|
case led_off:
|
||||||
|
setState(led_on);
|
||||||
|
break;
|
||||||
|
case led_dim_off:
|
||||||
|
setState(led_on);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
setState(led_off);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
c_led ledarray[] = {
|
||||||
|
c_led(DIM_FL),
|
||||||
|
c_led(DIM_FR),
|
||||||
|
c_led(DIM_RL),
|
||||||
|
c_led(DIM_RR),
|
||||||
|
c_led(BLINK_FL),
|
||||||
|
c_led(BLINK_FR),
|
||||||
|
c_led(INTERIOUR)};
|
||||||
|
|
||||||
|
void sceneBlinkLeft(void)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// put your setup code here, to run once:
|
||||||
|
for (auto led : ledarray)
|
||||||
|
{
|
||||||
|
led.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
analogWriteResolution(10);
|
||||||
|
|
||||||
|
ledarray[Dim_FL].setState(led_on);
|
||||||
|
ledarray[Dim_FR].setState(led_on);
|
||||||
|
ledarray[Dim_RL].setState(led_on);
|
||||||
|
ledarray[Dim_RR].setState(led_on);
|
||||||
|
ledarray[Interiour].setState(led_on);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
for (auto led : ledarray)
|
||||||
|
{
|
||||||
|
led.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t currentmillis = millis();
|
||||||
|
if (currentmillis - lastmillis > BLINKSPEED)
|
||||||
|
{
|
||||||
|
ledarray[Blink_FR].toggle();
|
||||||
|
ledarray[Blink_FL].toggle();
|
||||||
|
ledarray[Dim_FL].toggle();
|
||||||
|
ledarray[Dim_FR].toggle();
|
||||||
|
ledarray[Dim_RL].toggle();
|
||||||
|
ledarray[Dim_RR].toggle();
|
||||||
|
lastmillis = currentmillis;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
test/README
Normal file
11
test/README
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
This directory is intended for PlatformIO Unit Testing 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/page/plus/unit-testing.html
|
||||||
Reference in New Issue
Block a user