AppGlobal.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace Fietsclient
  8. {
  9. public class AppGlobal
  10. {
  11. private static AppGlobal _instance;
  12. public int[] StatusItemsChecked;
  13. Thread workerThread;
  14. public static AppGlobal Instance
  15. {
  16. get { return _instance ?? (_instance = new AppGlobal()); }
  17. }
  18. private KettlerBikeComm _bikeComm;
  19. private AppGlobal()
  20. {
  21. _bikeComm = new KettlerBikeComm();
  22. KettlerBikeComm.IncomingDataEvent += HandleBikeData; //initialize event
  23. }
  24. public void setTimeMode(string time)
  25. {
  26. _bikeComm.sendData("CU");
  27. _bikeComm.sendData("PT " + time);
  28. }
  29. public void setPower(string power)
  30. {
  31. _bikeComm.sendData("CU");
  32. _bikeComm.sendData("PW " + power);
  33. }
  34. public void setDistanceMode(string distance)
  35. {
  36. _bikeComm.sendData("CU");
  37. _bikeComm.sendData("PD " + distance);
  38. }
  39. public void startComPort()
  40. {
  41. startComPort("COM4");
  42. }
  43. public void startComPort(string portname)
  44. {
  45. _bikeComm.initComm(portname);
  46. }
  47. public void startAskingData()
  48. {
  49. workerThread = new Thread(() => workerThreadLoop());
  50. workerThread.Start();
  51. }
  52. private void workerThreadLoop()
  53. {
  54. while(true)
  55. {
  56. Thread.Sleep(1000);
  57. _bikeComm.sendData(KettlerBikeComm.STATUS);
  58. }
  59. }
  60. //event handler
  61. private void HandleBikeData(string[] data)
  62. {
  63. //doe iets ermee...
  64. }
  65. public void closeComPort()
  66. {
  67. if (workerThread != null)
  68. workerThread.Suspend();
  69. _bikeComm.closeComm();
  70. }
  71. }
  72. }