cmd_key_event.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. // 枚举定义
  2. const EnumCmdEvent = {
  3. nextChannel: 'nextChannel',
  4. previousChannel: 'previousChannel',
  5. switchChannel: 'switchChannel',
  6. previousAlbum: 'previousAlbum',
  7. nextAlbum: 'nextAlbum',
  8. nextSong: 'nextSong',
  9. previousSong: 'previousSong',
  10. speed: 'speed',
  11. fastback: 'fastback',
  12. stopSpeed: 'stopSpeed',
  13. stopFastback: 'stopFastback',
  14. startRecord: 'startRecord',
  15. stopRecord: 'stopRecord',
  16. battery: 'battery',
  17. lowKwnSet: 'lowKwnSet',
  18. batteryEarphone: 'batteryEarphone',
  19. ctrlStatus: 'ctrlStatus',
  20. lowPowerOpen: 'lowPowerOpen',
  21. eq: 'eq',
  22. lowDelayMode: 'lowDelayMode',
  23. sleep: 'sleep',
  24. wake: 'wake',
  25. volume: 'volume',
  26. version: 'version',
  27. sim: 'sim',
  28. dsn: 'dsn',
  29. playInfo: 'playInfo',
  30. playStatus: 'playStatus',
  31. auth: 'auth',
  32. unbind: 'unbind',
  33. enableTTS: 'enableTTS',
  34. switchDeviceMode: 'switchDeviceMode',
  35. netModeAuto: 'netModeAuto',
  36. getDeviceInfo: 'getDeviceInfo',
  37. collectState: 'collectState',
  38. todayStep: 'todayStep',
  39. todayRates: 'todayRates',
  40. targetSteps: 'targetSteps',
  41. setTimeFormat: 'setTimeFormat',
  42. setNotDisturb: 'setNotDisturb',
  43. setQuickViewTime: 'setQuickViewTime',
  44. openPush: 'openPush',
  45. takeHandLight: 'takeHandLight',
  46. payId: 'payId',
  47. authSleepStatus: 'authSleepStatus',
  48. btMac: 'btMac'
  49. };
  50. // 枚举定义
  51. const EnumPlayStatus = {
  52. none: 'none',
  53. play: 'play',
  54. pause: 'pause',
  55. stop: 'stop',
  56. completed: 'completed',
  57. error: 'error',
  58. buffering: 'buffering', // APP自己定义的特殊处理中间状态
  59. };
  60. // 或者使用对象字面量
  61. const EnumSupplier = {
  62. shanJing: "ShanJing",
  63. jieLi: "JieLi",
  64. lingXin: "LingXin",
  65. qiXinWei: "QiXinWei"
  66. };
  67. // 设备操作类
  68. class CmdEvent {
  69. constructor({ cmdEvent }) {
  70. this.cmdEvent = cmdEvent;
  71. this.channelId = 1;
  72. this.wakeSwitch = null;
  73. this.wakeCycle = [0, 0, 0, 0, 0, 0, 0];
  74. this.ctrlStatus = [0, 0, 0];
  75. this.lowPowerOpen = null;
  76. this.wakeHour = null;
  77. this.wakeMinutes = null;
  78. this.sleepSwitch = null;
  79. this.sleepHour = null;
  80. this.sleepMinutes = null;
  81. this.kwh = 9;
  82. this.kwhLeft = 9;
  83. this.kwhRight = 9;
  84. this.kwhBox = 9;
  85. this.lowKwnSet = false;
  86. this.volume = 0;
  87. this.version = "1.0.0";
  88. this.dsn = null;
  89. this.playStatus = null;
  90. this.playInfo = null;
  91. this.authInfo = null;
  92. this.item = null;
  93. this.eSim = null;
  94. this.sim = null;
  95. this.simIndex = null;
  96. this.enableTTS = null;
  97. this.eqs = null;
  98. this.lowDelayMode = null;
  99. this.lowDelayModeOpen = null;
  100. this.netModeAuto = null;
  101. this.pauseSleep = null;
  102. this.collectStatus = null;
  103. this.audioInfoId = null;
  104. this.todayStep = null;
  105. this.todayRates = null;
  106. this.stepTarget = null;
  107. this.setTimeFormat = null;
  108. this.setQuickViewTime = null;
  109. this.setNotDisturb = null;
  110. this.openPush = null;
  111. this.takeHandLight = null;
  112. this.stepDistance = null;
  113. this.stepCalories = null;
  114. this.stepTime = null;
  115. this.payId = null;
  116. this.btMac = null;
  117. this.deviceMode = null;
  118. }
  119. static wake({ wakeSwitch, wakeCycle, wakeHour, wakeMinutes }) {
  120. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.wake });
  121. event.wakeSwitch = wakeSwitch;
  122. event.wakeCycle = wakeCycle;
  123. event.wakeHour = wakeHour;
  124. event.wakeMinutes = wakeMinutes;
  125. return event;
  126. }
  127. static sim({ eSim, sim, simIndex }) {
  128. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sim });
  129. event.eSim = eSim;
  130. event.sim = sim;
  131. event.simIndex = simIndex;
  132. return event;
  133. }
  134. static sleep({ sleepSwitch, sleepHour, sleepMinutes }) {
  135. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.sleep });
  136. event.sleepSwitch = sleepSwitch;
  137. event.sleepHour = sleepHour;
  138. event.sleepMinutes = sleepMinutes;
  139. return event;
  140. }
  141. static ctrlStatus({ ctrlStatus }) {
  142. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.ctrlStatus });
  143. event.ctrlStatus = ctrlStatus;
  144. return event;
  145. }
  146. static switchChannel({ channelId }) {
  147. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchChannel });
  148. event.channelId = channelId;
  149. return event;
  150. }
  151. static switchDeviceMode({ deviceMode }) {
  152. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.switchDeviceMode });
  153. event.deviceMode = deviceMode;
  154. return event;
  155. }
  156. static enableTTS({ enableTTS }) {
  157. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.enableTTS });
  158. event.enableTTS = enableTTS;
  159. return event;
  160. }
  161. static battery({ kwh }) {
  162. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.battery });
  163. event.kwh = kwh;
  164. return event;
  165. }
  166. static queryLowKwn({ kwh }) {
  167. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowKwnSet });
  168. event.kwh = kwh;
  169. return event;
  170. }
  171. static dsn({ dsn }) {
  172. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.dsn });
  173. event.dsn = dsn;
  174. return event;
  175. }
  176. static getDeviceInfo() {
  177. return new CmdEvent({ cmdEvent: EnumCmdEvent.getDeviceInfo });
  178. }
  179. static todayStep({ todayStep, stepDistance, stepCalories, stepTime }) {
  180. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  181. event.todayStep = todayStep;
  182. event.stepDistance = stepDistance;
  183. event.stepCalories = stepCalories;
  184. event.stepTime = stepTime;
  185. return event;
  186. }
  187. static todaySport({ todayStep, stepDistance, stepCalories, stepTime }) {
  188. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayStep });
  189. event.todayStep = todayStep;
  190. event.stepDistance = stepDistance;
  191. event.stepCalories = stepCalories;
  192. event.stepTime = stepTime;
  193. return event;
  194. }
  195. static todayRates({ todayRates }) {
  196. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.todayRates });
  197. event.todayRates = todayRates;
  198. return event;
  199. }
  200. static pauseSleep({ pauseSleep }) {
  201. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.authSleepStatus });
  202. event.pauseSleep = pauseSleep;
  203. return event;
  204. }
  205. static targetSteps({ stepTarget }) {
  206. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.targetSteps });
  207. event.stepTarget = stepTarget;
  208. return event;
  209. }
  210. static setTimeFormat({ setTimeFormat }) {
  211. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setTimeFormat });
  212. event.setTimeFormat = setTimeFormat;
  213. return event;
  214. }
  215. static setNotDisturb({ setNotDisturb }) {
  216. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setNotDisturb });
  217. event.setNotDisturb = setNotDisturb;
  218. return event;
  219. }
  220. static setQuickViewTime({ setQuickViewTime }) {
  221. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.setQuickViewTime });
  222. event.setQuickViewTime = setQuickViewTime;
  223. return event;
  224. }
  225. static openPush({ openPush }) {
  226. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.openPush });
  227. event.openPush = openPush;
  228. return event;
  229. }
  230. static takeHandLight({ takeHandLight }) {
  231. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.takeHandLight });
  232. event.takeHandLight = takeHandLight;
  233. return event;
  234. }
  235. static batteryEarphone({ kwh, kwhLeft, kwhRight, kwhBox }) {
  236. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.batteryEarphone });
  237. event.kwh = kwh;
  238. event.kwhLeft = kwhLeft;
  239. event.kwhRight = kwhRight;
  240. event.kwhBox = kwhBox;
  241. return event;
  242. }
  243. static unbind({ item }) {
  244. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.unbind });
  245. event.item = item;
  246. return event;
  247. }
  248. static auth({ authInfo }) {
  249. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.auth });
  250. event.authInfo = authInfo;
  251. return event;
  252. }
  253. static eqs({ eqs }) {
  254. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.eq });
  255. event.eqs = eqs;
  256. return event;
  257. }
  258. static lowDelayMode({ lowDelayMode, lowDelayModeOpen }) {
  259. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowDelayMode });
  260. event.lowDelayMode = lowDelayMode;
  261. event.lowDelayModeOpen = lowDelayModeOpen;
  262. return event;
  263. }
  264. static lowPowerOpen({ lowPowerOpen }) {
  265. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.lowPowerOpen });
  266. event.lowPowerOpen = lowPowerOpen;
  267. return event;
  268. }
  269. static volume({ volume }) {
  270. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.volume });
  271. event.volume = volume;
  272. return event;
  273. }
  274. static version({ version }) {
  275. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.version });
  276. event.version = version;
  277. return event;
  278. }
  279. static btMac({ btMac }) {
  280. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.btMac });
  281. event.btMac = btMac;
  282. return event;
  283. }
  284. static netModeAuto({ netModeAuto }) {
  285. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.netModeAuto });
  286. event.netModeAuto = netModeAuto;
  287. return event;
  288. }
  289. static playInfo({ playInfo }) {
  290. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playInfo });
  291. event.playInfo = playInfo;
  292. return event;
  293. }
  294. static payId({ payId }) {
  295. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.payId });
  296. event.payId = payId;
  297. return event;
  298. }
  299. static collectState({ collectStatus, audioInfoId }) {
  300. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.collectState });
  301. event.collectStatus = collectStatus;
  302. event.audioInfoId = audioInfoId;
  303. return event;
  304. }
  305. static playStatus({ playStatus }) {
  306. const event = new CmdEvent({ cmdEvent: EnumCmdEvent.playStatus });
  307. switch (playStatus) {
  308. case 1:
  309. event.playStatus = EnumPlayStatus.play;
  310. break;
  311. case 2:
  312. event.playStatus = EnumPlayStatus.pause;
  313. break;
  314. case 3:
  315. event.playStatus = EnumPlayStatus.stop;
  316. break;
  317. case 4:
  318. event.playStatus = EnumPlayStatus.completed;
  319. break;
  320. default:
  321. }
  322. return event
  323. }
  324. toString() {
  325. return `CmdEvent{cmdEvent: ${this.cmdEvent}, channelId: ${this.channelId}, wakeSwitch: ${this.wakeSwitch}, wakeCycle: ${this.wakeCycle}, wakeHour: ${this.wakeHour}, wakeMinutes: ${this.wakeMinutes}, sleepSwitch: ${this.sleepSwitch}, sleepHour: ${this.sleepHour}, sleepMinutes: ${this.sleepMinutes}, kwh: ${this.kwh}, volume: ${this.volume}, version: ${this.version}}`;
  326. }
  327. }
  328. module.exports = {
  329. CmdEvent,
  330. EnumCmdEvent,
  331. EnumPlayStatus,
  332. EnumSupplier
  333. };