Ejemplo n.º 1
0
//===================================
static int lwifi_scan( lua_State* L )
{
  OSStatus err = 0;
  int tmo = mico_get_time();
  
  wifi_scanned_print = 0;
  
  if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION) {
    lua_pushvalue(L, 1);  // copy argument (func) to the top of stack
    if (wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    
    wifi_scan_succeed = luaL_ref(L, LUA_REGISTRYINDEX);
  } 
  else {
    if (wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = LUA_NOREF;
    if (lua_type(L, 1) == LUA_TNUMBER) {
      int prn = luaL_checkinteger( L, 1 );
      if (prn == 1) wifi_scanned_print = 1;
    }
  }
  err = mico_system_notify_register( mico_notify_WIFI_SCAN_ADV_COMPLETED, (void *)_micoNotify_WiFi_Scan_OK, NULL );
  require_noerr( err, exit );
  gL = L;
  wifi_scanned = 0;
  micoWlanStartScanAdv();

  tmo = mico_get_time();
  if (wifi_scan_succeed == LUA_NOREF) {
    while (wifi_scanned == 0) {
      if ((mico_get_time() - tmo) > 8000) break;
      mico_thread_msleep(100);
      luaWdgReload();
    }
    if ((wifi_scanned == 1) && (wifi_scanned_print == 0)) {
      return 2;
    }
  }
exit:
  return 0;
}
Ejemplo n.º 2
0
//function listap(t) if t then for k,v in pairs(t) do print(k.."\t"..v);end else print('no ap') end end wifi.scan(listap)
static int lwifi_scan( lua_State* L )
{
  if (lua_type(L, 1) == LUA_TFUNCTION || lua_type(L, 1) == LUA_TLIGHTFUNCTION)
  {
    lua_pushvalue(L, 1);  // copy argument (func) to the top of stack
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    
     wifi_scan_succeed = luaL_ref(L, LUA_REGISTRYINDEX);
     OSStatus err = MICOAddNotification( mico_notify_WIFI_SCAN_ADV_COMPLETED, (void *)_micoNotify_WiFi_Scan_OK );
     require_noerr( err, exit );
     micoWlanStartScanAdv();
     gL = L;
  } 
  else 
  {
    if(wifi_scan_succeed != LUA_NOREF)
      luaL_unref(L, LUA_REGISTRYINDEX, wifi_scan_succeed);
    wifi_scan_succeed = LUA_NOREF;
  }
 exit: 
    return 0;
}