-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSequencer.h
104 lines (93 loc) · 2.4 KB
/
Sequencer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Sequencer.h
*
* Created on: 22.02.2017
* Author: cybaer
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef SEQUENCER_H_
#define SEQUENCER_H_
#include "HardwareConfig.h"
#include "Pulse.h"
#include "clock.h"
#include "divider.h"
#include "stepper.h"
using namespace avrlib;
class Sequencer
{
public:
Sequencer(void);
void onClock(void) { m_Tick++; multivider.onTick(); } // called only in ISR context
void onStep(void);
void poll(void);
void update(void);
void onStartStop(void) { m_Run = !m_Run; };
void onReset(void);
void setPulse_A(void) { m_Pulse_A.set(m_Tick); };
void setPulse_B(void) { m_Pulse_B.set(m_Tick); };
private:
void createNextStep(void);
void writeOutStep(void);
void nextStep_A(uint8_t in);
void nextStep_B(uint8_t in);
uint8_t calcDivisor(uint8_t value);
uint8_t calcFactor(uint8_t value);
Multivider multivider;
//Divider divider;
Clock<ClockOut> clock;
uint8_t m_Tick;
bool m_Run;
bool m_ClockValue;
Stepper m_Stepper;
Pulse<Output_A> m_Pulse_A;
Pulse<Output_B> m_Pulse_B;
typedef void (Sequencer::*P2MF)(void);
class StepAction
{
public:
StepAction(Sequencer& parent, P2MF function)
: m_Parent(parent)
, setPulse(function)
, m_Mode(1)
{}
void setMode(uint8_t mode) { m_Mode = mode; }
void action(uint8_t in)
{
if(in)
{
switch(m_Mode)
{
case 0:
m_Parent.onReset();
break;
case 1:
(m_Parent.*setPulse)(); // call of P2MF
break;
case 2:
m_Parent.onStartStop();
break;
}
}
}
private:
Sequencer& m_Parent;
P2MF setPulse;
uint8_t m_Mode;
};
friend class StepAction;
StepAction m_Action_A;
StepAction m_Action_B;
};
extern Sequencer sequencer;
#endif /* SEQUENCER_H_ */