LocalArmbandInterface.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Runtime.InteropServices;
  7. namespace SketchAssistantWPF
  8. {
  9. /// <summary>
  10. /// interface providing access to the vibrotactile armband
  11. /// accessing the BodyActuator.dll C library via the StaticLibMotors.dll c++ library
  12. /// </summary>
  13. public static class LocalArmbandInterface
  14. {
  15. /// <summary>
  16. /// constant to set the vibration mode:
  17. /// 0 -> no vibration
  18. /// 1 -> intensity 0.33
  19. /// 2 -> intensity 0.66
  20. /// 3 -> intensity 1.0
  21. /// </summary>
  22. static readonly int VIBRATION_MODE = 2;
  23. /// <summary>
  24. /// initializes the armband (and binds the C dll)
  25. /// must be called before calling any other of the methods of this class
  26. /// explicitly allocates memory and therefore must only be called once and must be followed by a call to DestroyArmband eventually
  27. /// </summary>
  28. /// <returns>an integer purely for debugging purposes, -1 means no unexpected behaviour occured and the initialization was successful</returns>
  29. [DllImport (@"../Debug/StaticLibMotors.dll", EntryPoint = "?setupArmband@ArmbandInterface@@QAAHXZ",
  30. CallingConvention = CallingConvention.Cdecl)]
  31. public static extern int SetupArmband();
  32. /// <summary>
  33. /// destroys the armband instance created by SetupArmband (thus freeing its allocated memory)
  34. /// </summary>
  35. /// <returns></returns>
  36. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?destroyArmband@ArmbandInterface@@QAAHXZ",
  37. CallingConvention = CallingConvention.Cdecl)]
  38. public static extern int DestroyArmband();
  39. /// <summary>
  40. /// starts actuation of the specified tactor (motor) at the specified intensity (until it is stopped)
  41. /// </summary>
  42. /// <param name="motorNumber">integer from 0 to 7 specifying the number of the tactor to actuate</param>
  43. /// <param name="intensity">intensity, ranging from 0.0 to 1.0 by default</param>
  44. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?startVibrate@ArmbandInterface@@QAAXHM@Z",
  45. CallingConvention = CallingConvention.Cdecl)]
  46. public static extern void StartVibrate(int motorNumber, double intensity);
  47. /// <summary>
  48. /// stop actuation of the specified tactor (motor)
  49. /// </summary>
  50. /// <param name="motorNumber">integer from 0 to 7 specifying the number of the tactor to stop</param>
  51. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?stopVibrate@ArmbandInterface@@QAAXH@Z",
  52. CallingConvention = CallingConvention.Cdecl)]
  53. public static extern void StopVibration(int motorNumber);
  54. /// <summary>
  55. /// starts actuation of the specified tactor (motor) at 0.33 for a specified amount of time
  56. /// </summary>
  57. /// <param name="tactor">integer from 0 to 7 specifying the number of the tactor to actuate</param>
  58. /// <param name="intensity">intensity, ranging from 0.0 to 1.0 by default</param>
  59. /// <param name="duration">number of millisecons to actuate the tactor for</param>
  60. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?actuate33@ArmbandInterface@@QAAXHNH@Z",
  61. CallingConvention = CallingConvention.Cdecl)]
  62. private static extern void Actuate33(int tactor, double intensity, int duration);
  63. /// <summary>
  64. /// starts actuation of the specified tactor (motor) at intensity 0.66 for a specified amount of time
  65. /// </summary>
  66. /// <param name="tactor">integer from 0 to 7 specifying the number of the tactor to actuate</param>
  67. /// <param name="intensity">intensity, ranging from 0.0 to 1.0 by default</param>
  68. /// <param name="duration">number of millisecons to actuate the tactor for</param>
  69. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?actuate66@ArmbandInterface@@QAAXHNH@Z",
  70. CallingConvention = CallingConvention.Cdecl)]
  71. private static extern void Actuate66(int tactor, double intensity, int duration);
  72. /// <summary>
  73. /// starts actuation of the specified tactor (motor) at intensity 1.0 for a specified amount of time
  74. /// </summary>
  75. /// <param name="tactor">integer from 0 to 7 specifying the number of the tactor to actuate</param>
  76. /// <param name="intensity">intensity, ranging from 0.0 to 1.0 by default</param>
  77. /// <param name="duration">number of millisecons to actuate the tactor for</param>
  78. [DllImport(@"../Debug/StaticLibMotors.dll", EntryPoint = "?actuate100@ArmbandInterface@@QAAXHNH@Z",
  79. CallingConvention = CallingConvention.Cdecl)]
  80. private static extern void Actuate100(int tactor, double intensity, int duration);
  81. /// <summary>
  82. /// starts actuation of the specified tactor (motor) at the specified intensity (specified in VIBRATION_MODE) for a specified amount of time
  83. /// </summary>
  84. /// <param name="tactor">integer from 0 to 7 specifying the number of the tactor to actuate</param>
  85. /// <param name="intensity">intensity, ranging from 0.0 to 1.0 by default</param>
  86. /// <param name="duration">number of millisecons to actuate the tactor for</param>
  87. public static void Actuate(int tactor, double intensity, int duration)
  88. {
  89. switch (VIBRATION_MODE)
  90. {
  91. case 0:
  92. break;
  93. case 1:
  94. Actuate33(tactor, intensity, duration);
  95. break;
  96. case 2:
  97. Actuate66(tactor, intensity, duration);
  98. break;
  99. case 3:
  100. Actuate100(tactor, intensity, duration);
  101. break;
  102. default:
  103. Console.WriteLine("Error: invalid value for VIBRATION_MODE constant");
  104. break;
  105. }
  106. }
  107. }
  108. }