cmd_key_event.js 12 KB

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