SimpleFOClibrary
2.4.0
Loading...
Searching...
No Matches
StepDirListener.cpp
Go to the documentation of this file.
1
#include "
StepDirListener.h
"
2
3
StepDirListener::StepDirListener
(
int
_pinStep,
int
_pinDir,
float
_counter_to_value){
4
pin_step
= _pinStep;
5
pin_dir
= _pinDir;
6
counter_to_value = _counter_to_value;
7
}
8
9
void
StepDirListener::init
(){
10
pinMode(
pin_dir
,
INPUT
);
11
pinMode(
pin_step
, INPUT_PULLUP);
12
count
= 0;
13
}
14
15
void
StepDirListener::enableInterrupt
(
void
(*doA)()){
16
attachInterrupt(digitalPinToInterrupt(
pin_step
), doA,
polarity
);
17
}
18
19
void
StepDirListener::attach
(
float
* variable){
20
attached_variable = variable;
21
}
22
23
void
StepDirListener::handle
(){
24
// read step status
25
//bool step = digitalRead(pin_step);
26
// update counter only on rising edge
27
//if(step && step != step_active){
28
if
(digitalRead(
pin_dir
))
29
count
++;
30
else
31
count
--;
32
//}
33
//step_active = step;
34
// if attached variable update it
35
if
(attached_variable) *attached_variable =
getValue
();
36
}
37
// calculate the position from counter
38
float
StepDirListener::getValue
(){
39
return
(
float
)
count
* counter_to_value;
40
}
StepDirListener.h
StepDirListener::getValue
float getValue()
Definition
StepDirListener.cpp:38
StepDirListener::attach
void attach(float *variable)
Definition
StepDirListener.cpp:19
StepDirListener::handle
void handle()
Definition
StepDirListener.cpp:23
StepDirListener::pin_step
int pin_step
step pin
Definition
StepDirListener.h:48
StepDirListener::polarity
decltype(RISING) polarity
polarity of the step pin
Definition
StepDirListener.h:51
StepDirListener::StepDirListener
StepDirListener(int pinStep, int pinDir, float counter_to_value=1)
Definition
StepDirListener.cpp:3
StepDirListener::init
void init()
Definition
StepDirListener.cpp:9
StepDirListener::enableInterrupt
void enableInterrupt(void(*handleStep)())
Definition
StepDirListener.cpp:15
StepDirListener::pin_dir
int pin_dir
direction pin
Definition
StepDirListener.h:49
StepDirListener::count
long count
current counter value - should be set to 0 for homing
Definition
StepDirListener.h:50
INPUT
INPUT
Definition
current_sense/hardware_specific/generic_mcu.cpp:14
src
communication
StepDirListener.cpp
Generated by
1.9.8