示例#1
0
static int lpwmled_setcolor_abs_i(u32 r,u32 g,u32 b)
{
  platform_pwm_set_duty( led.pwmidr,CLIP(r,0,NORMAL_PWM_DEPTH) );
  platform_pwm_set_duty( led.pwmidg,CLIP(g,0,NORMAL_PWM_DEPTH) );
  platform_pwm_set_duty( led.pwmidb,CLIP(b,0,NORMAL_PWM_DEPTH) );
  return 1;
}
示例#2
0
// Lua: realduty = setduty( id, duty )
static int ICACHE_FLASH_ATTR lpwm_setduty( lua_State* L )
{
  unsigned id;
  s32 duty;  // signed to error-check for negative values
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( pwm, id );
  duty = luaL_checkinteger( L, 2 );
  if ( duty > NORMAL_PWM_DEPTH )
    return luaL_error( L, "wrong arg range" );
  duty = platform_pwm_set_duty( id, (u32)duty );
  lua_pushinteger( L, duty );
  return 1;
}
示例#3
0
文件: pwm.c 项目: whitecatboard/LuaOS
static int lpwm_setduty(lua_State* L) {
    int id = luaL_checkinteger(L, 1); 
    double duty = luaL_checknumber(L, 2); 

    if (!platform_pwm_exists(L, id)) {
        return luaL_error(L, "pwm%d does not exist", id);
    }
    
    if (pwm[id - 1].mode != 0) {
        return luaL_error(L, "pwm%d isn't setup in DEFAULT mode, function not allowed", id);
    }

    if (!pwm[id - 1].configured) {
        return luaL_error(L, "pwm%d is not setup", id);
    }

    if (!pwm[id - 1].started) {
        return luaL_error(L, "pwm%d is not started", id);
    }

    platform_pwm_set_duty(L, id, duty);
    
    return 0;
}