mirror of
https://gitlab.com/fabinfra/fabhardware/absaugungsklappensteuerung.git
synced 2025-03-12 14:51:44 +01:00
Umbau auf Vererbung. Funktion wie vorher
This commit is contained in:
parent
3009625469
commit
01b9353eb8
@ -12,15 +12,12 @@
|
||||
* @param pinSense
|
||||
* @param id
|
||||
*/
|
||||
KlappenSteuerung::KlappenSteuerung(int pin_A, int pin_B, int pin_Sense, int i_d)
|
||||
KlappenSteuerung::KlappenSteuerung(int pinA, int pinB, int pinSense, int id)
|
||||
{
|
||||
initAttributes();
|
||||
pinA = pin_A;
|
||||
pinB = pin_B;
|
||||
pinSense = pin_Sense;
|
||||
id = i_d;
|
||||
vorherKlappe = letzteKlappe;
|
||||
letzteKlappe = this;
|
||||
setPins(pinA , pinB);
|
||||
SetId(id);
|
||||
this->pinSense = pinSense;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -40,50 +37,13 @@ KlappenSteuerung::~KlappenSteuerung()
|
||||
// Other methods
|
||||
//
|
||||
|
||||
KlappenSteuerung *KlappenSteuerung::letzteKlappe;
|
||||
|
||||
/**
|
||||
*/
|
||||
void KlappenSteuerung::setup()
|
||||
{
|
||||
if(KlappenSteuerung::letzteKlappe){
|
||||
KlappenSteuerung::letzteKlappe->localSetup();
|
||||
}
|
||||
Motor::setup();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
void KlappenSteuerung::loop()
|
||||
{
|
||||
if(KlappenSteuerung::letzteKlappe){
|
||||
KlappenSteuerung::letzteKlappe->localLoop();
|
||||
}
|
||||
Motor::loop();
|
||||
}
|
||||
|
||||
|
||||
void KlappenSteuerung::localSetup()
|
||||
{
|
||||
if(vorherKlappe){
|
||||
vorherKlappe->localSetup();
|
||||
}else{
|
||||
|
||||
}
|
||||
motor.setPins(pinA , pinB);
|
||||
|
||||
}
|
||||
|
||||
void KlappenSteuerung::localLoop()
|
||||
{
|
||||
if(vorherKlappe){
|
||||
vorherKlappe->localLoop();
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -93,12 +53,5 @@ void KlappenSteuerung::setOpen(bool open)
|
||||
{
|
||||
}
|
||||
|
||||
void KlappenSteuerung::initAttributes()
|
||||
{
|
||||
pinA = -1;
|
||||
pinB = -1;
|
||||
pinSense = -1;
|
||||
id = -1;
|
||||
status = NICHTS;
|
||||
}
|
||||
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
class KlappenSteuerung
|
||||
class KlappenSteuerung : public Motor
|
||||
{
|
||||
public:
|
||||
// Constructors/Destructors
|
||||
@ -46,12 +46,12 @@ public:
|
||||
|
||||
/**
|
||||
*/
|
||||
static void setup();
|
||||
//static void setup();
|
||||
|
||||
|
||||
/**
|
||||
*/
|
||||
static void loop();
|
||||
//static void loop();
|
||||
|
||||
|
||||
/**
|
||||
@ -61,27 +61,21 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
int pinA;
|
||||
int pinB;
|
||||
int pinSense;
|
||||
int id;
|
||||
statusKlappen status;
|
||||
|
||||
void localSetup();
|
||||
void localLoop();
|
||||
//void memberSetup();
|
||||
//void memberLoop();
|
||||
|
||||
|
||||
Motor motor;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static KlappenSteuerung *letzteKlappe;
|
||||
KlappenSteuerung *vorherKlappe = 0;
|
||||
|
||||
|
||||
|
||||
void initAttributes();
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // KLAPPENSTEUERUNG_H
|
||||
|
24
Arduino/motor/src/arduinoAnpassung.cpp
Normal file
24
Arduino/motor/src/arduinoAnpassung.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#include"arduinoAnpassung.h"
|
||||
|
||||
ArduinoAnpassung::~ArduinoAnpassung(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ArduinoAnpassung::setup(){
|
||||
MyList *zeiger;
|
||||
zeiger = ArduinoAnpassung::getErstesElement();
|
||||
while(zeiger){
|
||||
((ArduinoAnpassung*)zeiger)->memberSetup();
|
||||
zeiger = zeiger->getNachfolgerElement();
|
||||
}
|
||||
}
|
||||
|
||||
void ArduinoAnpassung::loop(){
|
||||
MyList *zeiger;
|
||||
zeiger = ArduinoAnpassung::getErstesElement();
|
||||
while(zeiger){
|
||||
((ArduinoAnpassung*)zeiger)->memberLoop();
|
||||
zeiger = zeiger->getNachfolgerElement();
|
||||
}
|
||||
}
|
28
Arduino/motor/src/arduinoAnpassung.h
Normal file
28
Arduino/motor/src/arduinoAnpassung.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef ARDUINO_APASSUNG_H
|
||||
#define ARDUINO_APASSUNG_H
|
||||
|
||||
#include "myList.h"
|
||||
|
||||
class ArduinoAnpassung : public MyList{
|
||||
|
||||
public:
|
||||
~ArduinoAnpassung();
|
||||
|
||||
|
||||
static void setup();
|
||||
static void loop();
|
||||
|
||||
|
||||
virtual void memberLoop();
|
||||
virtual void memberSetup();
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
|
||||
};
|
||||
#endif
|
@ -8,15 +8,16 @@ void Ablauf();
|
||||
void AblaufSekunde();
|
||||
|
||||
KlappenSteuerung klappe1 (M1A , M1B , M1SENSE , 5 );
|
||||
KlappenSteuerung klappe2 (M2A , M2B , M2SENSE , 2 );
|
||||
KlappenSteuerung klappe3 (M3A , M3B , M3SENSE , 23 );
|
||||
KlappenSteuerung klappe4 (M4A , M4B , M4SENSE , 1 );
|
||||
//KlappenSteuerung klappe2 (M2A , M2B , M2SENSE , 2 );
|
||||
//KlappenSteuerung klappe3 (M3A , M3B , M3SENSE , 23 );
|
||||
//KlappenSteuerung klappe4 (M4A , M4B , M4SENSE , 1 );
|
||||
|
||||
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
KlappenSteuerung::setup();
|
||||
pinMode(LED_BUILTIN , OUTPUT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -48,7 +49,7 @@ void Ablauf(){
|
||||
void AblaufSekunde(){
|
||||
static unsigned int sekunden;
|
||||
sekunden ++;
|
||||
//digitalWrite(LED_DEBUG , !(sekunden & 3));
|
||||
//digitalWrite(LED_BUILTIN , !(sekunden & 3));
|
||||
switch(sekunden){
|
||||
case 1:
|
||||
klappe1.setOpen(true);
|
||||
|
@ -1,52 +1,28 @@
|
||||
#include "motor.h"
|
||||
|
||||
Motor *Motor::letztesElement;
|
||||
|
||||
Motor::Motor(){
|
||||
|
||||
vorherElement = Motor::letztesElement;
|
||||
Motor::letztesElement = this;
|
||||
this->pinA = pinA;
|
||||
this->pinB = pinB;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Motor::~Motor(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Motor::setPins(uint8_t pinA , uint8_t pinB){
|
||||
this->pinA = pinA;
|
||||
this->pinB = pinB;
|
||||
}
|
||||
|
||||
|
||||
void Motor::setup(){
|
||||
if(Motor::letztesElement){
|
||||
Motor::letztesElement->localSetup();
|
||||
}
|
||||
ArduinoAnpassung::setup();
|
||||
Timer1.initialize(100); // 10kHz
|
||||
Timer1.attachInterrupt(Motor::interruptEinsprung);
|
||||
|
||||
//digitalWrite(LED_BUILTIN , 0 );
|
||||
}
|
||||
|
||||
void Motor::loop(){
|
||||
if(Motor::letztesElement){
|
||||
Motor::letztesElement->localLoop();
|
||||
}
|
||||
}
|
||||
|
||||
void Motor::localSetup(){
|
||||
mySetup();
|
||||
if(vorherElement){
|
||||
vorherElement->localSetup();
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Motor::mySetup(){
|
||||
void Motor::memberSetup(){
|
||||
pinMode(pinA , OUTPUT);
|
||||
digitalWrite( pinA , 0);
|
||||
|
||||
@ -55,16 +31,8 @@ void Motor::mySetup(){
|
||||
}
|
||||
|
||||
|
||||
void Motor::localLoop(){
|
||||
myLoop();
|
||||
if(vorherElement){
|
||||
vorherElement->localLoop();
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void Motor::myLoop(){
|
||||
void Motor::memberLoop(){
|
||||
if(richtung){
|
||||
if(test == 32767)
|
||||
richtung = !richtung;
|
||||
@ -78,6 +46,7 @@ void Motor::myLoop(){
|
||||
}
|
||||
setSollSpeed( test / 64);
|
||||
//setSollSpeed(100);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -95,17 +64,22 @@ void Motor::setSollSpeed(int16_t speed){
|
||||
|
||||
|
||||
void Motor::interruptEinsprung(){
|
||||
if(letztesElement)
|
||||
letztesElement->localInterruptEinsprung();
|
||||
}
|
||||
void Motor::localInterruptEinsprung(){
|
||||
interruptBerechnungen();
|
||||
if(vorherElement){
|
||||
vorherElement->localInterruptEinsprung();
|
||||
}else{
|
||||
timer ++;
|
||||
//digitalWrite(LED_DEBUG , (timer & 0x100) != 0 );
|
||||
MyList *zeiger;
|
||||
zeiger = ArduinoAnpassung::getErstesElement();
|
||||
while(zeiger){
|
||||
((Motor*)zeiger)->memberInterruptEinsprung();
|
||||
zeiger = zeiger->getNachfolgerElement();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Motor::memberInterruptEinsprung(){
|
||||
interruptBerechnungen();
|
||||
timer ++;
|
||||
//digitalWrite(LED_DEBUG , (timer & 0x100) != 0 );
|
||||
//digitalWrite(LED_BUILTIN , 1 );
|
||||
}
|
||||
|
||||
void Motor::interruptBerechnungen(){
|
||||
@ -115,15 +89,18 @@ void Motor::interruptBerechnungen(){
|
||||
summeSpeed -= 256;
|
||||
digitalWrite(pinA , 0);
|
||||
digitalWrite(pinB , 1);
|
||||
digitalWrite(LED_BUILTIN , 0 );
|
||||
|
||||
}else if (summeSpeed <= -256){
|
||||
summeSpeed += 256;
|
||||
digitalWrite(pinA , 1);
|
||||
digitalWrite(pinB , 0);
|
||||
digitalWrite(LED_BUILTIN , 1 );
|
||||
|
||||
}else{
|
||||
digitalWrite(pinA , 0);
|
||||
digitalWrite(pinB , 0);
|
||||
digitalWrite(LED_BUILTIN , 0 );
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,17 +3,16 @@
|
||||
|
||||
#include <TimerOne.h>
|
||||
#include "pins.h"
|
||||
#include "arduinoAnpassung.h"
|
||||
|
||||
class Motor{
|
||||
class Motor :public ArduinoAnpassung{
|
||||
|
||||
public:
|
||||
Motor();
|
||||
Motor(uint8_t pinA , uint8_t pinB);
|
||||
|
||||
virtual ~Motor();
|
||||
|
||||
|
||||
//virtual ~Motor();
|
||||
|
||||
static void setup();
|
||||
static void loop();
|
||||
|
||||
void setPins(uint8_t pinA , uint8_t pinB);
|
||||
|
||||
@ -24,14 +23,14 @@ protected:
|
||||
static Motor *letztesElement;
|
||||
Motor *vorherElement;
|
||||
|
||||
void localSetup();
|
||||
void localLoop();
|
||||
|
||||
void mySetup();
|
||||
void myLoop();
|
||||
|
||||
void memberSetup();
|
||||
void memberLoop();
|
||||
|
||||
static void interruptEinsprung();
|
||||
void localInterruptEinsprung();
|
||||
void memberInterruptEinsprung();
|
||||
//void InterruptEinsprung();
|
||||
|
||||
void interruptBerechnungen();
|
||||
|
||||
|
27
Arduino/motor/src/myList.cpp
Normal file
27
Arduino/motor/src/myList.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
#include "myList.h"
|
||||
|
||||
MyList::MyList(){
|
||||
nachfolger = erstesElement;
|
||||
erstesElement = this;
|
||||
}
|
||||
|
||||
|
||||
MyList::~MyList(){
|
||||
|
||||
}
|
||||
|
||||
MyList *MyList::erstesElement = 0;
|
||||
|
||||
MyList *MyList::getErstesElement(){
|
||||
return MyList::erstesElement;
|
||||
}
|
||||
|
||||
MyList *MyList::getNachfolgerElement(){
|
||||
return nachfolger;
|
||||
}
|
||||
|
||||
void MyList::SetId(int id){
|
||||
this->id = id;
|
||||
}
|
||||
|
25
Arduino/motor/src/myList.h
Normal file
25
Arduino/motor/src/myList.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef MY_LIST_H
|
||||
#define MY_LIST_H
|
||||
|
||||
class MyList{
|
||||
public:
|
||||
MyList();
|
||||
virtual ~MyList();
|
||||
static MyList* getErstesElement();
|
||||
static MyList* getIdElement();
|
||||
MyList* getNachfolgerElement();
|
||||
void SetId(int id);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
static MyList *erstesElement;
|
||||
MyList *nachfolger;
|
||||
int id;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user