星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PenEvents.cs 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. using System;
  2. using TQLComm;
  3. namespace XHWK.WKTool
  4. {
  5. public class PenEvents : PenEvent
  6. {
  7. //int SA = 0;
  8. //int SB = 0;
  9. //int SC = 0;
  10. //int SD = 0;
  11. //int Sindex = 0;
  12. //int S = 0;
  13. //int O = 0;
  14. //int B = 0;
  15. //int P = 0;
  16. public static bool ConnectPen = false;
  17. public bool ShowPointLog = false;
  18. public static bool DrawIngend = true;
  19. public PenCommManager Manager;
  20. public int InToType = 0;
  21. /// <summary>
  22. /// TQL事件初始化,进入类型1录制2录屏
  23. /// </summary>
  24. /// <param name="type">进入类型1录制2录屏</param>
  25. public PenEvents(int type)//(Form1 form)
  26. {
  27. InToType = type;
  28. //this.form = form;
  29. Manager = new PenCommManager(this);
  30. Manager.Init();
  31. ////获取离线数据量
  32. //Manager.GetOfflineDataNo();
  33. ////开始下载离线数据
  34. //Manager.StartDownloadOfflineData();
  35. ////继续
  36. //Manager.ContinueDownloadOfflineData();
  37. ////暂停下载
  38. //Manager.PauseDownloadOfflineData();
  39. //删除离线数据
  40. Manager.RemoveOfflineData();
  41. }
  42. public void StartRecvDataTimer1()
  43. {
  44. DrawIngend = false;
  45. System.Timers.Timer t = new System.Timers.Timer(1000);
  46. t.Elapsed += new System.Timers.ElapsedEventHandler(timerCall);
  47. t.AutoReset = false;//设置是执行一次(false)还是一直执行(true);
  48. t.Enabled = true;//是否执行System.Timers.Timer.Elapsed事件;
  49. }
  50. //委托执行的方法
  51. private void timerCall(object source, System.Timers.ElapsedEventArgs e)
  52. {
  53. DrawIngend = true;
  54. //MessageBox.Show("ni");
  55. }
  56. public void OnGetOIDType(uint oType)
  57. {
  58. }
  59. public void OnSetOIDType(bool bSuccess)
  60. {
  61. }
  62. public void onConfirmReceiveOfflineData(bool bSuccess)
  63. {
  64. }
  65. /// <summary>
  66. /// 智能笔连接状态
  67. /// </summary>
  68. /// <param name="bConnected"></param>
  69. public void onConnectionStatus(bool bConnected)
  70. {
  71. ConnectPen = bConnected;
  72. try
  73. {
  74. if (bConnected)
  75. {
  76. App.TQLPenStatus = true;
  77. //form.AddLog("智能笔已连接!");
  78. if (App.W_XHMicroLessonSystemWindow != null)
  79. App.W_XHMicroLessonSystemWindow.UpdateDevStatus();
  80. }
  81. else
  82. {
  83. App.TQLPenStatus = false;
  84. //form.DisConnect();
  85. //form.AddLog("智能笔已断开连接!");
  86. if (App.W_XHMicroLessonSystemWindow != null)
  87. App.W_XHMicroLessonSystemWindow.UpdateDevStatus();
  88. }
  89. }
  90. catch (Exception)
  91. {
  92. }
  93. }
  94. public void onContinueOfflineData(bool bSuccess)
  95. {
  96. }
  97. /// <summary>
  98. /// 下载离线数据
  99. /// </summary>
  100. /// <param name="bEnd"></param>
  101. public void onEndOfDownloadOfflineData(bool bEnd)
  102. {
  103. if (bEnd)
  104. {
  105. ////继续
  106. //Manager.ContinueDownloadOfflineData();
  107. ////暂停下载
  108. //Manager.PauseDownloadOfflineData();
  109. //下载离线数据成功!
  110. //删除离线数据
  111. Manager.RemoveOfflineData();
  112. }
  113. else
  114. {
  115. //下载离线数据失败!
  116. //删除离线数据
  117. Manager.RemoveOfflineData();
  118. }
  119. }
  120. public void onGetAutoPowerOffTime(short Data)
  121. {
  122. //if (form.PenAttribute != null) form.PenAttribute.SetoffTextString(Data.ToString());
  123. //form.AddLog("当前自动休眠时间:" + Data.ToString() + "!");
  124. }
  125. public void onGetAutoPowerOnMode(bool bSetOn)
  126. {
  127. //if (form.PenAttribute != null) form.PenAttribute.SetSevseepComBox(bSetOn);
  128. //form.AddLog("当前唤醒模式笔尖压力是否唤醒:" + bSetOn.ToString() + "!");
  129. }
  130. public void onGetBatteryPower(short Data)
  131. {
  132. //if (form.PenAttribute != null) form.PenAttribute.SetBatteryTextString(Data.ToString() + "%");
  133. //form.AddLog("当前剩余电量:" + Data.ToString() + "%!");
  134. }
  135. public void onGetBeepStatus(bool bSetOn)
  136. {
  137. //if (form.PenAttribute != null) form.PenAttribute.SetBeetComBox(bSetOn);
  138. //form.AddLog("当前蜂鸣器模式是否响动:" + bSetOn.ToString() + "!");
  139. }
  140. public void onGetCustomerID(uint ID1, uint ID2)
  141. {
  142. }
  143. public void onGetElementCode(uint OID, uint SID, int Size)
  144. {
  145. }
  146. public void onGetFWVersion(string strData)
  147. {
  148. //if (form.PenAttribute != null) form.PenAttribute.SetBTTextString(strData);
  149. //form.AddLog("当前蓝牙版本号:" + strData + "!");
  150. }
  151. public void onGetMCUFWVersion(string strData)
  152. {
  153. //if (form.PenAttribute != null) form.PenAttribute.SetMCUTextString(strData);
  154. //form.AddLog("当前MCU版本号:" + strData + "!");
  155. }
  156. public void onGetMacAddress(string macAddress)
  157. {
  158. //if (form.PenAttribute != null) form.PenAttribute.SetMAcTextString(macAddress);
  159. //form.AddLog("当前MAC:" + macAddress + "!");
  160. }
  161. public void onGetOID4ElementCode(int SA, int SB, int SC, int SD, int index)
  162. {
  163. //if (this.SA != SA || this.SB != SB || this.SC != SC || this.SD != SD || this.Sindex != index)
  164. //{
  165. // this.SA = SA; this.SB = SB; this.SC = SC; this.SD = SD; this.Sindex = index;
  166. // form.AddLog("SA:" + SA.ToString() + "," + "SB:" + SB.ToString() + "," + "SC:" + SC.ToString() + "," + "SD:" + SD.ToString() + "," + "index:" + index.ToString());
  167. //}
  168. }
  169. public void onGetOfflineDataNo(int Data)
  170. {
  171. ConnectPen = true;
  172. if (Data > 0)
  173. {
  174. //开始下载离线数据
  175. Manager.StartDownloadOfflineData();
  176. }
  177. //form.AddLog("当前离线数据量:" + Data.ToString() + "!");
  178. //if (Data == 0 && form.StartDownload == true)
  179. //{
  180. // form.StartDownload = false;
  181. // form.StartOrStop(form.StartDownload);
  182. // form.AddLog("下载离线数据成功!");
  183. //}
  184. }
  185. public void onGetPenColor(short Data)
  186. {
  187. //if (form.PenAttribute != null) form.PenAttribute.SetLEDComBox(Data);
  188. //switch (Data)
  189. //{
  190. // case 1:
  191. // form.timing.SetPenColor(Color.Blue);
  192. // break;
  193. // case 2:
  194. // form.timing.SetPenColor(Color.Green);
  195. // break;
  196. // case 3:
  197. // form.timing.SetPenColor(Color.Cyan);
  198. // break;
  199. // case 4:
  200. // form.timing.SetPenColor(Color.Red);
  201. // break;
  202. // case 5:
  203. // form.timing.SetPenColor(Color.Magenta);
  204. // break;
  205. // case 6:
  206. // form.timing.SetPenColor(Color.Yellow);
  207. // break;
  208. // case 7:
  209. // form.timing.SetPenColor(Color.Black);
  210. // break;
  211. // default:
  212. // break;
  213. //}
  214. }
  215. /// <summary>
  216. /// 获取笔名
  217. /// </summary>
  218. /// <param name="localName"></param>
  219. public void onGetPenLocalName(string localName)
  220. {
  221. //if (form.PenAttribute != null) form.PenAttribute.SetNameTextString(localName);
  222. //form.AddLog("当前笔名:" + localName + "!");
  223. }
  224. public void onGetPressureCalibrationData(uint LData, uint HData)
  225. {
  226. }
  227. private DateTime ConvertLongToDateTime(long d)
  228. {
  229. DateTime dtStart = Convert.ToDateTime("1970-1-1");
  230. long lTime = long.Parse(d.ToString());
  231. TimeSpan toNow = new TimeSpan(lTime);
  232. DateTime dtResult = dtStart.AddSeconds(lTime);
  233. return dtResult;
  234. // return dtResult;
  235. }
  236. public void onGetRTC(long Data)
  237. {
  238. //DateTime time = ConvertLongToDateTime(Data);
  239. //if (form.PenAttribute != null) form.PenAttribute.SetRTCTextString(time.ToString("yyyy-MM-dd HH:mm:ss"));
  240. //form.AddLog("当前RTC:" + time.ToString("yyyy-MM-dd HH:mm:ss") + "!");
  241. }
  242. public void onGetSensitivityLevel(short Data)
  243. {
  244. //ConnectPen = true;
  245. //if (form.PenAttribute != null) form.PenAttribute.SetSevComBox(Data);
  246. //form.AddLog("当前压力敏感度:" + Data.ToString() + "!");
  247. }
  248. /// <summary>
  249. /// 内存使用量
  250. /// </summary>
  251. /// <param name="Data"></param>
  252. public void onGetUsedMemory(short Data)
  253. {
  254. //if (form.PenAttribute != null) form.PenAttribute.SetmemTextString(Data.ToString());
  255. //form.AddLog("当前使用内存为:" + Data.ToString() + "!");
  256. }
  257. /// <summary>
  258. /// 获取蓝牙适配器连接状态
  259. /// </summary>
  260. /// <param name="bReady"></param>
  261. public void onHIDGetReady(bool bReady)
  262. {
  263. //if (bReady)
  264. //{
  265. // form.AddLog("蓝牙适配器已连接!");
  266. //}
  267. //else
  268. //{
  269. // form.AddLog("蓝牙适配器已断开连接!");
  270. //}
  271. }
  272. public void onPauseOfflineData(bool bSuccess)
  273. {
  274. }
  275. /// <summary>
  276. /// 书写点
  277. /// </summary>
  278. /// <param name="dot"></param>
  279. /// <param name="count"></param>
  280. public void onReceiveDot(Dot dot, int count)
  281. {
  282. if (InToType == 1)
  283. {
  284. //录制模式
  285. if (dot.type == DotType.PEN_HOVER)
  286. {
  287. return;
  288. }
  289. else if (dot.type == DotType.PEN_DOWN)
  290. {
  291. App.W_XHMicroLessonSystemWindow.TqlDown();
  292. }
  293. else if (dot.type == DotType.PEN_UP)
  294. {
  295. App.W_XHMicroLessonSystemWindow.TqlUp();
  296. }
  297. else if (dot.type == DotType.PEN_MOVE)
  298. {
  299. double CX = (double)dot.x + (double)dot.fx / 100.00;
  300. double CY = (double)dot.y + (double)dot.fy / 100.00;
  301. App.W_XHMicroLessonSystemWindow.TqlPenWrite
  302. (
  303. CX,
  304. CY,
  305. dot.force
  306. );
  307. //form.AddLog("x:" + (dot.x + dot.fx / 100f).ToString() + ", " + "y:" + (dot.y + dot.fy / 100f).ToString());
  308. }
  309. }
  310. else if (InToType == 2)
  311. {
  312. //录屏模式
  313. if (dot.type == DotType.PEN_HOVER)
  314. {
  315. return;
  316. }
  317. else if (dot.type == DotType.PEN_DOWN)
  318. {
  319. App.W_PracticeWindow.TqlDown();
  320. }
  321. else if (dot.type == DotType.PEN_UP)
  322. {
  323. App.W_PracticeWindow.TqlUp();
  324. }
  325. else if (dot.type == DotType.PEN_MOVE)
  326. {
  327. double CX = (double)dot.x + (double)dot.fx / 100.00;
  328. double CY = (double)dot.y + (double)dot.fy / 100.00;
  329. App.W_PracticeWindow.TqlPenWrite
  330. (
  331. CX,
  332. CY,
  333. dot.force
  334. );
  335. //form.AddLog("x:" + (dot.x + dot.fx / 100f).ToString() + ", " + "y:" + (dot.y + dot.fy / 100f).ToString());
  336. }
  337. }
  338. ////可用于分页使用
  339. //if (this.S != dot.sectionId || this.O != dot.ownerId || this.B != dot.noteId || this.P != dot.pageId)
  340. //{
  341. // this.S = dot.sectionId; this.O = dot.ownerId; this.B = dot.noteId; this.P = dot.pageId;
  342. // //form.AddLog("Dot_S:" + this.S.ToString() + ", " + "Dot_O:" + this.O.ToString() + ", " + "Dot_B:" + this.B.ToString() + ", " + "Dot_P:" + this.P.ToString());
  343. //}
  344. //if (dot.type == DotType.PEN_HOVER) return;
  345. //if (this.S != dot.sectionId || this.O != dot.ownerId || this.B != dot.noteId || this.P != dot.pageId)
  346. //{
  347. // this.S = dot.sectionId; this.O = dot.ownerId; this.B = dot.noteId; this.P = dot.pageId;
  348. // //form.AddLog("Dot_S:" + this.S.ToString() + ", " + "Dot_O:" + this.O.ToString() + ", " + "Dot_B:" + this.B.ToString() + ", " + "Dot_P:" + this.P.ToString());
  349. //}
  350. //if (ShowPointLog == true)
  351. //{
  352. // //form.AddLog("x:" + (dot.x + dot.fx / 100f).ToString() + ", " + "y:" + (dot.y + dot.fy / 100f).ToString());
  353. //}
  354. ///* if (dot.type == DotType.PEN_DOWN || dot.type == DotType.PEN_MOVE || dot.type == DotType.PEN_UP)
  355. // {
  356. // form.AddLog("Dot_type:" + dot.type.ToString() + ", " + "Dot_force:" + dot.force.ToString());
  357. // } */
  358. ////if (DrawingBox.DrawType != 2) DrawingBox.DrawType = 1;
  359. ////form.Drawing(dot);
  360. //if (DrawIngend == true)
  361. //{
  362. // StartRecvDataTimer1();
  363. //}
  364. ///* long unixTimeStamp = (long)(dot.timeLong - 28800000);//1478162177;
  365. // System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(2010, 1, 1)); // 当地时区
  366. // DateTime dt = startTime.AddMilliseconds(unixTimeStamp);
  367. // form.AddLog("ON:" + dt.ToString("MM/dd HH:mm:ss.fff"));*/
  368. }
  369. /// <summary>
  370. /// 接收脱机数据
  371. /// </summary>
  372. /// <param name="dot"></param>
  373. /// <param name="count"></param>
  374. public void onReceiveOfflineData(Dot dot, int count)
  375. {
  376. //if (form.StartDownload == false)
  377. //{
  378. // Manager.StopDownloadOfflineData();
  379. // return;
  380. //}
  381. //if (this.S != dot.sectionId || this.O != dot.ownerId || this.B != dot.noteId || this.P != dot.pageId)
  382. //{
  383. // this.S = dot.sectionId; this.O = dot.ownerId; this.B = dot.noteId; this.P = dot.pageId;
  384. // form.AddLog("Dot_S:" + this.S.ToString() + ", " + "Dot_O:" + this.O.ToString() + ", " + "Dot_B:" + this.B.ToString() + ", " + "Dot_P:" + this.P.ToString());
  385. //}
  386. ///*long unixTimeStamp = (long)(dot.timeLong - 28800000);//1478162177;
  387. //System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(2010, 1, 1)); // 当地时区
  388. //DateTime dt = startTime.AddMilliseconds(unixTimeStamp);
  389. //form.AddLog("OFF:" + dt.ToString("MM/dd HH:mm:ss.fff"));
  390. //*/
  391. ///* DateTime tmp = new System.DateTime(2010, 1, 1);
  392. // tmp.AddMilliseconds(dot.timeLong);
  393. // form.AddLog("TIME:" + tmp.ToString("MM/dd HH:mm:ss"));*/
  394. //// form.AddLog("TIME:" + dot.timeLong.ToString());
  395. //if (DrawingBox.DrawType != 2) DrawingBox.DrawType = 3;
  396. //form.Drawing(dot);
  397. }
  398. public void onReceiveOriginalDot(Dot dot, int count)
  399. {
  400. //form.Drawing(dot);
  401. }
  402. public void onRemoveOfflineData(bool bRemoved)
  403. {
  404. //if (bRemoved)
  405. //{
  406. // form.AddLog("删除离线数据成功!");
  407. // form.StartDownload = false;
  408. // form.ContinueDownload = true;
  409. // form.DrawOffType = -1;
  410. //}
  411. //else form.AddLog("删除离线数据失败!");
  412. }
  413. public void onSetAutoPowerOffTime(bool bsuccess)
  414. {
  415. //if (bsuccess) form.AddLog("设置自动休眠时间成功!");
  416. //else form.AddLog("设置自动休眠时间失败!");
  417. }
  418. public void onSetAutoPowerOnMode(bool bsuccess)
  419. {
  420. //if (bsuccess) form.AddLog("设置笔的唤醒模式成功!");
  421. //else form.AddLog("设置笔的唤醒模式失败!");
  422. }
  423. public void onSetBeepStatus(bool bsuccess)
  424. {
  425. //if (bsuccess) form.AddLog("设置蜂鸣器成功!");
  426. //else form.AddLog("设置蜂鸣器失败!");
  427. }
  428. public void onSetCustomerID(bool bsuccess)
  429. {
  430. }
  431. public void onSetElementCode(bool bSuccess)
  432. {
  433. }
  434. public void onSetPenColor(bool bsuccess)
  435. {
  436. //if (Form1.SetColor == false) return;
  437. //Form1.SetColor = false;
  438. //if (bsuccess) form.AddLog("设置笔LED灯颜色成功!");
  439. //else form.AddLog("设置笔LED灯颜色失败!");
  440. }
  441. public void onSetPenLocalName(bool bsuccess)
  442. {
  443. //if (bsuccess) form.AddLog("设置笔名成功!");
  444. //else form.AddLog("设置笔名失败!");
  445. }
  446. public void onSetSensitivityLevel(bool bsuccess)
  447. {
  448. //if (bsuccess) form.AddLog("设置压力敏感度成功!");
  449. //else form.AddLog("设置压力敏感度失败!");
  450. }
  451. public void onStartDownloadOfflineData(bool bStart)
  452. {
  453. }
  454. public void onStopDownloadOfflineData(bool bStart)
  455. {
  456. }
  457. public void onWriteRTC(bool bsuccess)
  458. {
  459. //if (bsuccess)
  460. //{
  461. // form.AddLog("设置RTC成功!");
  462. // Manager.GetRTC();
  463. //}
  464. //else form.AddLog("设置RTC失败!");
  465. }
  466. public void DownloadOfflineDataRate(float Rate)
  467. {
  468. //form.SetProGress(Rate);
  469. }
  470. public void onGetMCUFCode(string strData)
  471. {
  472. //if (form.PenAttribute != null) form.PenAttribute.SetMcuCodeTextString(strData);
  473. //form.AddLog("MCU序列号:" + strData + "!");
  474. }
  475. public void OnGetPenCodeType(uint oType)
  476. {
  477. }
  478. public void onSetPenHover(byte type)
  479. {
  480. //if (type == 1)
  481. //{
  482. // form.AddLog("设置悬浮打开!");
  483. // form.PenAttribute.SetHoverComBox(0);
  484. //}
  485. //else if (type == 0)
  486. //{
  487. // form.AddLog("设置悬浮关闭!");
  488. // form.PenAttribute.SetHoverComBox(1);
  489. //}
  490. }
  491. }
  492. }