Repository navigation
Expand file tree
/
Copy pathCWrapper.cpp
More file actions
98 lines (70 loc) · 1.89 KB
/
Copy pathCWrapper.cpp
File metadata and controls
98 lines (70 loc) · 1.89 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
#include "pch.h"
#include "Arduino.h"
#include "ArduinoMock.h"
#include "AdafruitPwmServoDriverMock.h"
using namespace std;
namespace
{
recursive_mutex gMutex;
typedef unique_lock<recursive_mutex> unique_recursive_lock;
}
extern "C" {
MOCK_API void __cdecl Arduino_Setup()
{
const unique_recursive_lock lock(gMutex);
ArduinoSetup();
}
MOCK_API void __cdecl Arduino_Loop()
{
const unique_recursive_lock lock(gMutex);
ArduinoLoop();
}
MOCK_API void __cdecl Set_Micros(uint32_t micros)
{
setMockMicros(micros);
}
MOCK_API void __cdecl Serial_Write(const unsigned char* str, int32_t strLen)
{
const unique_recursive_lock lock(gMutex);
Serial.writeMock(str, strLen);
}
MOCK_API void __cdecl Serial_Read(char* buf, int32_t bufLen, int32_t* available)
{
const unique_recursive_lock lock(gMutex);
const auto str = Serial.readMock();
*available = static_cast<int32_t>(str.length());
str.copy(buf, bufLen);
}
MOCK_API void __cdecl Serial_SetCallback(void (*callback)())
{
const unique_recursive_lock lock(gMutex);
Serial.setCallback(callback);
}
MOCK_API int32_t __cdecl EEPROM_Size()
{
const unique_recursive_lock lock(gMutex);
return EEPROM.length();
}
MOCK_API void __cdecl EEPROM_Read(char* buf, int32_t bufLen)
{
const unique_recursive_lock lock(gMutex);
const auto end = EEPROM._mem.begin() + min<int>(bufLen, EEPROM.length());
copy(EEPROM._mem.begin(), end, buf);
}
MOCK_API int32_t __cdecl PWM_NumServos()
{
const unique_recursive_lock lock(gMutex);
return static_cast<int32_t>(PwmController()._pwmOn.size());
}
MOCK_API void __cdecl PWM_Read(uint16_t* on, uint16_t* off)
{
const unique_recursive_lock lock(gMutex);
const auto& pwm = PwmController();
copy(pwm._pwmOn.begin(), pwm._pwmOn.end(), on);
copy(pwm._pwmOff.begin(), pwm._pwmOff.end(), off);
}
MOCK_API void __cdecl AnalogInput_Set(uint8_t pin, uint16_t value)
{
setMockAnalogRead(pin, value);
}
}