auf VSCode mit PlatformIO umgestellt.

This commit is contained in:
Toberfra
2022-02-04 19:22:43 +01:00
parent 3b9117669d
commit ba5ee42fce
13 changed files with 258 additions and 149 deletions

5
Arduino/motor/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View 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
Arduino/motor/lib/README Normal file
View 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

View File

@ -0,0 +1,14 @@
; 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:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino

View File

@ -0,0 +1,23 @@
#include "KlappenAblauf.h"
// Constructors/Destructors
//
KlappenAblauf::~KlappenAblauf()
{
}
//
// Methods
//
// Accessor methods
//
// Other methods
//

View File

@ -0,0 +1,52 @@
#ifndef KLAPPENABLAUF_H
#define KLAPPENABLAUF_H
#include "KlappenSteuerung.h"
/**
* class KlappenAblauf
*
*/
class KlappenAblauf : public KlappenSteuerung
{
public:
// Constructors/Destructors
//
/**
* Empty Constructor
*/
KlappenAblauf();
/**
* Empty Destructor
*/
virtual ~KlappenAblauf();
// Static Public attributes
//
// Public attributes
//
protected:
// Static Protected attributes
//
// Protected attributes
//
private:
// Static Private attributes
//
// Private attributes
//
};
#endif // KLAPPENABLAUF_H

View File

@ -0,0 +1,72 @@
#include "KlappenSteuerung.h"
// Constructors/Destructors
//
/**
* @param pinA
* @param pinB
* @param pinPwm
* @param pinSense
* @param id
*/
KlappenSteuerung::KlappenSteuerung(int pin_A, int pin_B, int pin_Pwm, int pin_Sense, int i_d)
{
initAttributes();
pinA = pin_A;
pinB = pin_B;
pinPwm = pin_Pwm;
pinSense = pin_Sense;
id = i_d;
}
KlappenSteuerung::~KlappenSteuerung()
{
}
//
// Methods
//
// Accessor methods
//
// Other methods
//
/**
*/
void KlappenSteuerung::setup()
{
}
/**
*/
void KlappenSteuerung::loop()
{
}
/**
* @param open
*/
void KlappenSteuerung::setOpen(bool open)
{
}
void KlappenSteuerung::initAttributes()
{
pinA = -1;
pinB = -1;
pinPwm = -1;
pinSense = -1;
id = -1;
status = NICHTS;
}

View File

@ -0,0 +1,88 @@
#ifndef KLAPPENSTEUERUNG_H
#define KLAPPENSTEUERUNG_H
#include "statusKlappen.h"
/**
* class KlappenSteuerung
*
*/
class KlappenSteuerung
{
public:
// Constructors/Destructors
//
/**
* Empty Constructor
*/
//KlappenSteuerung();
/**
* Empty Destructor
*/
virtual ~KlappenSteuerung();
// Static Public attributes
//
// Public attributes
//
/**
* @param pinA
* @param pinB
* @param pinPwm
* @param pinSense
* @param id
*/
KlappenSteuerung(int pinA, int pinB, int pinPwm, int pinSense, int id);
/**
*/
void setup();
/**
*/
void loop();
/**
* @param open
*/
void setOpen(bool open);
protected:
// Static Protected attributes
//
// Protected attributes
//
int pinA;
int pinB;
int pinPwm;
int pinSense;
int id;
statusKlappen status;
private:
// Static Private attributes
//
// Private attributes
//
void initAttributes();
};
#endif // KLAPPENSTEUERUNG_H

View File

@ -0,0 +1,69 @@
#include <Arduino.h>
#include "pins.h"
#include "KlappenSteuerung.h"
void Ablauf();
void AblaufSekunde();
KlappenSteuerung klappe1 (M1A , M1B , M1PWM , M1SENSE , 5 );
KlappenSteuerung klappe2 (M2A , M2B , M2PWM , M2SENSE , 2 );
KlappenSteuerung klappe3 (M3A , M3B , M3PWM , M3SENSE , 23 );
KlappenSteuerung klappe4 (M4A , M4B , M4PWM , M4SENSE , 1 );
void setup() {
// put your setup code here, to run once:
klappe1.setup();
klappe2.setup();
klappe3.setup();
klappe4.setup();
}
void loop() {
// put your main code here, to run repeatedly:
klappe1.loop();
klappe2.loop();
klappe3.loop();
klappe4.loop();
Ablauf();
}
void Ablauf(){
static unsigned long alteZeit;
static unsigned int summeZeit;
unsigned long neueZeit;
unsigned int deltaZeit;
neueZeit = millis();
deltaZeit = (unsigned int) (neueZeit - alteZeit);
alteZeit = neueZeit;
summeZeit += deltaZeit;
if(summeZeit >= 1000){ // eine Sekunde
summeZeit -= 1000;
AblaufSekunde();
}
}
void AblaufSekunde(){
static unsigned int sekunden;
sekunden ++;
switch(sekunden){
case 1:
klappe1.setOpen(true);
break;
case 11:
klappe1.setOpen(false);
break;
case 19:
sekunden = 0;
break;
}
}

28
Arduino/motor/src/pins.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef PINS_H
#define PINS_H
#define M1A 2
#define M1B 3
#define M1PWM 5
#define M1SENSE 1
#define M2A 4
#define M2B 7
#define M2PWM 6
#define M2SENSE 2
#define M3A 8
#define M3B 11
#define M3PWM 9
#define M3SENSE 3
#define M4A 12
#define M4B 13
#define M4PWM 10
#define M4SENSE 4
#endif // PINS_H

View File

@ -0,0 +1,15 @@
#ifndef STATUS_H
#define STATUS_H
typedef enum statusKlappenenum{
NICHTS,
}statusKlappen;
#endif

11
Arduino/motor/test/README Normal file
View 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