Skip to content

Commit e74fd34

Browse files
authored
feat(Sparkbot): add camera flip control via MCP (#716)
1 parent 89fbf89 commit e74fd34

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

main/boards/esp-sparkbot/esp_sparkbot_board.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "button.h"
77
#include "config.h"
88
#include "mcp_server.h"
9+
#include "settings.h"
910

1011
#include <wifi_station.h>
1112
#include <esp_log.h>
@@ -164,6 +165,12 @@ class EspSparkBot : public WifiBoard {
164165
camera_config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
165166

166167
camera_ = new Esp32Camera(camera_config);
168+
169+
Settings settings("sparkbot", false);
170+
// 考虑到部分复刻使用了不可动摄像头的设计,默认启用翻转
171+
bool camera_flipped = static_cast<bool>(settings.GetInt("camera-flipped", 1));
172+
camera_->SetHMirror(camera_flipped);
173+
camera_->SetVFlip(camera_flipped);
167174
}
168175

169176
/*
@@ -246,6 +253,19 @@ class EspSparkBot : public WifiBoard {
246253
}
247254
throw std::runtime_error("Invalid light mode");
248255
});
256+
257+
mcp_server.AddTool("self.camera.set_camera_flipped", "翻转摄像头图像方向", PropertyList(), [this](const PropertyList& properties) -> ReturnValue {
258+
Settings settings("sparkbot", true);
259+
// 考虑到部分复刻使用了不可动摄像头的设计,默认启用翻转
260+
bool flipped = !static_cast<bool>(settings.GetInt("camera-flipped", 1));
261+
262+
camera_->SetHMirror(flipped);
263+
camera_->SetVFlip(flipped);
264+
265+
settings.SetInt("camera-flipped", flipped ? 1 : 0);
266+
267+
return true;
268+
});
249269
}
250270

251271
public:

0 commit comments

Comments
 (0)