123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #include "sensorsim.h"
- void sensorsim_init(sensorsim_state_t * p_state,
- const sensorsim_cfg_t * p_cfg)
- {
- if (p_cfg->start_at_max)
- {
- p_state->current_val = p_cfg->max;
- p_state->is_increasing = false;
- }
- else
- {
- p_state->current_val = p_cfg->min;
- p_state->is_increasing = true;
- }
- }
- uint32_t sensorsim_measure(sensorsim_state_t * p_state,
- const sensorsim_cfg_t * p_cfg)
- {
- if (p_state->is_increasing)
- {
- sensorsim_increment(p_state, p_cfg);
- }
- else
- {
- sensorsim_decrement(p_state, p_cfg);
- }
- return p_state->current_val;
- }
- void sensorsim_increment(sensorsim_state_t * p_state,
- const sensorsim_cfg_t * p_cfg)
- {
- if (p_cfg->max - p_state->current_val > p_cfg->incr)
- {
- p_state->current_val += p_cfg->incr;
- }
- else
- {
- p_state->current_val = p_cfg->max;
- p_state->is_increasing = false;
- }
- }
- void sensorsim_decrement(sensorsim_state_t * p_state,
- const sensorsim_cfg_t * p_cfg)
- {
- if (p_state->current_val - p_cfg->min > p_cfg->incr)
- {
- p_state->current_val -= p_cfg->incr;
- }
- else
- {
- p_state->current_val = p_cfg->min;
- p_state->is_increasing = true;
- }
- }
|