Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
2.7 KiB

  1. // -----------------------------------------------------------------------------
  2. // VEML6075 Sensor over I2C
  3. // Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
  4. // -----------------------------------------------------------------------------
  5. #if SENSOR_SUPPORT && VEML6075_SUPPORT
  6. #pragma once
  7. #undef I2C_SUPPORT
  8. #define I2C_SUPPORT 1 // Explicitly request I2C support.
  9. #include "Arduino.h"
  10. #include "I2CSensor.h"
  11. #include "SparkFun_VEML6075_Arduino_Library.h"
  12. class VEML6075Sensor : public I2CSensor {
  13. public:
  14. // ---------------------------------------------------------------------
  15. // Public
  16. // ---------------------------------------------------------------------
  17. VEML6075Sensor(): I2CSensor() {
  18. _count = 3;
  19. _sensor_id = SENSOR_VEML6075_ID;
  20. _veml6075 = new VEML6075();
  21. }
  22. ~VEML6075Sensor() {
  23. delete _veml6075;
  24. }
  25. void begin() {
  26. if (!_veml6075->begin()) {
  27. return;
  28. };
  29. _ready = true;
  30. }
  31. // ---------------------------------------------------------------------
  32. // Sensor API
  33. // ---------------------------------------------------------------------
  34. // Descriptive name of the sensor
  35. String description() {
  36. char buffer[25];
  37. snprintf(buffer, sizeof(buffer), "VEML6075 @ I2C (0x%02X)", _address);
  38. return String(buffer);
  39. }
  40. // Descriptive name of the slot # index
  41. String slot(unsigned char index) {
  42. return description();
  43. };
  44. // Type for slot # index
  45. unsigned char type(unsigned char index) {
  46. if (index == 0) return MAGNITUDE_UVA;
  47. if (index == 1) return MAGNITUDE_UVB;
  48. if (index == 2) return MAGNITUDE_UVI;
  49. return MAGNITUDE_NONE;
  50. }
  51. // Pre-read hook (usually to populate registers with up-to-date data)
  52. void pre() {
  53. _error = SENSOR_ERROR_OK;
  54. }
  55. // Current value for slot # index
  56. double value(unsigned char index) {
  57. if (index == 0) return _veml6075->a();
  58. if (index == 1) return _veml6075->b();
  59. if (index == 2) return _veml6075->index();
  60. return 0;
  61. }
  62. void setIntegrationTime(VEML6075::veml6075_uv_it_t integration_time) {
  63. _veml6075->setIntegrationTime(integration_time);
  64. }
  65. void setDynamicMode(VEML6075::veml6075_hd_t dynamic_mode) {
  66. _veml6075->setHighDynamic(dynamic_mode);
  67. }
  68. protected:
  69. VEML6075 * _veml6075 = NULL;
  70. };
  71. #endif // SENSOR_SUPPORT && VEML6075_SUPPORT