refactor: remove duplicate pose handler
This commit is contained in:
parent
afbb9bef28
commit
b342118980
@ -235,47 +235,8 @@ func (s *Server) handleResetPose(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecutePresetPose 执行预设姿势
|
// handleGetPresetPose 获取设备支持的预设姿势列表
|
||||||
func (s *Server) ExecutePresetPose(c *gin.Context) {
|
func (s *Server) handleGetPresetPose(c *gin.Context) {
|
||||||
deviceID := c.Param("deviceId")
|
|
||||||
presetName := c.Param("presetName")
|
|
||||||
|
|
||||||
device, err := s.deviceManager.GetDevice(deviceID)
|
|
||||||
if err != nil {
|
|
||||||
c.JSON(http.StatusNotFound, ApiResponse{
|
|
||||||
Status: "error",
|
|
||||||
Error: fmt.Sprintf("设备 %s 不存在", deviceID),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用设备的预设姿势方法
|
|
||||||
if err := device.ExecutePreset(presetName); err != nil {
|
|
||||||
c.JSON(http.StatusBadRequest, ApiResponse{
|
|
||||||
Status: "error",
|
|
||||||
Error: fmt.Sprintf("执行预设姿势失败: %v", err),
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// 停止当前动画(如果有)
|
|
||||||
engine := device.GetAnimationEngine()
|
|
||||||
if engine.IsRunning() {
|
|
||||||
engine.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, ApiResponse{
|
|
||||||
Status: "success",
|
|
||||||
Message: fmt.Sprintf("预设姿势 '%s' 执行成功", presetName),
|
|
||||||
Data: map[string]any{
|
|
||||||
"deviceId": deviceID,
|
|
||||||
"presetName": presetName,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSupportedPresets 获取设备支持的预设姿势列表
|
|
||||||
func (s *Server) GetSupportedPresets(c *gin.Context) {
|
|
||||||
deviceID := c.Param("deviceId")
|
deviceID := c.Param("deviceId")
|
||||||
|
|
||||||
device, err := s.deviceManager.GetDevice(deviceID)
|
device, err := s.deviceManager.GetDevice(deviceID)
|
||||||
|
@ -46,14 +46,13 @@ func (s *Server) SetupRoutes(r *gin.Engine) {
|
|||||||
// 姿态控制路由
|
// 姿态控制路由
|
||||||
poses := deviceRoutes.Group("/poses")
|
poses := deviceRoutes.Group("/poses")
|
||||||
{
|
{
|
||||||
poses.POST("/fingers", s.handleSetFingerPose) // 设置手指姿态
|
poses.POST("/fingers", s.handleSetFingerPose) // 设置手指姿态
|
||||||
poses.POST("/palm", s.handleSetPalmPose) // 设置手掌姿态
|
poses.POST("/palm", s.handleSetPalmPose) // 设置手掌姿态
|
||||||
poses.POST("/preset/:pose", s.handleSetPresetPose) // 设置预设姿势
|
poses.POST("/reset", s.handleResetPose) // 重置姿态
|
||||||
poses.POST("/reset", s.handleResetPose) // 重置姿态
|
|
||||||
|
|
||||||
// 新的预设姿势 API
|
// 新的预设姿势 API
|
||||||
poses.GET("/presets", s.GetSupportedPresets) // 获取支持的预设姿势列表
|
poses.GET("/presets", s.handleGetPresetPose) // 获取支持的预设姿势列表
|
||||||
poses.POST("/presets/:presetName", s.ExecutePresetPose) // 执行预设姿势
|
poses.POST("/presets/:presetName", s.handleSetPresetPose) // 执行预设姿势
|
||||||
}
|
}
|
||||||
|
|
||||||
// 动画控制路由
|
// 动画控制路由
|
||||||
|
Loading…
x
Reference in New Issue
Block a user