2012-04-21 00:04:34 +00:00
|
|
|
/*
|
|
|
|
epple2
|
2015-07-29 01:14:58 +00:00
|
|
|
Copyright (C) 2008 by Christopher A. Mosher <cmosher01@gmail.com>
|
2012-04-21 00:04:34 +00:00
|
|
|
|
|
|
|
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 STEPPERMOTOR_H
|
|
|
|
#define STEPPERMOTOR_H
|
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
class StepperMotor {
|
2012-04-21 00:04:34 +00:00
|
|
|
private:
|
2018-12-23 21:44:30 +00:00
|
|
|
enum { QTRACKS = 160 };
|
|
|
|
// quarter track: 0=t0, 1=t0.25, 2=t0.5, 3=t0.75, 4=t1, ... 140=t35.00 ... 159=t39.75
|
|
|
|
// (see TMAP in WOZ2 file format spec)
|
2018-12-19 03:59:20 +00:00
|
|
|
std::int16_t quarterTrack;
|
2018-12-23 21:44:30 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
signed char pos; // 0 - 7
|
|
|
|
unsigned char mags;
|
2012-04-21 00:04:34 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
static signed char mapMagPos[];
|
2012-04-21 00:04:34 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
static signed char calcDeltaPos(const unsigned char cur, const signed char next) {
|
|
|
|
signed char d = next-cur; // -7 to +7
|
2012-04-21 00:04:34 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
if (d == 4 || d == -4) {
|
|
|
|
d = 0; // <--- TODO pick random direction?
|
|
|
|
} else if (4 < d) {
|
|
|
|
d -= 8;
|
|
|
|
} else if (d < -4) {
|
|
|
|
d += 8;
|
|
|
|
}
|
2012-04-21 00:04:34 +00:00
|
|
|
|
2018-12-18 13:46:46 +00:00
|
|
|
return d;
|
|
|
|
}
|
2012-04-21 00:04:34 +00:00
|
|
|
|
|
|
|
public:
|
2018-12-18 13:46:46 +00:00
|
|
|
StepperMotor();
|
|
|
|
~StepperMotor();
|
|
|
|
|
|
|
|
void setMagnet(const unsigned char magnet, const bool on);
|
|
|
|
unsigned char getTrack() {
|
|
|
|
return ((unsigned short)(this->quarterTrack)) >> 2;
|
|
|
|
}
|
|
|
|
std::uint8_t getQuarterTrack() {
|
|
|
|
return this->quarterTrack;
|
|
|
|
}
|
2012-04-21 00:04:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|