ArmbandInterface.cpp 2.0 KB

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