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.

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