This commit is contained in:
2020-11-02 00:27:02 +01:00
parent 2a2ba7693e
commit 35a57e2e36
12 changed files with 141 additions and 32 deletions
+28 -7
View File
@@ -10,48 +10,69 @@
#include "peripheral.h"
#include "io/AudioSwitcher.hpp"
#include "io/LED.hpp"
#include "io/Comperator.hpp"
#include "io/PTT.hpp"
#include "io/Timer.hpp"
template <int delay_plus>
class ProgrammT {
class Programm {
private:
void ResetTimer() {
led.SetColor(Led::CYAN);
//timer.Reset();
if(!this->timer_running) {
audio.SetFunk();
//timer.Start();
}
this->timer_running = true;
}
void TimerEnd() {
audio.SetRadio();
//timer.Stop();
this->timer_running = false;
}
protected:
public:
ProgrammT() : timer_running(false) {
Programm() : timer_running(false) {
}
void Setup() {
led.SetColor(Led::RED);
_delay_ms(500);
}
void Loop() {
if(this->timer_running) {
led.SetColor(Led::YELLOW);
if(comp.GetInterruptActivated()) {
this->ResetTimer();
}
if(ptt.GetPttActivated()) {
this->ResetTimer();
}
} else {
led.SetColor(Led::GREEN);
}
}
void Vect_Ptt() {
this->ResetTimer();
}
void Vect_Comp() {
this->ResetTimer();
}
void Vect_Timer() {
this->TimerEnd();
}
private:
AudioSwitcher audio;
Led led;
Comperator comp;
Ptt ptt;
//Timer timer;
protected:
bool timer_running;
public:
};
typedef ProgrammT<settings_prog_delay_plus> Programm;
};
+12 -7
View File
@@ -9,16 +9,21 @@
#ifndef COMPERATOR_HPP_
#define COMPERATOR_HPP_
#include <avr/io.h>
class Comperator {
// Methods
private:
protected:
public:
// Variables
private:
protected:
public:
Comperator() {
ADCSRB = 0;
ACSR = (1<<ACI) | (1<<ACIE) | (1<<ACIS1) | (1<<ACIS0);
}
bool GetInterruptActivated() {
if(ACSR & (1<<ACO)) {
return true;
}
return false;
}
};
#endif /* COMPERATOR_HPP_ */
-2
View File
@@ -57,8 +57,6 @@ class LedT {
led_pin_r led_r;
led_pin_g led_g;
led_pin_b led_b;
protected:
public:
};
typedef LedT<blubblib::pin<blubblib::portc, PINC1>, blubblib::pin<blubblib::portc, PINC2>, blubblib::pin<blubblib::portc, PINC0> > Led;
+16 -2
View File
@@ -9,18 +9,32 @@
#ifndef PTT_HPP_
#define PTT_HPP_
#include <avr/io.h>
#include "ports/pin.hpp"
#include "ports/portd.hpp"
template<typename ptt_pin>
class PttT {
// Methods
private:
protected:
public:
PttT() {
ptt.MakeInput();
EICRA = (1<<ISC01) | (1<<ISC00);
EIMSK = (1<<INT0);
}
bool GetPttActivated() {
return ptt.Value();
}
// Variables
private:
protected:
public:
ptt_pin ptt;
};
typedef PttT<blubblib::pin<blubblib::portd, PIND2> > Ptt;
#endif /* PTT_HPP_ */
+29 -2
View File
@@ -9,11 +9,38 @@
#ifndef TIMER_H_
#define TIMER_H_
class Timer {
#include <avr/io.h>
template <long int timer_count_till, int timer_prescaler>
class TimerT {
// Methods
private:
protected:
public:
TimerT() {
TCCR1A = 0;
TCCR1B = 0;
TCCR1C = 0;
TCNT1 = 0;
OCR1AH = (timer_count_till<<8);
OCR1AL = timer_count_till;
TIMSK1 = (1<<ICIE1) | (1<<OCIE1A);
}
void Stop() {
TCCR1B = 0;
}
void Start() {
TCCR1B = timer_prescaler;
}
void Reset() {
TCNT1 = 0;
}
// Variables
private:
@@ -21,6 +48,6 @@ class Timer {
public:
};
typedef TimerT<settings_timer_count_till, settings_timer_prescaler> Timer;
#endif /* TIMER_H_ */
+12 -2
View File
@@ -36,10 +36,16 @@ namespace blubblib {
PortT::Port(PortT::Port() ^ (1<<Pin));
}
static bool Get() {
return (PortT::Port() & (1<<Pin)) != 0;
}
/**
* \brief
* Return Value of the Pin (High or Low)
* \return bool
*/
static bool Value() {
return (PortT::Pin() & (1<<Pin)) != 0;
}
@@ -60,6 +66,11 @@ namespace blubblib {
Output(true);
}
/**
* \brief
* Set as Input and no Pullup
* \return void
*/
static void MakeInput() {
Output(false);
Clear();
@@ -67,8 +78,7 @@ namespace blubblib {
/**
* \brief
* Set Output and Low
*
* Set as Output and Low
* \return void
*/
static void MakeLow() {
+8
View File
@@ -20,4 +20,12 @@ int main(void) {
ISR(INT0_vect) {
p.Vect_Ptt();
}
ISR(ANALOG_COMP_vect) {
p.Vect_Comp();
}
ISR(TIMER1_COMPA_vect) {
p.Vect_Timer();
}
+3 -2
View File
@@ -10,8 +10,9 @@
#define PERIPHERAL_H_
namespace {
//Programm settings
extern int const settings_prog_delay_plus = 5000;
//Timer settings = 5s
extern long const settings_timer_count_till = 39062;
extern int const settings_timer_prescaler = 5;
}