当前位置: 首页>>代码示例>>C++>>正文


C++ MOD_CHECK_ID函数代码示例

本文整理汇总了C++中MOD_CHECK_ID函数的典型用法代码示例。如果您正苦于以下问题:C++ MOD_CHECK_ID函数的具体用法?C++ MOD_CHECK_ID怎么用?C++ MOD_CHECK_ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了MOD_CHECK_ID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: plisp_adc_setclock

// (adc-setclock 'num 'num 'num) -> num
any plisp_adc_setclock(any ex) {
  s32 sfreq; // signed version for negative checking.
  u32 freq;
  unsigned id, timer_id = 0;
  any x, y;

  x = cdr(ex);
  NeedNum(ex, y = EVAL(car(x)));
  id = unBox(y); // get adc id.
  MOD_CHECK_ID(ex, adc, id);

  x = cdr(x);
  NeedNum(ex, y = EVAL(car(x)));
  sfreq = unBox(y); // get frequency.
  if (sfreq < 0)
    err(ex, y, "frequency must be 0 or positive");

  freq = (u32) sfreq;
  if (freq > 0) {
    x = cdr(x);
    NeedNum(ex, y = EVAL(car(x)));
    timer_id = unBox(y); // get timer id.
    MOD_CHECK_ID(ex, timer, timer_id);
    MOD_CHECK_RES_ID(ex, adc, id, timer, timer_id);
  }

  platform_adc_set_timer(id, timer_id);
  freq = platform_adc_set_clock(id, freq);
  return box(freq);
}
开发者ID:simplemachines-italy,项目名称:Alcor6L,代码行数:31,代码来源:adc.c

示例2: transport_open_connection

// Open Connection / Client
int transport_open_connection(lua_State *L, Handle *handle)
{
	// Get args & Set up connection
	unsigned uart_id, tmr_id;

	check_num_args( L,3 ); // 1st arg is uart num, 2nd arg is tmr_id, 3nd is handle
	if ( !lua_isnumber( L, 1 ) )
		return luaL_error( L, "1st arg must be uart num" );

	if ( !lua_isnumber( L, 2 ) )
		return luaL_error( L, "2nd arg must be timer num" );

	uart_id = lua_tonumber( L, 1 );
	MOD_CHECK_ID( uart, uart_id );

	tmr_id = lua_tonumber( L, 1 );
	MOD_CHECK_ID( timer, tmr_id );

	adispatch_buff = -1;

	handle->tpt.fd = ( int )uart_id;
	handle->tpt.tmr_id = tmr_id;

	// Setup uart
	platform_uart_setup( (unsigned int) uart_id, 115200, 8, PLATFORM_UART_PARITY_NONE, PLATFORM_UART_STOPBITS_1 );

	return 1;
}
开发者ID:Amalinda,项目名称:ruuvitracker_fw,代码行数:29,代码来源:luarpc_elua_uart.c

示例3: apa102_write

// Lua: apa102.write(data_pin, clock_pin, "string")
// Byte quads in the string are interpreted as (brightness, B, G, R) values.
// Only the first 5 bits of the brightness value is actually used (0-31).
// This function does not corrupt your buffer.
//
// apa102.write(1, 3, string.char(31, 0, 255, 0)) uses GPIO5 for DATA and GPIO0 for CLOCK and sets the first LED green, with the brightness 31 (out of 0-32)
// apa102.write(5, 6, string.char(255, 0, 0, 255):rep(10)) uses GPIO14 for DATA and GPIO12 for CLOCK and sets ten LED to red, with the brightness 31 (out of 0-32).
//                                                         Brightness values are clamped to 0-31.
static int apa102_write(lua_State* L) {
  uint8_t data_pin = luaL_checkinteger(L, 1);
  MOD_CHECK_ID(gpio, data_pin);
  uint32_t alt_data_pin = pin_num[data_pin];

  uint8_t clock_pin = luaL_checkinteger(L, 2);
  MOD_CHECK_ID(gpio, clock_pin);
  uint32_t alt_clock_pin = pin_num[clock_pin];

  size_t buf_len;
  const char *buf = luaL_checklstring(L, 3, &buf_len);
  uint32_t nbr_frames = buf_len / 4;

  if (nbr_frames > 100000) {
    return luaL_error(L, "The supplied buffer is too long, and might cause the callback watchdog to bark.");
  }

  // Initialize the output pins
  platform_gpio_mode(data_pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);
  GPIO_OUTPUT_SET(alt_data_pin, PLATFORM_GPIO_HIGH); // Set pin high
  platform_gpio_mode(clock_pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);
  GPIO_OUTPUT_SET(alt_clock_pin, PLATFORM_GPIO_LOW); // Set pin low

  // Send the buffers
  apa102_send_buffer(alt_data_pin, alt_clock_pin, (uint32_t *) buf, (uint32_t) nbr_frames);
  return 0;
}
开发者ID:Alvaro99CL,项目名称:nodemcu-firmware,代码行数:35,代码来源:apa102.c

示例4: hx711_init

/*Lua: hx711.init(clk_pin,data_pin)*/
static int hx711_init(lua_State* L) {
  clk_pin = luaL_checkinteger(L,1);
  data_pin = luaL_checkinteger(L,2);
  MOD_CHECK_ID( gpio, clk_pin );
  MOD_CHECK_ID( gpio, data_pin );

  platform_gpio_mode(clk_pin, PLATFORM_GPIO_OUTPUT, PLATFORM_GPIO_FLOAT);
  platform_gpio_mode(data_pin, PLATFORM_GPIO_INPUT, PLATFORM_GPIO_FLOAT);
  platform_gpio_write(clk_pin,1);//put chip to sleep.
  return 0;
}
开发者ID:jiangxilong,项目名称:nodemcu-firmware,代码行数:12,代码来源:hx711.c

示例5: adc_insertsamples

// PicoC: adc_insertsamples(id, arr, idx, count);
// Function parameters:
// 1. id - ADC channel ID.
// 2. arr - array to write samples to. Values at arr[idx]
//    to arr[idx + count -1] will be overwritten with samples
//    (or 0 if not enough samples are available).
// 3. idx - first index to use in the array for writing
//    samples.
// 4. count - number of samples to return. If not enough
//    samples are available (after blocking, if enabled)
//    remaining values will be 0;
static void adc_insertsamples(pstate *p, val *r, val **param, int n)
{
  unsigned id, i, startidx;
  int *arr;
  u16 bcnt, count;

  id = param[0]->Val->UnsignedInteger;
  MOD_CHECK_ID(adc, id);

  arr = param[1]->Val->Pointer;

  startidx = param[2]->Val->UnsignedInteger;
  if (startidx < 0)
     return pmod_error("idx must be >= 0");

  count = param[3]->Val->UnsignedInteger;
  if (count == 0)
    return pmod_error("count must be > 0");
  
  bcnt = adc_wait_samples(id, count);

  for (i = startidx; i < (count + startidx); i++) {
    if (i < bcnt + startidx)
      arr[i] = adc_get_processed_sample(id);
    else
      // zero-out values where we don't have enough samples
      arr[i] = 0;
  }
}
开发者ID:simplemachines-italy,项目名称:Alcor6L,代码行数:40,代码来源:adc.c

示例6: uart_write

// Lua: write( id, string1, [string2], ..., [stringn] )
static int uart_write( lua_State* L )
{
  int id;
  const char* buf;
  size_t len, i;
  int total = lua_gettop( L ), s;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  for( s = 2; s <= total; s ++ )
  {
    if( lua_type( L, s ) == LUA_TNUMBER )
    {
      len = lua_tointeger( L, s );
      if( ( len < 0 ) || ( len > 255 ) )
        return luaL_error( L, "invalid number" );
      platform_uart_send( id, ( u8 )len );
    }
    else
    {
      luaL_checktype( L, s, LUA_TSTRING );
      buf = lua_tolstring( L, s, &len );
      for( i = 0; i < len; i ++ )
        platform_uart_send( id, buf[ i ] );
    }
  }
  return 0;
}
开发者ID:AlbertFERNANDES,项目名称:elua,代码行数:29,代码来源:uart.c

示例7: checkid

static int checkid(lua_State* L,unsigned *ret,char var){
	*ret = luaL_checkinteger( L, var );
	if(*ret==0)
		return luaL_error( L, "no pwm for D0" );
	MOD_CHECK_ID( pwm, *ret );
	return 1;
}
开发者ID:complynx,项目名称:nodemcu-IoT,代码行数:7,代码来源:pwmled.c

示例8: adc_insertsamples

// Lua: insertsamples(id, table, idx, count)
static int adc_insertsamples( lua_State* L )
{
  unsigned id, i, startidx;
  u16 bcnt, count;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( adc, id );
  
  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 );
  
  for( i = startidx; i < ( count + startidx ); i ++ )
  {
    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 );
  }
  
  return 0;
}
开发者ID:ARMinARM,项目名称:elua,代码行数:33,代码来源:adc.c

示例9: ow_reset

// Lua: r = ow.reset( id )
static int ow_reset( lua_State *L )
{
  unsigned id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( ow, id );
  lua_pushinteger( L, onewire_reset(id) );
  return 1;
}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:8,代码来源:ow.c

示例10: ltmr_stop

//tmr.stop(id)
//id:1~16
static int ltmr_stop( lua_State* L )
{
  unsigned id = luaL_checkinteger( L, 1 ) - 1;
  MOD_CHECK_ID( tmr, id+1 );
  mico_stop_timer(&_timer[id]);
  return 0;
}
开发者ID:rongfengyu,项目名称:WiFiMCU,代码行数:9,代码来源:tmr.c

示例11: tmr_alarm

// Lua: alarm( id, interval, repeat, function )
static int tmr_alarm( lua_State* L )
{
  s32 interval;
  unsigned repeat = 0;
  int stack = 1;
  
  unsigned id = luaL_checkinteger( L, stack );
  stack++;
  MOD_CHECK_ID( tmr, id );

  interval = luaL_checkinteger( L, stack );
  stack++;
  if ( interval <= 0 )
    return luaL_error( L, "wrong arg range" );

  if ( lua_isnumber(L, stack) ){
    repeat = lua_tointeger(L, stack);
    stack++;
    if ( repeat != 1 && repeat != 0 )
      return luaL_error( L, "wrong arg type" );
  }

  // luaL_checkanyfunction(L, stack);
  if (lua_type(L, stack) == LUA_TFUNCTION || lua_type(L, stack) == LUA_TLIGHTFUNCTION){
    lua_pushvalue(L, stack);  // copy argument (func) to the top of stack
    if(alarm_timer_cb_ref[id] != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, alarm_timer_cb_ref[id]);
    alarm_timer_cb_ref[id] = luaL_ref(L, LUA_REGISTRYINDEX);
  }

  os_timer_disarm(&(alarm_timer[id]));
  os_timer_setfn(&(alarm_timer[id]), (os_timer_func_t *)(alarm_timer_cb[id]), L);
  os_timer_arm(&(alarm_timer[id]), interval, repeat); 
  return 0;  
}
开发者ID:141141,项目名称:nodemcu-firmware-lua5.3.0,代码行数:36,代码来源:tmr.c

示例12: uart_on

//uart.on(id,function(t))
static int uart_on( lua_State* L )
{
  uint16_t id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  
  size_t sl;
  const char *method = luaL_checklstring( L, 2, &sl );
  if (method == NULL)
    return luaL_error( L, "wrong arg type" );
  
  if(sl == 4 && strcmp(method, "data") == 0)
  {
    if (lua_type(L, 3) == LUA_TFUNCTION || lua_type(L, 3) == LUA_TLIGHTFUNCTION)
      {
        lua_pushvalue(L, 3);
        if(usr_uart_cb_ref != LUA_NOREF)
        {
          luaL_unref(L, LUA_REGISTRYINDEX, usr_uart_cb_ref);
        }
        usr_uart_cb_ref = luaL_ref(L, LUA_REGISTRYINDEX);
      }
  }
  else
  {
    return luaL_error( L, "wrong arg type" );
  }
  return 0;
}
开发者ID:SmartArduino,项目名称:MICO-1,代码行数:29,代码来源:uart.c

示例13: adc_getsamples

// Lua: table_of_vals = getsamples( id, [count] )
static int adc_getsamples( lua_State* L )
{
  unsigned id, i;
  u16 bcnt, count = 0;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( adc, id );

  if ( lua_isnumber(L, 2) == 1 )
    count = ( u16 )lua_tointeger(L, 2);
  
  bcnt = adc_wait_samples( id, count );
  
  // If count is zero, grab all samples
  if ( count == 0 )
    count = bcnt;
  
  // Don't pull more samples than are available
  if ( count > bcnt )
    count = bcnt;
  
  lua_createtable( L, count, 0 );
  for( i = 1; i <= count; i ++ )
  {
    lua_pushinteger( L, adc_get_processed_sample( id ) );
    lua_rawseti( L, -2, i );
  }
  return 1;
}
开发者ID:ARMinARM,项目名称:elua,代码行数:30,代码来源:adc.c

示例14: ow_skip

// Lua: ow.skip( id )
static int ow_skip( lua_State *L )
{
  unsigned id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( ow, id );
  onewire_skip(id);
  return 0;
}
开发者ID:Dxploto,项目名称:nodemcu-firmware,代码行数:8,代码来源:ow.c

示例15: uart_setup

//uart.setup(1,9600,'n','8','1')
//baud:all supported
//parity:
//      n,NO_PARITY;
//      o,ODD_PARITY;
//      e,EVEN_PARITY
//databits:
//      5:DATA_WIDTH_5BIT,
//      6:DATA_WIDTH_6BIT,
//      7:DATA_WIDTH_7BIT,
//      8:DATA_WIDTH_8BIT,
//      9:DATA_WIDTH_9BIT
//stopbits:
//      1,STOP_BITS_1
//      2,STOP_BITS_2
static int uart_setup( lua_State* L )
{
  uint16_t id, databits=DATA_WIDTH_8BIT, parity=NO_PARITY, stopbits=STOP_BITS_1;
  uint32_t baud=9600;
  
  id = luaL_checkinteger( L, 1 );
  MOD_CHECK_ID( uart, id );
  baud = luaL_checkinteger( L, 2 );
  size_t sl=0;
  char const *str = luaL_checklstring( L, 3, &sl );
  if(sl == 1 && strcmp(str, "n") == 0)
    parity = NO_PARITY;
  else if(sl == 1 && strcmp(str, "o") == 0)
    parity = ODD_PARITY;
  else if(sl == 1 && strcmp(str, "e") == 0)
    parity = EVEN_PARITY;
  else
    return luaL_error( L, "arg parity should be 'n' or 'o' or 'e' " );
  
  str = luaL_checklstring( L, 4, &sl );
  if(sl == 1 && strcmp(str, "5") == 0)
    databits = DATA_WIDTH_5BIT;
  else if(sl == 1 && strcmp(str, "6") == 0)
    databits = DATA_WIDTH_6BIT;
  else if(sl == 1 && strcmp(str, "7") == 0)
    databits = DATA_WIDTH_7BIT;
  else if(sl == 1 && strcmp(str, "8") == 0)
    databits = DATA_WIDTH_8BIT;
  else if(sl == 1 && strcmp(str, "9") == 0)
    databits = DATA_WIDTH_9BIT;
  else
    return luaL_error( L, "arg databits should be '5'~'9' " );
  
  str = luaL_checklstring( L, 5, &sl );
  if(sl == 1 && strcmp(str, "1") == 0)
    stopbits = STOP_BITS_1;
  else if(sl == 1 && strcmp(str, "2") == 0)
    stopbits = STOP_BITS_2;
  else
    return luaL_error( L, "arg stopbits should be '1' or '2' " );

  lua_usr_uart_config.baud_rate = baud;
  lua_usr_uart_config.parity=(platform_uart_parity_t)parity;
  lua_usr_uart_config.data_width =(platform_uart_data_width_t)databits;
  lua_usr_uart_config.stop_bits =(platform_uart_stop_bits_t)stopbits;
  
  if(lua_usr_rx_data !=NULL) free(lua_usr_rx_data);
  lua_usr_rx_data = (uint8_t*)malloc(USR_INBUF_SIZE);
  if(pinbuf !=NULL) free(pinbuf);
  pinbuf = (uint8_t*)malloc(USR_UART_LENGTH);
  ring_buffer_init( (ring_buffer_t*)&lua_usr_rx_buffer, (uint8_t*)lua_usr_rx_data, USR_INBUF_SIZE );
  
  //MicoUartFinalize(LUA_USR_UART);
  MicoUartInitialize( LUA_USR_UART, &lua_usr_uart_config, (ring_buffer_t*)&lua_usr_rx_buffer );
  gL = L;
  usr_uart_cb_ref = LUA_NOREF;
  if(plua_usr_usart_thread !=NULL) mico_rtos_delete_thread(plua_usr_usart_thread);  
  mico_rtos_create_thread(plua_usr_usart_thread, MICO_DEFAULT_WORKER_PRIORITY, "lua_usr_usart_thread", lua_usr_usart_thread, 0x300, 0);
  return 0;
}
开发者ID:SmartArduino,项目名称:MICO-1,代码行数:75,代码来源:uart.c


注:本文中的MOD_CHECK_ID函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。