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.

77 lines
1.7KB

  1. #include "CV.hpp"
  2. namespace SynthDevKit {
  3. CV::CV (float threshold) {
  4. this->threshold = threshold;
  5. this->reset();
  6. }
  7. bool CV::newTrigger ( ) {
  8. // check to see if this is a status change, if so reset the states and return true
  9. if (this->triggered == true && this->lastTriggered == false) {
  10. this->lastTriggered = true;
  11. return true;
  12. }
  13. this->lastTriggered = this->triggered;
  14. return false;
  15. }
  16. void CV::update (float current) {
  17. // set the last value to whatever the current value is
  18. this->lastValue = current;
  19. // increase the trigger interval count
  20. this->triggerIntervalCount++;
  21. // check the threshold, if it meets or is greater, then we make a change
  22. if (current >= this->threshold) {
  23. if (this->triggered == false) {
  24. this->triggered = true;
  25. // increment the total number of triggers fired
  26. this->triggerCount++;
  27. // set the last trigger interval to the interval
  28. this->lastTriggerInterval = this->triggerIntervalCount;
  29. // reset the count to 0
  30. this->triggerIntervalCount = 0;
  31. }
  32. } else {
  33. this->triggered = false;
  34. }
  35. }
  36. bool CV::isHigh ( ) {
  37. return this->triggered;
  38. }
  39. bool CV::isLow ( ) {
  40. return !this->triggered;
  41. }
  42. void CV::reset ( ) {
  43. this->triggered = false;
  44. this->lastTriggered = false;
  45. this->lastValue = 0;
  46. this->triggerCount = 0;
  47. this->triggerIntervalCount = 0;
  48. this->lastTriggerInterval = 0;
  49. }
  50. float CV::currentValue ( ) {
  51. return this->lastValue;
  52. }
  53. uint32_t CV::triggerInterval ( ) {
  54. return this->lastTriggerInterval;
  55. }
  56. uint32_t CV::triggerTotal ( ) {
  57. return this->triggerCount;
  58. }
  59. }