mirror of
https://github.com/elua/elua.git
synced 2025-01-25 01:02:54 +08:00
ADC: Some checking and consistency adjustments.
This commit is contained in:
parent
bd2e819368
commit
300ba00a55
@ -24,7 +24,7 @@ elua_adc_dev_state *adc_get_dev_state( unsigned dev_id )
|
||||
return &adc_dev_state;
|
||||
}
|
||||
|
||||
// Rewrite
|
||||
// Rewrite revice sequence
|
||||
void adc_update_dev_sequence( unsigned dev_id )
|
||||
{
|
||||
elua_adc_dev_state *d = adc_get_dev_state( dev_id );
|
||||
|
@ -193,7 +193,7 @@ static int adc_getsamples( lua_State* L )
|
||||
static int adc_insertsamples( lua_State* L )
|
||||
{
|
||||
unsigned id, i, startidx;
|
||||
u16 bcnt, count;
|
||||
u16 bcnt, count, zcount;
|
||||
|
||||
id = luaL_checkinteger( L, 1 );
|
||||
MOD_CHECK_ID( adc, id );
|
||||
@ -201,16 +201,22 @@ static int adc_insertsamples( lua_State* L )
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
|
||||
startidx = luaL_checkinteger( L, 3 );
|
||||
if ( startidx <= 0 )
|
||||
return luaL_error( L, "idx must be > 0" );
|
||||
|
||||
count = luaL_checkinteger(L, 4 );
|
||||
if ( count == 0 )
|
||||
return luaL_error( L, "count must be > 0" );
|
||||
|
||||
bcnt = adc_wait_samples( id, count );
|
||||
|
||||
if ( count > bcnt )
|
||||
count = bcnt;
|
||||
|
||||
for( i = startidx; i < ( count + startidx ); i ++ )
|
||||
{
|
||||
lua_pushinteger( L, adc_get_processed_sample( id ) );
|
||||
if ( i < bcnt + startidx )
|
||||
lua_pushinteger( L, adc_get_processed_sample( id ) );
|
||||
else
|
||||
lua_pushnil( L ); // nil-out values where we don't have enough samples
|
||||
|
||||
lua_rawseti( L, 2, i );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user