-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservo.cpp
More file actions
112 lines (96 loc) · 2.44 KB
/
servo.cpp
File metadata and controls
112 lines (96 loc) · 2.44 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <Arduino.h>
#include "SoftataDevice_actuator.h"
SoftataDevice_Servo::SoftataDevice_Servo()
{
Setup();
}
SoftataDevice_Servo::SoftataDevice_Servo(int pin)
{
SetupServo(pin,MIN_PW,MAX_PW,PERIOD);
}
bool SoftataDevice_Servo::Setup()
{
return SetupServo(DEFAULT_SERVO_PIN,MIN_PW,MAX_PW,PERIOD);
}
bool SoftataDevice_Servo::Setup(byte * settings, byte numSettings)
{
if(numSettings>0)
{
int pin = settings[0];
if(numSettings>1)
{
int min = settings[1];
if(numSettings>2)
{
int max = settings[2];
if(numSettings>3)
{
int period = settings[3];
return SetupServo(pin,min,max,period);
}
else
return SetupServo(pin,min,max,PERIOD);
}
else
return SetupServo(pin,min,MAX_PW,PERIOD);
}
else
return SetupServo(pin,MIN_PW,MAX_PW,PERIOD);
}
else
return SetupServo(DEFAULT_SERVO_PIN,MIN_PW,MAX_PW,PERIOD);
}
int SoftataDevice_Servo::GetNumBits()
{
Serial.print("SoftataDevice_Servo::GetNumBits():");
Serial.println(num_bits);
return num_bits;
}
int SoftataDevice_Servo::GetInstanceValueRange()
{
return SERVO_MAX;
}
byte SoftataDevice_Servo::GetActuatorCapabilities()
{
return (byte)(a_writebyte);
}
/*
String SoftataDevice_Servo::GetPins()
{
String msg = "Servo Pins:";
msg.concat(SERVO_PINOUT);
return msg;
}*/
bool SoftataDevice_Servo::SetupServo(int pin, int min, int max, int period)
{
myservo.attach(pin,min,max);
return true;
}
// Index for if there are an array of actuators here.
Tristate SoftataDevice_Servo::Write(double value, int index)
{
return notImplemented;
}
Tristate SoftataDevice_Servo::Write(int angle, int index, int numBytes /*=1*/)
{
if((angle<SERVO_MIN)||(angle>SERVO_MAX))
return invalidParams;
myservo.write(angle);
return (Tristate)true;
}
Tristate SoftataDevice_Servo::SetBitState(bool state,int bitIndex)
{
return notImplemented;
}
Tristate SoftataDevice_Servo::SetBit(int bitNo )
{
return notImplemented;
}
Tristate SoftataDevice_Servo::ClearBit(int bitNo)
{
return notImplemented;
}
Tristate SoftataDevice_Servo::ToggleBit(int bitNo)
{
return notImplemented;
}