Skip to content

Commit e34dccb

Browse files
Fixed
1 parent ac412d7 commit e34dccb

File tree

11 files changed

+395
-345
lines changed

11 files changed

+395
-345
lines changed

3rdparty/ConfigReader

CMakeLists.txt

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,27 @@ else()
2323
SET(REWRITE_FORCE "")
2424
endif()
2525

26+
# Set default Release mode if not specified
27+
if(NOT CMAKE_BUILD_TYPE)
28+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type defaulting to Release" FORCE)
29+
endif()
30+
2631

2732

2833
################################################################################
2934
## CONFIGURATION
3035
## project configuration
3136
################################################################################
3237
SET(${PARENT}_PAN_TILT ON CACHE BOOL "" ${REWRITE_FORCE})
33-
SET(${PARENT}_PAN_TILT_TEST ON CACHE BOOL "" ${REWRITE_FORCE})
34-
SET(${PARENT}_PAN_TILT_EXAMPLE ON CACHE BOOL "" ${REWRITE_FORCE})
38+
if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
39+
SET(${PARENT}_PAN_TILT_TEST OFF CACHE BOOL "" ${REWRITE_FORCE})
40+
SET(${PARENT}_PAN_TILT_EXAMPLE OFF CACHE BOOL "" ${REWRITE_FORCE})
41+
message("${PROJECT_NAME} included as subrepository.")
42+
else()
43+
SET(${PARENT}_PAN_TILT_TEST ON CACHE BOOL "" ${REWRITE_FORCE})
44+
SET(${PARENT}_PAN_TILT_EXAMPLE ON CACHE BOOL "" ${REWRITE_FORCE})
45+
message("${PROJECT_NAME} is a standalone project.")
46+
endif()
3547

3648

3749

@@ -40,8 +52,8 @@ SET(${PARENT}_PAN_TILT_EXAMPLE ON CACHE BOOL "" ${REWRITE_FORCE})
4052
## Adding subdirectories according to the project configuration
4153
################################################################################
4254
if (${PARENT}_PAN_TILT)
43-
add_subdirectory(src)
4455
add_subdirectory(3rdparty)
56+
add_subdirectory(src)
4557
endif()
4658

4759
if (${PARENT}_PAN_TILT_TEST)
-183 KB
Binary file not shown.

README.md

Lines changed: 180 additions & 173 deletions
Large diffs are not rendered by default.

example/CustomPanTilt.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ std::string cr::pantilt::CustomPanTilt::getVersion()
2626
bool cr::pantilt::CustomPanTilt::openPanTilt(std::string initString)
2727
{
2828
// Set connection flags.
29-
m_params.isInitialized = true;
29+
m_params.isOpen = true;
3030
m_params.isConnected = true;
3131

3232
return true;
@@ -40,7 +40,7 @@ bool cr::pantilt::CustomPanTilt::initPanTilt(PanTiltParams& params)
4040
m_params = params;
4141

4242
// Set connection flags.
43-
m_params.isInitialized = true;
43+
m_params.isOpen = true;
4444
m_params.isConnected = true;
4545

4646
return true;
@@ -51,14 +51,14 @@ bool cr::pantilt::CustomPanTilt::initPanTilt(PanTiltParams& params)
5151
void cr::pantilt::CustomPanTilt::closePanTilt()
5252
{
5353
m_params.isConnected = false;
54-
m_params.isInitialized = false;
54+
m_params.isOpen = false;
5555
}
5656

5757

5858

5959
bool cr::pantilt::CustomPanTilt::isPanTiltOpen()
6060
{
61-
return m_params.isInitialized;
61+
return m_params.isOpen;
6262
}
6363

6464

@@ -137,16 +137,6 @@ bool cr::pantilt::CustomPanTilt::setParam(PanTiltParam id, float value)
137137
m_params.tiltMotorSpeed = value;
138138
return true;
139139
}
140-
case PanTiltParam::IS_CONNECTED:
141-
{
142-
// Read only.
143-
return false;
144-
}
145-
case PanTiltParam::IS_INITIALIZED:
146-
{
147-
// Read only.
148-
return false;
149-
}
150140
case PanTiltParam::CUSTOM_1:
151141
{
152142
// Custom parameter.
@@ -204,9 +194,9 @@ float cr::pantilt::CustomPanTilt::getParam(PanTiltParam id)
204194
{
205195
return m_params.isConnected ? 1.0f : 0.0f;
206196
}
207-
case PanTiltParam::IS_INITIALIZED:
197+
case PanTiltParam::IS_OPEN:
208198
{
209-
return m_params.isInitialized ? 1.0f : 0.0f;
199+
return m_params.isOpen ? 1.0f : 0.0f;
210200
}
211201
case PanTiltParam::CUSTOM_1:
212202
{
@@ -293,23 +283,15 @@ bool cr::pantilt::CustomPanTilt::decodeAndExecuteCommand(uint8_t* data, int size
293283
// Decode command.
294284
PanTiltCommand commandId = PanTiltCommand::GO_TO_PAN_POSITION;
295285
PanTiltParam paramId = PanTiltParam::PAN_MOTOR_POSITION;
296-
float value = 0.0f;
297-
switch (PanTilt::decodeCommand(data, size, paramId, commandId, value))
298-
{
299-
// COMMAND.
300-
case 0:
301-
// Execute command.
302-
return executeCommand(commandId);
303-
// SET_PARAM.
304-
case 1:
305-
{
306-
// Set param.
307-
return setParam(paramId, value);
308-
}
309-
default:
310-
{
311-
return false;
312-
}
286+
float value1 = 0.0f;
287+
float value2 = 0.0f;
288+
switch (PanTilt::decodeCommand(data, size, paramId, commandId, value1, value2))
289+
{
290+
// COMMAND.
291+
case 0: return executeCommand(commandId, value1, value2);
292+
// SET_PARAM.
293+
case 1: return setParam(paramId, value1);
294+
default: return false;
313295
}
314296

315297
return false;

example/CustomPanTilt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,15 @@ class CustomPanTilt : public PanTilt
9191
* @param arg2 The argument value used by the command.
9292
* @return TRUE if the command was executed successfully, FALSE otherwise.
9393
*/
94-
bool executeCommand(PanTiltCommand id,
95-
float arg1 = 0.0f, float arg2 = 0.0f) override;
94+
bool executeCommand(PanTiltCommand id, float arg1 = 0.0f, float arg2 = 0.0f) override;
9695

9796
/**
9897
* @brief Decode and execute command.
9998
* @param data Pointer to command data.
10099
* @param size Size of data.
101100
* @return 0 - command decoded, 1 - set param command decoded, -1 - error.
102101
*/
103-
bool decodeAndExecuteCommand(uint8_t* data, int size);
102+
bool decodeAndExecuteCommand(uint8_t* data, int size) override;
104103

105104
private:
106105

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ cmake_minimum_required(VERSION 3.13)
66
## INTERFACE-PROJECT
77
## name and version
88
###############################################################################
9-
project(PanTilt VERSION 1.0.2 LANGUAGES CXX)
9+
project(PanTilt VERSION 1.1.0 LANGUAGES CXX)
1010

1111

1212

0 commit comments

Comments
 (0)