ble.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package ble
  2. import (
  3. "ai-status-light/internal/logger"
  4. )
  5. const (
  6. DefaultDeviceName = "AI-Light"
  7. )
  8. var modePriority = map[string]int{
  9. "error": 6,
  10. "alarm": 5,
  11. "thinking": 4,
  12. "busy": 3,
  13. "ai": 2,
  14. "traffic": 1,
  15. "success": 1,
  16. "off": 0,
  17. }
  18. func MapCodeToMode(code string) string {
  19. switch code {
  20. case "error":
  21. return "error"
  22. case "permission":
  23. return "alarm"
  24. case "reasoning":
  25. return "thinking"
  26. case "busy", "running", "using_tool", "retry", "pending":
  27. return "busy"
  28. case "idle":
  29. return "traffic"
  30. case "session_completed", "success":
  31. return "success"
  32. default:
  33. return "ai"
  34. }
  35. }
  36. func modePriorityValue(mode string) int {
  37. if p, ok := modePriority[mode]; ok {
  38. return p
  39. }
  40. return 0
  41. }
  42. func shouldUpdate(currentMode, newMode string) bool {
  43. return modePriorityValue(newMode) >= modePriorityValue(currentMode) || currentMode == ""
  44. }
  45. func logInfo(format string, args ...interface{}) {
  46. logger.Info(format, args...)
  47. }
  48. func logDebug(format string, args ...interface{}) {
  49. logger.Debug(format, args...)
  50. }
  51. func logError(format string, args ...interface{}) {
  52. logger.Error(format, args...)
  53. }
  54. func logWarn(format string, args ...interface{}) {
  55. logger.Warn(format, args...)
  56. }