schmidt_trigger.c 536 B

12345678910111213141516171819202122232425262728293031
  1. #include "schmidt_trigger.h"
  2. int schmidt_init(struct schmidt *schmidt, float low, float high)
  3. {
  4. if (low > high)
  5. return -1;
  6. schmidt->high = high;
  7. schmidt->low = low;
  8. schmidt->value = 0;
  9. return 0;
  10. }
  11. int schmidt_trig(struct schmidt *schmidt, float level)
  12. {
  13. if ((schmidt->value == 1 && level <= schmidt->low) ||
  14. (schmidt->value == 0 && level >= schmidt->high)) {
  15. schmidt->value ^= 1;
  16. return 1;
  17. }
  18. return 0;
  19. }
  20. int schmidt_get(struct schmidt *schmidt)
  21. {
  22. return schmidt->value;
  23. }
  24. /* vim: set ts=8 sw=8 sts=8 noet: */