MainForm.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. addTextToLog("pulse: " + data[0] + ", rpm: " + data[1] + ", speed*10: " + data[2] + ", distance: " + data[3] +
  28. ", requested_power: " + data[4] + ", energy: " + data[5] + ", mm:ss: " + data[6] + ", actual_power: " + data[7]);
  29. }
  30. private void addTextToLog(string text)
  31. {
  32. if (this.InvokeRequired)
  33. {
  34. this.Invoke((new Action(() => addTextToLog(text))));
  35. return;
  36. }
  37. textBox1.AppendText(text + "\n");
  38. }
  39. private void button2_Click(object sender, EventArgs e)
  40. {
  41. _global.startAskingData();
  42. }
  43. private void button3_Click(object sender, EventArgs e)
  44. {
  45. _global.closeComPort();
  46. }
  47. }
  48. }