ArduinoHub.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * ArduinoHub.h
  3. *
  4. * Copyright (C)
  5. * Honda Research Institute Europe GmbH
  6. * Carl-Legien-Str. 30
  7. * 63073 Offenbach/Main
  8. * Germany
  9. *
  10. * UNPUBLISHED PROPRIETARY MATERIAL.
  11. * ALL RIGHTS RESERVED.
  12. *
  13. */
  14. #pragma once
  15. #include <pthread.h>
  16. #include <stdbool.h>
  17. #include <stdint.h>
  18. #include <ctime>
  19. //#include <windows.h>
  20. #include "Serial.h"
  21. #include "Actuator.h"
  22. typedef enum
  23. {
  24. ARDUINOHUB_TYPE_PIEZO = 'P',
  25. ARDUINOHUB_TYPE_ERM = 'E',
  26. ARDUINOHUB_TYPE_EMS = 'M'
  27. } ArduinoHub_Type;
  28. typedef struct ArduinoHub
  29. {
  30. bool valid;
  31. pthread_mutex_t mutex;
  32. pthread_t thread;
  33. ArduinoHub_Type arduinoType;
  34. Serial* serial;
  35. Actuator* actuators;
  36. } ArduinoHub;
  37. ArduinoHub* ArduinoHub_new();
  38. void ArduinoHub_init(ArduinoHub* self, char* port, ArduinoHub_Type type);
  39. void ArduinoHub_clear(ArduinoHub* self);
  40. void ArduinoHub_delete(ArduinoHub* self);
  41. /**
  42. * Starts vibration for a specified duration. The command is non-blocking.
  43. * @intensity:
  44. * Intensity covering the whole spectrum of the actuator if no range is set.
  45. * An intensity range can be set with ArduinoHub_setIntensityRange().
  46. * @duration:
  47. * Duration of the vibration in milliseconds.
  48. */
  49. void ArduinoHub_vibrate(ArduinoHub* self, uint8_t tactor, float intensity, uint64_t duration);
  50. /**
  51. * Starts continuous vibration. The command is non-blocking.
  52. * @intensity:
  53. * Intensity covering the whole spectrum of the actuator if no range is set.
  54. * An intensity range can be set with ArduinoActuator_setIntensityRange().
  55. */
  56. void ArduinoHub_startVibration(ArduinoHub* self, uint8_t tactor, float intensity);
  57. /**
  58. * Stops continuous vibration.
  59. */
  60. void ArduinoHub_stopVibration(ArduinoHub* self, uint8_t tactor);
  61. /**
  62. * Sets the frequency of the vibration of all piezo actuators.
  63. * No effect for ERM and EMS.
  64. */
  65. void ArduinoHub_setFrequency(ArduinoHub* self, uint8_t tactor, uint16_t frequency);
  66. /**
  67. * Set the intensity range. The default range is the actuators whole intensity [0, 1].
  68. * Modifying this setting cuts-out intensity values under min and above max.
  69. * E.g., for the range [0.2, 1.0] the intensity 0.5 maps to a device intensity of 0.6.
  70. */
  71. void ArduinoHub_setIntensityRange(ArduinoHub* self, uint8_t tactor, float minIntensity, float maxIntensity);