ArmbandInterface.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "stdafx.h"
  2. extern "C" {
  3. #include "MotorHeader/BodyActuator.h"
  4. }
  5. #include <time.h>
  6. #include <stdio.h>
  7. #include "ArmbandInterface.h"
  8. #include <stdlib.h>
  9. typedef void(__cdecl *InitFunctionType)(BodyActuator*, BodyActuator_Type, char*, int);
  10. typedef void(__cdecl *StopFunctionType)(BodyActuator*, uint8_t);
  11. typedef void(__cdecl *StartFunctionType)(BodyActuator*, uint8_t, float);
  12. typedef void(__cdecl *ActuateFunctionType)(BodyActuator*, uint8_t, float, uint64_t);
  13. typedef void(__cdecl *DeleteFunctionType)(BodyActuator*);
  14. static InitFunctionType initFunctionHandle;
  15. static StartFunctionType startFunctionHandle;
  16. static StopFunctionType stopFunctionHandle;
  17. static ActuateFunctionType actuateFunctionHandle;
  18. static DeleteFunctionType deleteFunctionHandle;
  19. static BodyActuator* armband;
  20. //static char *port =
  21. static HINSTANCE lib;
  22. extern "C" {
  23. DllExport int __cdecl ArmbandInterface::setupArmband() {
  24. lib = LoadLibrary(TEXT("BodyActuator.dll"));
  25. if (lib == NULL) {
  26. printf("ERROR: library could not be loaded");
  27. return 0;
  28. }
  29. initFunctionHandle = (InitFunctionType)GetProcAddress(lib, "BodyActuator_init");
  30. if (initFunctionHandle == NULL) {
  31. printf("ERROR: init function could not be retrieved");
  32. return 1;
  33. }
  34. startFunctionHandle = (StartFunctionType)GetProcAddress(lib, "BodyActuator_startActuation");
  35. if (startFunctionHandle == NULL) {
  36. printf("ERROR: start function could not be retrieved");
  37. return 2;
  38. }
  39. stopFunctionHandle = (StopFunctionType)GetProcAddress(lib, "BodyActuator_stopActuation");
  40. if (stopFunctionHandle == NULL) {
  41. printf("ERROR: stop function could not be retrieved");
  42. return 3;
  43. }
  44. actuateFunctionHandle = (ActuateFunctionType)GetProcAddress(lib, "BodyActuator_actuate");
  45. if (actuateFunctionHandle == NULL) {
  46. printf("ERROR: actuate function could not be retrieved");
  47. return 4;
  48. }
  49. deleteFunctionHandle = (DeleteFunctionType)GetProcAddress(lib, "BodyActuator_delete");
  50. if (deleteFunctionHandle == NULL) {
  51. printf("ERROR: delete function could not be retrieved");
  52. return 5;
  53. }
  54. //strcpy(port, "COM5");
  55. setupMotors();
  56. //actuate100(0, 1.0, 20);
  57. //startVibrate(0, 1.0);
  58. return -1;
  59. }
  60. DllExport void __cdecl ArmbandInterface::startVibrate(int tactor, float intensity) {
  61. (startFunctionHandle)(armband, 0, 1.0);
  62. printf("sollte gehen");
  63. }
  64. DllExport void __cdecl ArmbandInterface::stopVibrate(int tactor) {
  65. (stopFunctionHandle)(armband, (uint8_t)tactor);
  66. }
  67. DllExport void __cdecl ArmbandInterface::actuate100() {
  68. (actuateFunctionHandle)(armband, 0, 1.0, 20);
  69. }
  70. DllExport void __cdecl ArmbandInterface::actuate66() {
  71. (actuateFunctionHandle)(armband, 0, 0.66, 20);
  72. }
  73. DllExport void __cdecl ArmbandInterface::actuate33() {
  74. (actuateFunctionHandle)(armband, 0, 0.33, 20);
  75. }
  76. DllExport void __cdecl ArmbandInterface::deleteArmband() {
  77. (deleteFunctionHandle)(armband);
  78. printf("armband deleted");
  79. }
  80. }
  81. void ArmbandInterface::setupMotors() {
  82. char* port = (char*) "COM5";//malloc(7);
  83. armband = (BodyActuator*) malloc(sizeof(BodyActuator*));
  84. //strcpy_s(port, "COM5");
  85. (initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
  86. printf("armband initialized");
  87. }
  88. /*void ArmbandInterface::deleteArmband() {
  89. (deleteFunctionHandle)(armband);
  90. }*/
  91. /*void ArmbandInterface::actuate(int tactor, double intensity, int duration) {
  92. (actuateFunctionHandle)(armband, tactor, intensity, duration);
  93. }*/