TouchSliderState.cpp 842 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "TouchSliderState.h"
  2. namespace TLAC::Components
  3. {
  4. void TouchSliderState::SetSensor(int index, int value, SliderSensorSetMode mode)
  5. {
  6. if (index < 0 || index >= SLIDER_SENSORS)
  7. return;
  8. if (mode == SENSOR_SET_MODE_RAW)
  9. {
  10. if (SerialState == nullptr)
  11. return;
  12. uint32_t* ph = SerialState->sliderSerialResponse.sensors[index].pressureHistory;
  13. ph[3] = ph[2];
  14. ph[2] = ph[1];
  15. ph[1] = ph[0];
  16. ph[0] = value;
  17. SerialState->sliderSerialResponse.scanMode = 1;
  18. SerialState->sliderSerialResponse.scanCount = 1;
  19. SerialState->sliderResponseCnt = 1;
  20. }
  21. else
  22. {
  23. SensorPressureLevels[index] = value;
  24. SensorTouched[index].IsTouched = value > 0;
  25. }
  26. }
  27. void TouchSliderState::ResetSensors(SliderSensorSetMode mode)
  28. {
  29. for (int i = 0; i < SLIDER_SENSORS; i++)
  30. SetSensor(i, NO_PRESSURE, mode);
  31. }
  32. }