feat(legacy): implement set hand type api
This commit is contained in:
parent
185646dbd2
commit
a55d15b30d
@ -1,6 +1,7 @@
|
|||||||
package legacy
|
package legacy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -62,3 +63,55 @@ func (s *LegacyServer) handleHandConfigs(c *gin.Context) {
|
|||||||
Data: result,
|
Data: result,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handleHandType 手型设置处理函数
|
||||||
|
func (s *LegacyServer) handleHandType(c *gin.Context) {
|
||||||
|
var req HandTypeRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
c.JSON(http.StatusBadRequest, define.ApiResponse{
|
||||||
|
Status: "error",
|
||||||
|
Error: "无效的手型设置请求:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证接口
|
||||||
|
if !s.mapper.IsValidInterface(req.Interface) {
|
||||||
|
c.JSON(http.StatusBadRequest, define.ApiResponse{
|
||||||
|
Status: "error",
|
||||||
|
Error: fmt.Sprintf("无效的接口 %s,可用接口: %v", req.Interface, config.Config.AvailableInterfaces),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证手型 ID
|
||||||
|
if req.HandType == "left" && req.HandId != uint32(define.HAND_TYPE_LEFT) {
|
||||||
|
req.HandId = uint32(define.HAND_TYPE_LEFT)
|
||||||
|
} else if req.HandType == "right" && req.HandId != uint32(define.HAND_TYPE_RIGHT) {
|
||||||
|
req.HandId = uint32(define.HAND_TYPE_RIGHT)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置手型配置
|
||||||
|
if err := s.mapper.SetHandConfig(req.Interface, req.HandType, req.HandId); err != nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, define.ApiResponse{
|
||||||
|
Status: "error",
|
||||||
|
Error: "设置手型失败:" + err.Error(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
handTypeName := "右手"
|
||||||
|
if req.HandType == "left" {
|
||||||
|
handTypeName = "左手"
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, define.ApiResponse{
|
||||||
|
Status: "success",
|
||||||
|
Message: fmt.Sprintf("接口 %s 手型已设置为%s (0x%X)", req.Interface, handTypeName, req.HandId),
|
||||||
|
Data: map[string]any{
|
||||||
|
"interface": req.Interface,
|
||||||
|
"handType": req.HandType,
|
||||||
|
"handId": req.HandId,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user