MainForm.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace Fietsclient
  11. {
  12. public partial class MainForm : Form
  13. {
  14. private readonly AppGlobal _global;
  15. public MainForm(AppGlobal global)
  16. {
  17. InitializeComponent();
  18. _global = global;
  19. KettlerBikeComm.IncomingDataEvent += HandleBikeData;
  20. }
  21. private void button1_Click(object sender, EventArgs e)
  22. {
  23. _global.startComPort();
  24. }
  25. private void HandleBikeData(string[] data)
  26. {
  27. String logString = "";
  28. foreach (int indexChecked in checkedListBox1.CheckedIndices)
  29. {
  30. object item = checkedListBox1.Items[indexChecked];
  31. logString += item.ToString() + " : " + data[indexChecked] + " ";
  32. }
  33. addTextToLog(logString);
  34. /*addTextToLog("pulse: " + data[0] + ", rpm: " + data[1] + ", speed*10: " + data[2] + ", distance: " + data[3] +
  35. ", requested_power: " + data[4] + ", energy: " + data[5] + ", mm:ss: " + data[6] + ", actual_power: " + data[7]);*/
  36. }
  37. private void addTextToLog(string text)
  38. {
  39. if (this.InvokeRequired)
  40. {
  41. this.Invoke((new Action(() => addTextToLog(text))));
  42. return;
  43. }
  44. textBox1.AppendText(text + "\n");
  45. }
  46. private void button2_Click(object sender, EventArgs e)
  47. {
  48. _global.startAskingData();
  49. }
  50. private void button3_Click(object sender, EventArgs e)
  51. {
  52. _global.closeComPort();
  53. }
  54. }
  55. }