コード例 #1
0
ファイル: AP_Var.cpp プロジェクト: Artoko/ardupilotdev
// Copy the variable's whole name to the supplied buffer.
//
// If the variable is a group member, prepend the group name.
//
void AP_Var::copy_name(char *buffer, size_t buffer_size) const
{
    buffer[0] = '\0';
    if (_name) {
        if (_group)
            _group->copy_name(buffer, buffer_size);
        strlcat_P(buffer, _name, buffer_size);
    }
}
コード例 #2
0
ファイル: strlcat_P.c プロジェクト: ChunHungLiu/avr-libc
void Check (int line,
	    const char *dst, const char *src, size_t size,
	    const char *result)
{
    char d[strlen_P (dst) + strlen_P (src) + 1];
    size_t n, must;

    strcpy_P (d, dst);

    must = (size < strlen_P (dst) ? size : strlen_P (dst)) + strlen_P (src);
    n = strlcat_P (d, src, size);
    if (n != must) {
	PRINTFLN (line, "wrong return value: %zu, must: %zu", n, must);
	EXIT (line);
    }

    if (strcmp_P (d, result) != 0) {
	PRINTFLN (line, "wrong result dst: %s", d);
	EXIT (1000 + line);
    }
}
コード例 #3
0
ファイル: proc_menu.c プロジェクト: nodep/7g-wireless
bool process_menu(void)
{
	start_led_sequence(led_seq_menu_begin);

	// print the main menu
	uint8_t keycode;
	char* pEnd;
	const uint8_t BUFF_SIZE = 64;
	char string_buff[BUFF_SIZE];
	for (;;)
	{
		// welcome & version
		if (!send_text(PSTR("\x01"	// translates to Ctrl-A on the dongle
							"7G wireless\n"
							"firmware build " __DATE__ "  " __TIME__ "\n"
							"battery voltage: "), true, false))
			return true;

		get_battery_voltage_str(string_buff);
		if (!send_text(string_buff, false, false))		return true;

		// RF stats
		if (!send_text(PSTR("\nRF packet stats (total/retransmit/lost): "), true, false))		return true;

		ultoa(rf_packets_total, string_buff, 10);
		pEnd = strchr(string_buff, '\0');
		*pEnd++ = '/';

		ultoa(arc_total, pEnd, 10);
		pEnd = strchr(string_buff, '\0');
		*pEnd++ = '/';

		ultoa(plos_total, pEnd, 10);
		if (!send_text(string_buff, false, false))			return true;

		// output the time since reset
		uint16_t days;
		uint8_t hours, minutes, seconds;
		get_time(&days, &hours, &minutes, &seconds);
		if (!send_text(PSTR("\nkeyboard's been on for "), true, false))		return true;

		string_buff[0] = '\0';
		if (days > 0)
		{
			itoa(days, string_buff, 10);
			strcat_P(string_buff, PSTR(" days "));
		}

		if (hours > 0  ||  days > 0)
		{
			itoa(hours, strchr(string_buff, 0), 10);
			pEnd = strlcat_P(string_buff, PSTR(" hours "), BUFF_SIZE) + string_buff;
		} else {
			pEnd = strchr(string_buff, 0);
		}

		itoa(minutes, pEnd, 10);
		pEnd = strlcat_P(string_buff, PSTR(" minutes "), BUFF_SIZE) + string_buff;

		itoa(seconds, pEnd, 10);
		strcat_P(string_buff, PSTR(" seconds\n"));

		if (!send_text(string_buff, false, true))		return true;

		// menu
		if (!send_text(PSTR("\n\nwhat do you want to do?\n"
							"F1 - change transmitter output power (current "), true, false))		return true;
		switch (get_nrf_output_power())
		{
		case vRF_PWR_M18DBM:	send_text(PSTR("-18"), true, false); 	break;
		case vRF_PWR_M12DBM:	send_text(PSTR("-12"), true, false); 	break;
		case vRF_PWR_M6DBM:		send_text(PSTR("-6"), true, false); 	break;
		case vRF_PWR_0DBM:		send_text(PSTR("0"), true, false); 		break;
		}

		if (!send_text(PSTR("dBm)\nF2 - change LED brightness (current "), true, false))		return true;

		uint8_t fcnt;
		for (fcnt = 0; fcnt < sizeof led_brightness_lookup; ++fcnt)
		{
			if (led_brightness_lookup[fcnt] == get_led_brightness())
			{
				string_buff[0] = 'F';
				itoa(fcnt + 1, string_buff + 1, 10);
				break;
			}
		}

		// no match found in the loop?
		if (fcnt == sizeof led_brightness_lookup)
			itoa(get_led_brightness(), string_buff, 10);

		if (!send_text(string_buff, false, false))
			return true;

		if (!send_text(PSTR(")\nF3 - lock keyboard (unlock with Func+Del+LCtrl)\n"
							"F4 - reset RF packet stats\n"
							"F5 - refresh this menu\n"
							"F6 - calibrate internal RC oscillator (OSCCAL="), true, false))
			return true;

		// output OSCCAL
		itoa(OSCCAL, string_buff, 10);
		if (!send_text(string_buff, false, false))
			return true;

		if (!send_text(PSTR(")\nEsc - exit menu\n\n"), true, false))
			return true;

		// get the user response
		do {
			keycode = get_key_input();
		} while (!(keycode >= KC_F1  &&  keycode <= KC_F6)  &&  keycode != KC_ESC);

		if (keycode == KC_F1)
		{
			if (!send_text(PSTR("select power:\nF1 0dBm\nF2 -6dBm\nF3 -12dBm\nF4 -18dBm\n"), true, false))
				return true;

			while (1)
			{
				keycode = get_key_input();
				if (keycode >= KC_F1  &&  keycode <= KC_F4)
				{
					if (keycode == KC_F1)	set_nrf_output_power(vRF_PWR_0DBM);
					if (keycode == KC_F2)	set_nrf_output_power(vRF_PWR_M6DBM);
					if (keycode == KC_F3)	set_nrf_output_power(vRF_PWR_M12DBM);
					if (keycode == KC_F4)	set_nrf_output_power(vRF_PWR_M18DBM);
					break;
				}
			}
		} else if (keycode == KC_F2) {
			if (!send_text(PSTR("press F1 (dimmest) to F12 (brightest) for brightness, Esc to finish\n"), true, false))
				return true;

			do {
				keycode = get_key_input();
				if (keycode >= KC_F1  &&  keycode <= KC_F12)
				{
					set_led_brightness(led_brightness_lookup[keycode - KC_F1]);
					set_leds(7, 50);
				}
			} while (keycode != KC_ESC);

		} else if (keycode == KC_F3) {
			send_text(PSTR("Keyboard is now LOCKED!!!\nPress Func+Del+LCtrl to unlock\n\n"), true, false);
			return true;

		} else if (keycode == KC_F4) {

			// reset the counters to 0
			plos_total = arc_total = rf_packets_total = 0;

		} else if (keycode == KC_F6) {

			// recalibrate the internnal RC oscillator
			calibrate_rc();

		} else if (keycode == KC_ESC) {

			start_led_sequence(led_seq_menu_end);
			send_text(PSTR("\nexiting menu, you can type now\n"), true, true);
			break;
		}
	}

	return false;
}