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