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.

weight_controller.cpp 852B

пре 3 месеци
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "weight_controller.h"
  2. void WeightController::init(String name, double min, double max) {
  3. this->name = name;
  4. this->val_min = min;
  5. this->val_max = max;
  6. }
  7. int WeightController::compare(double weight) const {
  8. if (val_min > weight) {
  9. return -1;
  10. }
  11. else if (val_max < weight) {
  12. return 1;
  13. }
  14. return 0;
  15. }
  16. void WeightControllerPool::next() {
  17. if (current == 0) {
  18. controller_displayed = true;
  19. }
  20. current++;
  21. if (current - 1 >= max) {
  22. controller_displayed = false;
  23. current = 0;
  24. }
  25. }
  26. WeightController& WeightControllerPool::get() {
  27. return items[current - 1];
  28. }
  29. WeightController& WeightControllerPool::get(int index) {
  30. if (index < 0) {
  31. return items[0];
  32. }
  33. else if (index > max) {
  34. return items[max];
  35. }
  36. return items[index];
  37. }