Allow turning off softwd again as documented (#3327)

* Allow turning off softwd again as documented

* fix luacheck warnings

* fix outcome of review
This commit is contained in:
Gregor Hartmann 2020-11-13 12:11:29 +01:00 committed by GitHub
parent d279ba2fd9
commit 02dcc235c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 184 additions and 178 deletions

View File

@ -257,9 +257,9 @@ inline static uint64_t rtc_timer_update(bool do_calibration){
void rtc_callback(void *arg){
rtc_timer_update(true);
if(soft_watchdog > 0){
if(soft_watchdog >= 0){
soft_watchdog--;
if(soft_watchdog == 0)
if(soft_watchdog < 0)
system_restart();
}
}
@ -273,9 +273,8 @@ static int tmr_time( lua_State* L ){
// Lua: tmr.softwd( value )
static int tmr_softwd( lua_State* L ){
int t = luaL_checkinteger(L, 1);
luaL_argcheck(L, t>0 , 2, "invalid time");
soft_watchdog = t;
soft_watchdog = luaL_checkinteger(L, 1);
// NO check is required as negative Values mean that the timer is disabled.
return 0;
}

View File

@ -89,3 +89,10 @@ N.testco('AUTO alarm coroutine', function(getCB, waitCB)
ok(true, "coroutine end")
end)
N.test('softwd set positive and negative values', function()
tmr.softwd(22)
tmr.softwd(0)
tmr.softwd(-1) -- disable it again
tmr.softwd(-22) -- disable it again
end)