Skip to content

Commit 2824c55

Browse files
author
Marcus Sonestedt
committed
Update mock/test to use Adafruit library instead
1 parent cdd17bc commit 2824c55

File tree

6 files changed

+34
-13
lines changed

6 files changed

+34
-13
lines changed

ServoPID.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
servopid.ino = servopid.ino
1515
EndProjectSection
1616
EndProject
17+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Adafruit-PWM-Servo-Driver", "Adafruit-PWM-Servo-Driver", "{09887C7C-D3AA-455B-B617-DCAFE1D65349}"
18+
ProjectSection(SolutionItems) = preProject
19+
Adafruit-PWM-Servo-Driver-Library\Adafruit_PWMServoDriver.cpp = Adafruit-PWM-Servo-Driver-Library\Adafruit_PWMServoDriver.cpp
20+
Adafruit-PWM-Servo-Driver-Library\Adafruit_PWMServoDriver.h = Adafruit-PWM-Servo-Driver-Library\Adafruit_PWMServoDriver.h
21+
EndProjectSection
22+
EndProject
1723
Global
1824
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1925
Debug|Any CPU = Debug|Any CPU

ServoPID.sln.DotSettings

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CppFormatting/NAMESPACE_INDENTATION/@EntryValue">Inner</s:String>
66
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CppFormatting/OUTDENT_COMMAS/@EntryValue">True</s:Boolean>
77
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EFeature_002EServices_002ECpp_002ECodeStyle_002ESettingsUpgrade_002EFunctionReturnStyleSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
8+
<s:Boolean x:Key="/Default/UserDictionary/Words/=Adafruit/@EntryIndexedValue">True</s:Boolean>
9+
<s:Boolean x:Key="/Default/UserDictionary/Words/=addr/@EntryIndexedValue">True</s:Boolean>
810
<s:Boolean x:Key="/Default/UserDictionary/Words/=Arduino/@EntryIndexedValue">True</s:Boolean>
9-
<s:Boolean x:Key="/Default/UserDictionary/Words/=coeff/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
11+
<s:Boolean x:Key="/Default/UserDictionary/Words/=caddr/@EntryIndexedValue">True</s:Boolean>
12+
<s:Boolean x:Key="/Default/UserDictionary/Words/=coeff/@EntryIndexedValue">True</s:Boolean>
13+
<s:Boolean x:Key="/Default/UserDictionary/Words/=prescale/@EntryIndexedValue">True</s:Boolean>
14+
<s:Boolean x:Key="/Default/UserDictionary/Words/=totempole/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

TestServoPID/ArduinoMock.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ extern std::vector<int> gAnalogPins;
1515

1616
}
1717
inline unsigned long micros() { return mock::gMicros; }
18-
inline void setMockMicros(const unsigned long value) { mock::gMicros = value;}
18+
inline void setMockMicros(const unsigned long value) { mock::gMicros = value; }
19+
20+
inline void delay(int ms) {};
1921

2022
inline int analogRead(const int pin) { return mock::gAnalogPins.at(pin);}
2123
inline void setMockAnalogRead(const int pin, const int value)

TestServoPID/TestServoPID.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
161161
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
162162
</ClCompile>
163+
<ClCompile Include="AdafruitPwmServoDriverMock.cpp" />
163164
<ClCompile Include="TestPID.cpp" />
164165
<ClCompile Include="TestSerial.cpp" />
165166
<ClCompile Include="TestSetupAndLoop.cpp" />
@@ -168,6 +169,7 @@
168169
<None Include="README.md" />
169170
</ItemGroup>
170171
<ItemGroup>
172+
<ClInclude Include="AdafruitPwmServoDriverMock.h" />
171173
<ClInclude Include="ArduinoMock.h" />
172174
<ClInclude Include="PCA9685Mock.h" />
173175
<ClInclude Include="pch.h" />

TestServoPID/TestServoPID.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<ClCompile Include="TestSetupAndLoop.cpp">
3737
<Filter>Source Files</Filter>
3838
</ClCompile>
39+
<ClCompile Include="AdafruitPwmServoDriverMock.cpp">
40+
<Filter>Source Files</Filter>
41+
</ClCompile>
3942
</ItemGroup>
4043
<ItemGroup>
4144
<None Include="README.md" />
@@ -50,5 +53,8 @@
5053
<ClInclude Include="PCA9685Mock.h">
5154
<Filter>Header Files</Filter>
5255
</ClInclude>
56+
<ClInclude Include="AdafruitPwmServoDriverMock.h">
57+
<Filter>Header Files</Filter>
58+
</ClInclude>
5359
</ItemGroup>
5460
</Project>

servopid.ino

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#define USE_PCA9685 1 // set 0 to use Arduino to directly control servos
22

3-
#ifndef ARDUINO
4-
#include "ArduinoMock.h"
5-
6-
namespace
7-
{
8-
#if USE_PCA9685 == 1
9-
#include "PCA9685Mock.h"
10-
#endif
11-
12-
#else
3+
#ifdef ARDUINO
134
#if USE_PCA9685 == 1
145
#include <Wire.h>
156
#include <Adafruit_PWMServoDriver.h>
167
#else
178
#include <Servo.h>
189
#endif
10+
#else
11+
#include "TestServoPID/ArduinoMock.h"
12+
13+
#if USE_PCA9685 == 1
14+
#include "TestServoPID/AdafruitPwmServoDriverMock.h"
15+
#endif
16+
17+
namespace
18+
{
1919
#endif
2020

2121
// PID regulator, incl low-pass lambda filter on D part
@@ -121,7 +121,7 @@ public:
121121
{
122122
const auto cAngle = constrain(angle, float(MinAngle), float(MaxAngle));
123123
const auto pwm = _pwmMin + (_pwmMax - _pwmMin) * cAngle / (float(MaxAngle) - float(MinAngle));
124-
gPwmController.setPWM(_pin, 0, pwm);
124+
gPwmController.setPWM(_pin, 0, uint16_t(pwm));
125125
}
126126

127127
private:

0 commit comments

Comments
 (0)