blob: ae20b2bdec239feda50f95927eab48eb64cdb5c9 (
plain)
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
|
/*
* Spindle.cpp
*
* Created on: Mar 21, 2018
* Author: Christian
*/
#include "Spindle.h"
// Allocate the pins returning true if successful
bool Spindle::AllocatePins(GCodeBuffer& gb, const StringRef& reply)
{
IoPort * const ports[] = { &spindleForwardPort, &spindleReversePort };
const PinAccess access[] = { PinAccess::pwm, PinAccess::pwm };
return IoPort::AssignPorts(gb, reply, PinUsedBy::spindle, 2, ports, access);
}
void Spindle::SetFrequency(PwmFrequency freq)
{
spindleForwardPort.SetFrequency(freq);
spindleReversePort.SetFrequency(freq);
}
void Spindle::SetRpm(float rpm)
{
const float pwm = abs(rpm / maxRpm);
if (rpm >= 0.0)
{
spindleReversePort.WriteAnalog(0.0);
spindleForwardPort.WriteAnalog(pwm);
}
else
{
spindleReversePort.WriteAnalog(pwm);
spindleForwardPort.WriteAnalog(0.0);
}
currentRpm = configuredRpm = rpm;
}
void Spindle::TurnOff()
{
spindleReversePort.WriteAnalog(0.0);
spindleForwardPort.WriteAnalog(0.0);
currentRpm = 0.0;
}
// End
|