aboutsummaryrefslogtreecommitdiff
path: root/Mussel/Mussel.h
blob: ba063c2cd9a5302e7fd9a74221a70d22fcfb1079 (plain)
  1. // SPDX-FileCopyrightText: 2025 Amal Mazrah <mazrah@ruc.dk>
  2. // SPDX-FileCopyrightText: 2025 Jonas Smedegaard <dr@jones.dk>
  3. // SPDX-FileCopyrightText: 2025 Mennatullah Hatim Kassim <stud-mennatulla@ruc.dk>
  4. // SPDX-FileCopyrightText: 2025 Noor Ahmad <noora@ruc.dk>
  5. // SPDX-FileCopyrightText: 2025 Tanishka Suwalka <tanishkas@ruc.dk>
  6. // SPDX-License-Identifier: GPL-3.0-or-later
  7. /// Mussel - a small library for Arduino to emulate a mussel biosensor
  8. ///
  9. /// @version 0.0.2
  10. /// @see <https://app.radicle.xyz/nodes/seed.radicle.garden/rad:z2tFBF4gN7ziG9oXtUytVQNYe3VhQ/tree/Mussel/README.md>
  11. /// @see <https://moodle.ruc.dk/course/view.php?id=23504>
  12. #ifndef Mussel_h
  13. #define Mussel_h
  14. #include "Arduino.h"
  15. // seconds
  16. #define MUSSEL_NORMAL_PACE 50U
  17. #define MUSSEL_STRESS_PACE 10U
  18. #define MUSSEL_VOTE_TIME_AHEAD 60000U // 1 minute
  19. #define MUSSEL_VOTE_TIME_BEHIND 120000U // 2 minutes
  20. // milliseconds
  21. #define MUSSEL_DEBOUNCE_DELAY 50U
  22. // Limited size NOW!! can be transformed into infinite array
  23. #define STACK_SIZE 1000
  24. struct Vote {
  25. String id;
  26. unsigned long timestamp;
  27. int measure;
  28. };
  29. class Mussel {
  30. public:
  31. // Default constructor
  32. Mussel(const int attitude);
  33. // Constructor for attitudes using an input pin
  34. Mussel(const int attitude, const uint8_t pin);
  35. // Constructor for attitudes using an input pin and a sensor type
  36. Mussel(
  37. const int attitude,
  38. const uint8_t pin,
  39. const uint8_t type);
  40. void begin();
  41. String desc();
  42. int read();
  43. String debug();
  44. bool push(String id, unsigned long timestamp, int measure);
  45. void printStack();
  46. bool qualifyVote(Vote vote, unsigned long currentTime);
  47. private:
  48. int _attitude;
  49. int _pin;
  50. bool _boolState;
  51. byte _count;
  52. unsigned long _time;
  53. #ifdef DHT_H
  54. DHT mussel_dht;
  55. #endif
  56. // Array to store ID strings
  57. String idStack[STACK_SIZE];
  58. unsigned long timeStack[STACK_SIZE];
  59. int measureStack[STACK_SIZE];
  60. // Index of the top element in the stack, -1 means stack is empty
  61. int top = -1;
  62. };
  63. #endif