bool ESPSerialWiFiManager::_connect_manual(){
    OFL("Manual WiFi Config:");
    String ssid = _prompt(F("Enter SSID (Case Sensitive)"));
    String opt = _prompt(F("Encrypted Network? y/n"));
    String pass = "";
    if(CHAROPT(opt[0],'y')){
        pass = _prompt("Password", '*');
    }

    _get_advanced();

    _disconnect();
    return _connect(ssid, pass);
}
bool ESPSerialWiFiManager::_connect_enc(String ssid){
    OF("Connect to "); O(ssid); OFL(":");

    String pass = _prompt("Password", '*');

    _get_advanced();

    return _connect(ssid, pass);
}
示例#3
0
文件: main.c 项目: ereio/FAT-CAT
int shell_loop(char * line, char cmd[255][255]) {
        _setup(cmd);
        _prompt();

        if(_read(line)){
                _parse(line, cmd);
                if (exec) _execute(cmd);
        } else {
	      	run = 0;
        }
	return 0;
}
IPAddress ESPSerialWiFiManager::_prompt_ip(String prompt, IPAddress def){
    while(true){
        String p(prompt);
        if(def != 0){
            p = p + " (Default: " + def.toString() + ")";
        }
        String ip_str = _prompt(p, ' ', 0);
        if(ip_str.length() == 0){
            return def;
        }
        IPAddress ip;
        if(ip.fromString(ip_str))
            return ip;
        else{
            OFL("Invalid IP entered! Please try again.\n");
        }
    }
}
bool ESPSerialWiFiManager::_connect_wps(){
    _disconnect();
    OFL("Push the WPS button on your access point now.");
    String opt = _prompt("Press Enter when complete (q to abort)");
    if(CHAROPT(opt[0], 'q')) return false;
    OFL("Attempting WPS connection. May take some time...");
    if(WiFi.beginWPSConfig()){
        String ssid = WiFi.SSID();
        if(ssid.length() > 0){
            OL("\nSuccess! Connected to network " + ssid);
            NL();
            _disp_network_details();
            NL();
            _save_config(ssid, WiFi.psk(), true);
            return true;
        }
        else{
            return false;
        }
    }
}
示例#6
0
void magic_eater_cast(int tval)
{
    int chance;
    _spell_t *spell;

    /* Duplicate anti-magic checks since "device" commands might re-route here (as "magic" commands)
       For example, do_cmd_use_staff() will allow magic-eaters to invoke staff based spells. */
    if (dun_level && (d_info[dungeon_type].flags1 & DF1_NO_MAGIC))
    {
        msg_print("The dungeon absorbs all attempted magic!");
        return;
    }
    else if (p_ptr->tim_no_spells)
    {
        msg_print("Your spells are blocked!");
        return;
    }
    else if (p_ptr->anti_magic)
    {
        msg_print("An anti-magic shell disrupts your magic!");
        return;
    }
    else if (IS_SHERO())
    {
        msg_print("You cannot think clearly!");
        return;
    }

    if (p_ptr->confused)
    {
        msg_print("You are too confused!");
        return;
    }

    spell = _prompt(tval);
    if (!spell)
        return;
    if (!_calc_charges(spell))
    {
        msg_print("You are out of charges!");
        return;
    }

    energy_use = 100;
    chance = _calc_fail_rate(spell);
    if (randint0(100) < chance)
    {
        if (flush_failure) flush();
        msg_format("You failed to get the magic off!");
        sound(SOUND_FAIL);
        if (randint1(100) >= chance)
            virtue_add(VIRTUE_CHANCE,-1);
        return;
    }
    else
    {
        if (_do_device(spell->kind.tval, spell->kind.sval, SPELL_CAST)) 
            _use_charge(spell);
        else
            energy_use = 0;
    }
}
void ESPSerialWiFiManager::run_menu(int timeout){
    bool first_run = true;
    static const uint8_t _main_menu_size = 7;
    static String _main_menu[_main_menu_size] = {
        F("Scan"),
        F("Enter SSID"),
        F("WPS Connect"),
        F("Disconnect"),
        F("Commit Config"),
        F("Display Network Details"),
        F("Quit")
        //"Disconnect"
    };

    static int i;
    NL();
    OFL("ESP Serial WiFi Manager");
    OFL("=======================");

    while(true){
        NL();
        OFL("================");
        OFL("MAIN MENU");
        OFL("================");
        i = _print_menu(_main_menu, _main_menu_size, first_run ? timeout : 0);
        if(i == -1) return; //timeout ocurred, exit
        first_run = false;
        switch(i){
            case 1:
                _scan_for_networks();
                break;
            case 2:
                if(_connect_manual())
                    _disp_network_details();
                break;
            case 3: //WPS Connect
                _connect_wps();
                break;
            case 4:
                if(WiFi.status() == WL_CONNECTED){
                    _disconnect();
                    OFL("Complete");
                    _reset_config();
                    _write_config();
                    OFL("Choose Commit Config to prevent reconnect on reboot.");
                }
                else{
                    OFL("Not currently connected...");
                }
                break;
            case 5:
                _commit_config();
                break;
            case 6:
                _disp_network_details();
                break;
            case 7:
                if(_dirty_config){
                    OFL("Your current config is unsaved.");
                    String opt = _prompt("Save Before Quit? y/n");
                    if(CHAROPT(opt[0], 'y')) _commit_config();
                }
                return;
        }
        delay(1);
    }
}
bool ESPSerialWiFiManager::_prompt_bool(String prompt){
    String opt = _prompt(prompt + " y/n");
    return CHAROPT(opt[0], 'y');
}
int ESPSerialWiFiManager::_prompt_int(String prompt, int timeout){
    String res = _prompt(prompt, ' ', timeout);
    int res_i = res.toInt();
    //NOTE: toInt() returns 0 if cannot parse, therefore 0 is not a valid input
    return res_i;
}
void ESPSerialWiFiManager::_scan_for_networks(){
    int i, opt, n;
    String opt_s;
    bool inv_opt = false;

    while(true){

        if(!inv_opt){
            OFL("Starting network scan...\n");
            n = WiFi.scanNetworks();
        }

        inv_opt = false;
        if(n == 0){
            OFL("\nNo Avaliable Networks!\nChoose Option Below.");
        }
        else{
            O(n); OFL(" networks found:");
            OFL("==================");
            for(i=0; i < n; i++){
                O(i + 1);O(": ");O(WiFi.SSID(i));
                O(" (");O(WiFi.RSSI(i));O(")");
                OL((WiFi.encryptionType(i) == ENC_TYPE_NONE)?"":"*");
            }
            OFL("==================");
        }

        NL();
        OFL("s: Scan Again");
        OFL("q: Quit Network Scan");

        opt_s  = _prompt("");

        if(CHAROPT(opt_s[0], 'q')){ return; } //exit scan
        else if(CHAROPT(opt_s[0], 's')){ continue; }
        else{
            opt = opt_s.toInt();
            if(opt < 1 || opt >= n + 2){
                OFL("Invalid Menu Option!");
                inv_opt = true;
            }
            else{
                    opt = opt - 1;
                    switch (WiFi.encryptionType(opt)) {
                        case ENC_TYPE_WEP:
                        case ENC_TYPE_TKIP:
                        case ENC_TYPE_CCMP:
                        case ENC_TYPE_AUTO:
                            if(_connect_enc(WiFi.SSID(opt))){
                                _disp_network_details();
                                return;
                            }
                            break;
                        case ENC_TYPE_NONE:
                            if(_connect_noenc(WiFi.SSID(opt))){
                                _disp_network_details();
                                return;
                            }
                            break;

                    opt_s = _prompt("Scan Again? y/n");
                    if(CHAROPT(opt_s[0], 'y')){ continue; }
                    else{ return; }
                  }
            }
        }
    }
}
示例#11
0
static void _libxlibtrace_init (void) {
	//printf("libxlibtrace: starting up\n");

	if (getenv(libxlibtrace_envvar_output_file)) {
		const char * output_filename = getenv(libxlibtrace_envvar_output_file);
		const char * output_mode = "w";
		if (getenv(libxlibtrace_envvar_append)) {
			output_mode = "a";
		}
		out = fopen(output_filename, output_mode);
		if (out == NULL) {
			fprintf(stderr, "xlibtrace: Error: Unable to open output file \"%s\"\n", output_filename);
			exit(1);
		}
	} else if (getenv(libxlibtrace_envvar_stderr)) {
		out = stderr;
	} else if (getenv(libxlibtrace_envvar_stdout)) {
		out = stdout;
	} else {
		out = stderr;
	}

	if (getenv(libxlibtrace_envvar_show_implementation_dependent_structs)) {
		__show_implementation_dependent_structs = 1;
	}

	if (getenv(libxlibtrace_envvar_single)) {
		const char *ld_preload = getenv("LD_PRELOAD");
		if (ld_preload == NULL) {
			// wtf?
		} else {
			unsigned int i = 0;
			while (ld_preload[i] && ld_preload[i] != ':' && !isspace(ld_preload[i])) {
				i++;
			}
			setenv("LD_PRELOAD", ld_preload + i, 1);
		}
	}

	if (getenv(libxlibtrace_envvar_prompt)) {
		__prompt = 1;
	}

	if (_prompt()) {
		// FIXME termios/readline
		setvbuf(stdin, NULL, _IONBF, 0);
	}

	if (getenv(libxlibtrace_envvar_sleep)) {
		const char *sleep_str = getenv(libxlibtrace_envvar_sleep);
		char *end;
		__sleep_amount = strtoul(sleep_str, &end, 10);
		// FIXME: check end/errno like I know I should...
	}

	if (getenv(libxlibtrace_envvar_xflush)) {
		__xflush = 1;
	}

	if (getenv(libxlibtrace_envvar_xsync)) {
		__xsync = 1;
	}

	if (getenv(libxlibtrace_envvar_fflush)) {
		__fflush = 1;
	}

}