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.

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