// Lua: setsmoothing( id, length ) static int adc_setsmoothing( lua_State *L ) { unsigned id, length, res; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( adc, id ); length = luaL_checkinteger( L, 2 ); if ( !( length & ( length - 1 ) ) ) { res = platform_adc_set_smoothing( id, length ); if ( res == PLATFORM_ERR ) return luaL_error( L, "Buffer allocation failed." ); else return 0; } else return luaL_error( L, "length must be power of 2" ); }
// PicoC: adc_setsmoothing(id, length); static void adc_setsmoothing(pstate *p, val *r, val **param, int n) { unsigned id, length, res; id = param[0]->Val->UnsignedInteger; MOD_CHECK_ID(adc, id); length = param[1]->Val->UnsignedInteger; if (!(length & (length - 1))) { res = platform_adc_set_smoothing(id, length); if (res == PLATFORM_ERR) { return pmod_error("Buffer allocation failed."); } else { r->Val->UnsignedInteger = res; return; } } else { return pmod_error("Length must be power of 2"); } }
// (adc-setsmoothing 'num 'num) -> num any plisp_adc_setsmoothing(any ex) { unsigned id, length, res; any x, y; x = cdr(ex); NeedNum(ex, y = EVAL(car(x))); id = unBox(y); // get id. MOD_CHECK_ID(ex, adc, id); x = cdr(x); NeedNum(ex, y = EVAL(car(x))); length = unBox(y); // get length. if (!(length & (length - 1))) { res = platform_adc_set_smoothing(id, length); if (res == PLATFORM_ERR) err(ex, NULL, "Buffer allocation failed."); else return box(res); } else { err(ex, y, "Length must be power of 2"); } }