MainWindow.xaml.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Collections;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. using ActuBoardAPI;
  17. namespace VTExperiment1
  18. {
  19. /// <summary>
  20. /// Interaction logic for MainWindow.xaml
  21. /// </summary>
  22. public partial class MainWindow : Window
  23. {
  24. private ActuBoardInterface _abi;
  25. double[] calibratedIntensities;
  26. int reversal_ctr = 0;
  27. int distance = 5;
  28. int reversal_flag = 0;
  29. int step = 1;
  30. Tuple<int, int>[] tuples =
  31. { Tuple.Create(4, 5), // 1 unit distance
  32. Tuple.Create(3, 5), // 2 units
  33. Tuple.Create(3, 6),
  34. Tuple.Create(2, 6),
  35. Tuple.Create(2, 7),
  36. Tuple.Create(1, 7),
  37. Tuple.Create(1, 8),
  38. Tuple.Create(0, 8),
  39. Tuple.Create(0, 9)
  40. };
  41. Tuple<int, int>[] tuples6 =
  42. {
  43. Tuple.Create(2, 3), // 1 unit distance
  44. Tuple.Create(2, 4), // 2 units
  45. Tuple.Create(1, 4),
  46. Tuple.Create(1, 5),
  47. Tuple.Create(0, 5)
  48. };
  49. public MainWindow()
  50. {
  51. InitializeComponent();
  52. //Console.WriteLine(_abi.SetChannel(45, 125));
  53. Calibration calibration = new Calibration();
  54. calibration.ShowDialog();
  55. calibration.BringIntoView();
  56. calibratedIntensities = calibration.GetCalibrationData();
  57. foreach (double d in calibratedIntensities)
  58. Console.Write(" " + d);
  59. _abi = new ActuBoardInterface();
  60. _abi.SetComPort(6);
  61. _abi.Connect();
  62. _abi.EnableOutput(true);
  63. }
  64. private void DISTINCT_Click(object sender, RoutedEventArgs e)
  65. {
  66. Logger.logger.LogWrite("1 Point" + distance);
  67. if (reversal_flag == 1)
  68. {
  69. reversal_ctr += 1;
  70. reversal_flag = 0;
  71. Logger.logger.LogWrite("REVERSAL " + reversal_ctr);
  72. }
  73. if (distance - step > 0)
  74. {
  75. distance = distance - step;
  76. }
  77. //Vibrate();
  78. }
  79. private void NONDISTINCT_Click(object sender, RoutedEventArgs e)
  80. {
  81. Logger.logger.LogWrite("Several Points" + distance);
  82. if (reversal_flag == 0)
  83. {
  84. reversal_ctr += 1;
  85. reversal_flag = 1;
  86. Logger.logger.LogWrite("REVERSAL " + reversal_ctr);
  87. }
  88. if (distance + step < 6)
  89. {
  90. distance = distance + step;
  91. }
  92. //Vibrate();
  93. }
  94. private void VIBRATE_Click(object sender, RoutedEventArgs e)
  95. {
  96. Vibrate();
  97. }
  98. private void Vibrate()
  99. { if(Logger.logger.BodyLocation == "Wrist")
  100. {
  101. int m1 = tuples6[distance].Item1;
  102. int m2 = tuples6[distance].Item2;
  103. _abi.SetChannel(m1 + 40, (int)((calibratedIntensities[m1] / 50) * 165));
  104. _abi.SetChannel(m2 + 40, (int)((calibratedIntensities[m2] / 50) * 165));
  105. System.Threading.Thread.Sleep(1000);
  106. _abi.SetChannel(m1 + 40, 0);
  107. _abi.SetChannel(m2 + 40, 0);
  108. }
  109. else
  110. {
  111. int m1 = tuples[distance].Item1;
  112. int m2 = tuples[distance].Item2;
  113. _abi.SetChannel(m1 + 40, (int)((calibratedIntensities[m1] / 50) * 165));
  114. _abi.SetChannel(m2 + 40, (int)((calibratedIntensities[m2] / 50) * 165));
  115. System.Threading.Thread.Sleep(1000);
  116. _abi.SetChannel(m1 + 40, 0);
  117. _abi.SetChannel(m2 + 40, 0);
  118. }
  119. if (reversal_ctr == 6)
  120. {
  121. Close();
  122. }
  123. }
  124. }
  125. public class DataPoint
  126. {
  127. int dist;
  128. bool distinct;
  129. public DataPoint(int distance, bool distinct)
  130. {
  131. dist = distance;
  132. this.distinct = distinct;
  133. }
  134. }
  135. }