Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MarlinKimbra
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
MarlinKimbra
Commits
a963b96f
Commit
a963b96f
authored
Feb 10, 2016
by
MagoKimbra
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'refs/remotes/origin/master' into dev
parents
a5ec7e53
9d4d7643
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
25 deletions
+31
-25
servo.cpp
MK/module/servo/servo.cpp
+13
-9
servo.h
MK/module/servo/servo.h
+18
-16
No files found.
MK/module/servo/servo.cpp
View file @
a963b96f
...
@@ -299,13 +299,10 @@ void Servo::writeMicroseconds(int value)
...
@@ -299,13 +299,10 @@ void Servo::writeMicroseconds(int value)
}
}
}
}
int
Servo
::
read
()
// return the value as degrees
// return the value as degrees
{
int
Servo
::
read
()
{
return
map
(
this
->
readMicroseconds
()
+
1
,
SERVO_MIN
(),
SERVO_MAX
(),
0
,
180
);
}
return
map
(
readMicroseconds
()
+
1
,
SERVO_MIN
(),
SERVO_MAX
(),
0
,
180
);
}
int
Servo
::
readMicroseconds
()
int
Servo
::
readMicroseconds
()
{
{
unsigned
int
pulsewidth
;
unsigned
int
pulsewidth
;
if
(
this
->
servoIndex
!=
INVALID_SERVO
)
if
(
this
->
servoIndex
!=
INVALID_SERVO
)
pulsewidth
=
ticksToUs
(
servos
[
this
->
servoIndex
].
ticks
)
+
TRIM_DURATION
;
pulsewidth
=
ticksToUs
(
servos
[
this
->
servoIndex
].
ticks
)
+
TRIM_DURATION
;
...
@@ -315,9 +312,16 @@ int Servo::readMicroseconds()
...
@@ -315,9 +312,16 @@ int Servo::readMicroseconds()
return
pulsewidth
;
return
pulsewidth
;
}
}
bool
Servo
::
attached
()
bool
Servo
::
attached
()
{
return
servos
[
this
->
servoIndex
].
Pin
.
isActive
;
}
{
return
servos
[
this
->
servoIndex
].
Pin
.
isActive
;
void
Servo
::
move
(
int
value
)
{
if
(
this
->
attach
(
0
)
>=
0
)
{
this
->
write
(
value
);
#if ENABLED(DEACTIVATE_SERVOS_AFTER_MOVE)
delay
(
SERVO_DEACTIVATION_DELAY
);
this
->
detach
();
#endif
}
}
}
#endif
#endif
MK/module/servo/servo.h
View file @
a963b96f
...
@@ -83,19 +83,21 @@ typedef struct {
...
@@ -83,19 +83,21 @@ typedef struct {
volatile
unsigned
int
ticks
;
volatile
unsigned
int
ticks
;
}
servo_t
;
}
servo_t
;
class
Servo
class
Servo
{
{
public
:
public
:
Servo
();
Servo
();
uint8_t
attach
(
int
pin
);
// attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t
attach
(
int
pin
);
// attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure
uint8_t
attach
(
int
pin
,
int
min
,
int
max
);
// as above but also sets min and max values for writes.
uint8_t
attach
(
int
pin
,
int
min
,
int
max
);
// as above but also sets min and max values for writes.
void
detach
();
void
detach
();
void
write
(
int
value
);
// if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
void
write
(
int
value
);
// if value is < 200 its treated as an angle, otherwise as pulse width in microseconds
void
writeMicroseconds
(
int
value
);
// Write pulse width in microseconds
void
writeMicroseconds
(
int
value
);
// Write pulse width in microseconds
void
move
(
int
value
);
// attach the servo, then move to value
// if value is < 200 it is treated as an angle, otherwise as pulse width in microseconds
// if DEACTIVATE_SERVOS_AFTER_MOVE wait SERVO_DEACTIVATION_DELAY, then detach
int
read
();
// returns current pulse width as an angle between 0 and 180 degrees
int
read
();
// returns current pulse width as an angle between 0 and 180 degrees
int
readMicroseconds
();
// returns current pulse width in microseconds for this servo (was read_us() in first release)
int
readMicroseconds
();
// returns current pulse width in microseconds for this servo (was read_us() in first release)
bool
attached
();
// return true if this servo is attached, otherwise false
bool
attached
();
// return true if this servo is attached, otherwise false
private
:
private
:
uint8_t
servoIndex
;
// index into the channel data for this servo
uint8_t
servoIndex
;
// index into the channel data for this servo
int8_t
min
;
// minimum is this value times 4 added to MIN_PULSE_WIDTH
int8_t
min
;
// minimum is this value times 4 added to MIN_PULSE_WIDTH
int8_t
max
;
// maximum is this value times 4 added to MAX_PULSE_WIDTH
int8_t
max
;
// maximum is this value times 4 added to MAX_PULSE_WIDTH
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment