half-way commit to explain some of what is going on
[clinton/Smoothieware.git] / src / libs / StepperMotor.h
CommitLineData
feb204be
AW
1/*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie 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.
4 Smoothie 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.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6*/
7
8#ifndef STEPPERMOTOR_H
9#define STEPPERMOTOR_H
10
11#include "libs/Kernel.h"
12#include "libs/Hook.h"
13
14class StepTicker;
15
16class StepperMotor {
17 public:
18 StepperMotor();
19 StepperMotor(Pin* step, Pin* dir, Pin* en);
20 bool tick();
21 void move( bool direction, unsigned int steps );
22 void set_speed( double speed );
23
24 template<typename T> void attach( T *optr, uint32_t ( T::*fptr )( uint32_t ) ){
25 Hook* hook = new Hook();
26 hook->attach(optr, fptr);
27 this->end_hook = hook;
28 }
29
30 Hook* end_hook;
31
32 StepTicker* step_ticker;
33 Pin* step_pin;
34 Pin* dir_pin;
35 Pin* en_pin;
36
37 double steps_per_second;
38
39 bool moving;
40 bool paused;
41
42 bool direction_bit;
43 bool step_bit;
44
45 uint32_t steps_to_move;
46 uint32_t stepped;
47 uint64_t fx_counter;
48 uint64_t fx_ticks_per_step;
49};
50
51
52
53#endif
54