星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PenEvents.cs 18KB

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