ArmbandInterface.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include "stdafx.h"
  2. extern "C" {
  3. #include "MotorHeader/BodyActuator.h"
  4. }
  5. #include <ctime>
  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, double, uint64_t);
  13. static InitFunctionType initFunctionHandle;
  14. static StartFunctionType startFunctionHandle;
  15. static StopFunctionType stopFunctionHandle;
  16. static ActuateFunctionType actuateFunctionHandle;
  17. static BodyActuator* armband;
  18. //static char *port =
  19. static HINSTANCE lib;
  20. extern "C" {
  21. DllExport int __cdecl ArmbandInterface::setupArmband() {
  22. lib = LoadLibrary(TEXT("BodyActuator.dll"));
  23. if (lib == NULL) {
  24. printf("ERROR: library could not be loaded");
  25. return 0;
  26. }
  27. initFunctionHandle = (InitFunctionType)GetProcAddress(lib, "BodyActuator_init");
  28. if (initFunctionHandle == NULL) {
  29. printf("ERROR: init function could not be retrieved");
  30. return 1;
  31. }
  32. startFunctionHandle = (StartFunctionType)GetProcAddress(lib, "BodyActuator_startActuation");
  33. if (startFunctionHandle == NULL) {
  34. printf("ERROR: start function could not be retrieved");
  35. return 2;
  36. }
  37. stopFunctionHandle = (StopFunctionType)GetProcAddress(lib, "BodyActuator_stopActuation");
  38. if (stopFunctionHandle == NULL) {
  39. printf("ERROR: stop function could not be retrieved");
  40. return 3;
  41. }
  42. actuateFunctionHandle = (ActuateFunctionType)GetProcAddress(lib, "BodyActuator_actuate");
  43. if (actuateFunctionHandle == NULL) {
  44. printf("ERROR: actuate function could not be retrieved");
  45. return 4;
  46. }
  47. //strcpy(port, "COM5");
  48. setupMotors();
  49. //startVibrate(0, 1.0);
  50. return -1;
  51. }
  52. DllExport void __cdecl ArmbandInterface::startVibrate(int tactor, float intensity) {
  53. (startFunctionHandle)(armband, (uint8_t)tactor, intensity);
  54. }
  55. DllExport void __cdecl ArmbandInterface::stopVibrate(int tactor) {
  56. (stopFunctionHandle)(armband, (uint8_t)tactor);
  57. }
  58. DllExport void __cdecl ArmbandInterface::actuate(int tactor, double intensity, int duration) {
  59. (actuateFunctionHandle)(armband, (uint8_t)tactor, intensity, (uint64_t)duration);
  60. }
  61. }
  62. void ArmbandInterface::setupMotors() {
  63. char* port = (char*) "COM5";//malloc(7);
  64. armband = (BodyActuator*) malloc(sizeof(BodyActuator*));
  65. //strcpy_s(port, "COM5");
  66. (initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
  67. printf("armband initialized");
  68. }