unleashed-firmware/applications/plugins/totp/services/roll_value/roll_value.c
2022-11-10 08:32:21 +03:00

28 lines
No EOL
1.5 KiB
C

#include "roll_value.h"
#define TOTP_ROLL_VALUE_FN(type, step_type) \
TOTP_ROLL_VALUE_FN_HEADER(type, step_type) { \
type v = *value; \
if(step > 0 && v > max - step) { \
if(overflow_behavior == RollOverflowBehaviorRoll) { \
v = min; \
} else if(overflow_behavior == RollOverflowBehaviorStop) { \
v = max; \
} \
} else if(step < 0 && v < min - step) { \
if(overflow_behavior == RollOverflowBehaviorRoll) { \
v = max; \
} else if(overflow_behavior == RollOverflowBehaviorStop) { \
v = min; \
} \
} else { \
v += step; \
} \
*value = v; \
}
TOTP_ROLL_VALUE_FN(int8_t, int8_t)
TOTP_ROLL_VALUE_FN(uint8_t, int8_t)
TOTP_ROLL_VALUE_FN(uint16_t, int16_t);