ArmbandInterface.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "stdafx.h"
  2. extern "C" {
  3. #include "MotorHeader/BodyActuator.h"
  4. }
  5. #include <ctime>
  6. #include <stdio.h>
  7. namespace StaticLib1
  8. {
  9. class UnitTest1
  10. {
  11. BodyActuator* armband;
  12. char *port = new char[5] {'C', 'O', 'M', '5', '\0'};
  13. HINSTANCE lib;
  14. typedef void (__cdecl *InitFunctionType)(BodyActuator*, BodyActuator_Type, char*, int);
  15. InitFunctionType initFunctionHandle;
  16. typedef void(__cdecl *StartFunctionType)(BodyActuator*, uint8_t, float);
  17. StartFunctionType startFunctionHandle;
  18. typedef void(__cdecl *StopFunctionType)(BodyActuator*, uint8_t);
  19. StopFunctionType stopFunctionHandle;
  20. public :
  21. int main() {
  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. //strcpy(port, "COM5");
  43. setupMotors();
  44. startVibrate(0, 1.0);
  45. }
  46. void setupMotors() {
  47. (initFunctionHandle) (armband, BODYACTUATOR_TYPE_EAI, port, 8);
  48. printf("armband initialized");
  49. }
  50. void startVibrate(uint8_t tactor, float intensity) {
  51. (startFunctionHandle) (armband, tactor, intensity);
  52. }
  53. void stopVibration(uint8_t tactor) {
  54. (stopFunctionHandle) (armband, tactor);
  55. }
  56. };
  57. }