Initial commit

This commit is contained in:
Kosmo Obermayer 2023-12-06 08:02:16 +01:00
commit 5907c6f197
13 changed files with 682 additions and 0 deletions

5
.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

10
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,10 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}

39
include/README Normal file
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
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

15
platformio.ini Normal file
View 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:esp32-s2-saola-1]
platform = espressif32
board = esp32-s2-saola-1
framework = arduino
monitor_speed = 115200

37
src/BACKUp_BLACKWHITE.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
#include <Arduino.h>
#define AO 14 // Analog Output //
#define DO 13 // Digital Output //
#define CLK 10 // display as usual //
#define DIO 11
class VALUES
{
public:
int DigVal;
int AnlVal;
};
void setup()
{
pinMode(AO, INPUT);
pinMode(DO, INPUT);
Serial.begin(9600);
}
void loop()
{
VALUES Wert;
Wert.DigVal = analogRead(AO);
Wert.AnlVal = digitalRead(DO);
Serial.printf("Analog: %d Digital: %d\n", Wert.AnlVal, Wert.DigVal);
}
*/

150
src/OLD_PROGRAMM.cpp Normal file
View File

@ -0,0 +1,150 @@
/*
#include <Arduino.h>
#define AnalogPIN 14
#define DigitalPIN
class WERTE
{
public:
int ANL = 0;
unsigned long int NewTime = 0;
unsigned long int NTBackup = 0;
unsigned long int OldTime = 0;
unsigned long int Delta = 0;
double IN_STUNDEN = 0;
double WATT = 0;
}Mess;
class VARIABLEN
{
public:
int COUNT = 0;
int TIMESTAMP = 0;
int CAST = 0; // Für delta -> Watt //
double PLACE = 0;
bool FLAG = false;
bool SIGNAL = false;
}VAR;
// Funktionen_prototypen: //
void nochimmer();
void check();
void calc();
void setup()
{
void IRAM_ATTR onTimer();
hw_timer_t *My_timer = 0;
My_timer = timerBegin(0, 80, true);
timerAttachInterrupt(My_timer, &onTimer, true);
timerAlarmWrite(My_timer, 5000, true);
timerAlarmEnable(My_timer);
Serial.begin(115200);
}
void loop()
{
//Serial.println(Mess.ANL);
if(Mess.ANL >= 450)
{
check(); // Zeit New & Old richtig einlesen && Aufrufen von NOCHIMMER() //
}
}
void IRAM_ATTR onTimer()
{
Mess.ANL = analogRead(AnalogPIN);
}
void nochimmer()
{
VAR.COUNT = 0;
while(1)
{
if(VAR.COUNT > 15)
{
break;
}
VAR.TIMESTAMP = millis() + 6;
while((VAR.TIMESTAMP - millis()) > 0){millis();};
if(Mess.ANL < 430)
{
VAR.COUNT++;
}
else
{
continue;
}
}
Serial.printf("\n\n\n\nSUCCESS\n\n\n\n");
calc(); // Ausrechnen von Delta, Watt und eventueller Output //
}
void check()
{
Mess.NTBackup = Mess.NewTime;
Mess.NewTime = millis();
VAR.COUNT = 0;
VAR.FLAG = false;
while(VAR.COUNT != 4 && VAR.FLAG != true)
{
VAR.TIMESTAMP = millis() + 6;
while((VAR.TIMESTAMP - millis()) > 0){millis();}; // Warte 5ms auf neuen Wert //
// Serial.printf("ANL: %d\n", Mess.ANL);
if(Mess.ANL >= 450)
{
VAR.COUNT++;
}
else
{
VAR.FLAG = true;
}
}
Serial.println("-----------------------------------");
if(VAR.FLAG == true)
{
Mess.NewTime = Mess.NTBackup;
// Serial.println("...");
}
else
{
Mess.OldTime = Mess.NTBackup;
// Serial.printf("TIME: %d\n", Mess.NewTime);
nochimmer(); // Überprüfen, ob statement noch immer zutrifft //
}
}
void calc()
{
if(Mess.OldTime != 0)
{
Mess.Delta = Mess.NewTime - Mess.OldTime;
VAR.CAST = Mess.Delta;
VAR.PLACE = VAR.CAST / 1000;
Mess.IN_STUNDEN = 60 * (60 / VAR.PLACE);
Mess.WATT = (1000 * Mess.IN_STUNDEN) / 960;
// OUTPUT //
Serial.printf("Momentanverbauch: DELTA: %d WATT: %0.2f\n", Mess.Delta, Mess.WATT);
}
}
*/

18
src/Variablen.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef VARIABLEN_H
#define VARIABLEN_H
#include <Werte.h>
class Variablen
{
protected:
static int _count;
static int _timestamp;
static int _cast; // Für delta -> Watt //
static double _place; // placeholder //
// boolsche Attribute //
static bool _flag;
};
#endif

116
src/Werte.cpp Normal file
View File

@ -0,0 +1,116 @@
#include <Werte.h>
#include <Variablen.h>
// 1st initialization: Werte //
int Werte::_anl = 0;
unsigned long Werte::_new_time = 0;
unsigned long Werte::_nt_backup = 0;
unsigned long Werte::_old_time = 0;
unsigned long Werte::_delta = 0;
double Werte::_watt = 0;
double Werte::_in_stunden = 0;
// 1st initialization: Variablen //
int Variablen::_count = 0;
int Variablen::_cast = 0;
int Variablen::_timestamp = 0;
double Variablen::_place = 0;
bool Variablen::_flag = false;
void Werte::set_ANL(int var)
{
_anl = var;
}
int Werte::get_ANL()
{
return _anl;
}
// Checkt ab, ob der Wert kein Fehlwert war //
void Werte::check()
{
_nt_backup = _new_time;
_new_time = millis();
_count = 0;
_flag = false;
while(_count != 4 && _flag != true)
{
_timestamp = millis() + 6;
// Warte 5ms auf neuen Wert //
while((_timestamp - millis()) > 0){millis();};
if(get_ANL() >= 450)
{
_count++;
}
else
{
// Falschwert erfasst //
_flag = true;
}
}
Serial.println("-----------------------------------");
if(_flag == true)
{
// Alten Wert wiederherstellen //
_new_time = _nt_backup;
}
else
{
_old_time = _nt_backup;
// Serial.printf("TIME: %d\n", Mess.NewTime); Überprüfe:
nochimmer();
}
}
// Überprüfen, ob statement noch immer zutrifft //
void Werte::nochimmer()
{
_count = 0;
while(1)
{
if(_count > 15)
{
break;
}
_timestamp = millis() + 6;
while((_timestamp - millis()) > 0){millis();};
if(get_ANL() < 430)
{
_count++;
}
else
{
continue;
}
}
Serial.printf("\n\n\n\nSUCCESS\n\n\n\n");
calc();
}
// Ausrechnen von Delta, Watt und eventueller Output //
void Werte::calc()
{
if(_old_time != 0)
{
_delta = _new_time - _old_time;
// Casting zu int ftf //
_cast = _delta;
_place = _cast / 1000;
_in_stunden = 60 * (60 / _place);
_watt = (1000 * _in_stunden) / 960;
// OUTPUT //
Serial.printf("Momentanverbauch: DELTA: %d WATT: %0.2f\n", _delta, _watt);
}
}

35
src/Werte.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef WERTE_H
#define WERTE_H
#include <Arduino.h>
#include <Variablen.h>
class Werte : protected Variablen
{
public:
Werte(){};
~Werte(){};
// Interaktion mit Timer: //
static void set_ANL(int var);
static int get_ANL();
// Trigger Methode //
static void check();
private:
static int _anl;
static unsigned long int _new_time;
static unsigned long int _nt_backup;
static unsigned long int _old_time;
static unsigned long int _delta;
static double _in_stunden;
static double _watt;
static void nochimmer();
static void calc();
};
#endif

41
src/main.cpp Normal file
View File

@ -0,0 +1,41 @@
#include <Arduino.h>
#include <Werte.h>
#include <Variablen.h>
#define AnalogPIN 14
#define DigitalPIN
void setup()
{
// Initialisiere den Timer //
void IRAM_ATTR onTimer();
hw_timer_t *My_timer = 0;
My_timer = timerBegin(0, 80, true);
timerAttachInterrupt(My_timer, &onTimer, true);
timerAlarmWrite(My_timer, 5000, true);
timerAlarmEnable(My_timer);
// Serielle Kommunikation //
Serial.begin(115200);
}
void loop()
{
// Serial.println(Werte::get_ANL());
// ^ zum Überprüfen der Analog-Werte //
// Wert möglicherweise vom Strich? //
if(Werte::get_ANL() >= 450)
{
// Zeit New & Old richtig einlesen && Aufrufen von NOCHIMMER() //
Werte::check();
}
}
void IRAM_ATTR onTimer()
{
// Liest Wert ein ca jede 5ms //
Werte::set_ANL(analogRead(AnalogPIN));
}

159
src/mainFIRSTATTEMPT.cpp Normal file
View File

@ -0,0 +1,159 @@
/*
#include <Arduino.h>
#define AO 14 // Analog Output //
#define DO 13 // Digital Output //
#define CLK 10 // display as usual //
#define DIO 11
class VALUES
{
public:
int DigVal;
int AnlVal =0 ;
unsigned long int NewT = 0;
unsigned long int delta = 0;
unsigned long int BACKUPdelta = 0;
unsigned long int BACKUPproz;
unsigned long int OldT = 0;
unsigned long int BACKUPtwice = 0;
};
VALUES Wert;
void setup()
{
void IRAM_ATTR onTimer();
hw_timer_t *My_timer = NULL;
pinMode(AO, INPUT);
//pinMode(DO, INPUT);
Serial.begin(115200);
My_timer = timerBegin(0, 80, true);
timerAttachInterrupt(My_timer, &onTimer, true);
timerAlarmWrite(My_timer, 50000, true);
timerAlarmEnable(My_timer);
}
int CHECK(int VAR);
void CALC(int TurnTime);
void COMPARE(int First, int Second);
void FILTERING();
int FLAG = 0;
int FLECK = 0;
int COUNTER = 0;
int CHECKING = 0;
int VAR = 0;
int LATE = 0;
double Watt;
double Var;
double INT;
int ARR[3];
bool SCREAM = 0;
void loop()
{
Wert.AnlVal = VAR;
//Serial.println(Wert.AnlVal);
//Serial.println(Wert.delta);
if (Wert.AnlVal > 450 && FLAG == 0)
{
Serial.println("JUMP");
Wert.NewT = millis();
if(SCREAM == 0)
{
Wert.BACKUPdelta = Wert.delta;
}
Wert.delta = Wert.NewT - Wert.OldT;
Wert.BACKUPproz = Wert.BACKUPdelta - (Wert.BACKUPdelta * 0.25); // ^ ??
if(Wert.delta <= Wert.BACKUPproz && FLECK != 0)
{
Serial.printf("Falschwert?? DELTA: %d\n", Wert.delta);
}
else
{
SCREAM = 1;
CHECKING = 0;
Wert.OldT = Wert.NewT;
Wert.BACKUPdelta = Wert.delta;
Serial.printf("NEWT: %d Delta: %d\n", Wert.NewT, Wert.delta);
CALC(Wert.delta);
Serial.printf("Momentan Verbrauch: %0.2f Watt\n", Watt);
}
FLAG = 1;
FLECK = 1;
}
else if (Wert.AnlVal > 450)
{
while(1)
{
Wert.AnlVal = VAR;
if(CHECK(VAR) == 1)
{
FLAG = 0;
break;
}
}
}
else if(Wert.AnlVal < 450)
{
FLAG = 0;
}
// NEW ASSIGNED TO OLD BTW INCASE THIS WONT WORK //
}//-------------------------------------------------------------------------------------------------------------------
int CHECK(int VAR)
{
if(COUNTER == 10)
{
COUNTER = 0;
return 1;
}
if(VAR < 450)
{
COUNTER++;
return 0;
}
else
{
COUNTER = 0;
return 0;
}
}
void IRAM_ATTR onTimer()
{
VAR = analogRead(AO);
}
void CALC(int TurnTime)
{
INT = TurnTime;
Var = INT / 1000;
double InStd = 60 * (60 / Var);
Watt = (1000 * InStd) / 960;
}
*/

11
test/README Normal file
View File

@ -0,0 +1,11 @@
This directory is intended for PlatformIO Test Runner 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/en/latest/advanced/unit-testing/index.html