ArmbandInterface.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. extern "C" {
  9. __declspec(dllexport) int __cdecl ArmbandInterface::setupArmband() {
  10. lib = LoadLibrary(TEXT("BodyActuator.dll"));
  11. if (lib == NULL) {
  12. printf("ERROR: library could not be loaded");
  13. return 0;
  14. }
  15. initFunctionHandle = (InitFunctionType)GetProcAddress(lib, "BodyActuator_init");
  16. if (initFunctionHandle == NULL) {
  17. printf("ERROR: init function could not be retrieved");
  18. return 1;
  19. }
  20. startFunctionHandle = (StartFunctionType)GetProcAddress(lib, "BodyActuator_startActuation");
  21. if (startFunctionHandle == NULL) {
  22. printf("ERROR: start function could not be retrieved");
  23. return 2;
  24. }
  25. stopFunctionHandle = (StopFunctionType)GetProcAddress(lib, "BodyActuator_stopActuation");
  26. if (stopFunctionHandle == NULL) {
  27. printf("ERROR: stop function could not be retrieved");
  28. return 3;
  29. }
  30. //strcpy(port, "COM5");
  31. setupMotors();
  32. startVibrate(0, 1.0);
  33. return -1;
  34. }
  35. __declspec(dllexport) void __cdecl ArmbandInterface::startVibrate(int tactor, float intensity) {
  36. (startFunctionHandle)(armband, (uint8_t)tactor, intensity);
  37. }
  38. __declspec(dllexport) void __cdecl ArmbandInterface::stopVibrate(int tactor) {
  39. (stopFunctionHandle)(armband, (uint8_t)tactor);
  40. }
  41. }
  42. void ArmbandInterface::setupMotors() {
  43. (initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, new char[5]{ 'C', 'O', 'M', '5', '\0' }, 8);
  44. printf("armband initialized");
  45. }