mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2024-12-22 12:51:39 +03:00
28 lines
1.5 KiB
C
28 lines
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); |