예제 #1
0
void main()
{
	uart_init(9600);
	vt_init();

	sonar_t so;
	sonar_t so2;

	sonar_init(&so, A0, A1);
	sonar_init(&so2, A2, A3);

	sei();

	// end
	int16_t res;
	while(1) {
		vt_clear();
		vt_home();
		uart_puts_pgm(PSTR("SONAR\r\n==================="));

		// first
		vt_goto(99, 99); // move cursor away
		sonar_start(&so);
		while(sonar_busy());
		res = sonar_result();

		// print value
		vt_goto(0, 2);
		uart_puts_pgm(PSTR("A: "));

		if (res < 0) {
			uart_puts_pgm(PSTR("No Obstacle"));
		} else {
			uart_puti(res, 1);
			uart_puts_pgm(PSTR(" cm"));
		}

		// second
		vt_goto(99, 99); // move cursor away
		sonar_start(&so2);
		while(sonar_busy());
		res = sonar_result();

		// print value
		vt_goto(0, 3);
		uart_puts_pgm(PSTR("B: "));

		if (res < 0) {
			uart_puts_pgm(PSTR("No Obstacle"));
		} else {
			uart_puti(res, 1);
			uart_puts_pgm(PSTR(" cm"));
		}

		vt_goto(99, 99); // move cursor away
		_delay_ms(200);
	}
}
예제 #2
0
static int __cdecl htsshow_loop(t_hts_callbackarg *carg, httrackp *opt,
	lien_back* back, int back_max, int back_index, int lien_n,
	int lien_tot, int stat_time, hts_stat_struct* stats) { // appel� � chaque boucle de HTTrack
	static TStamp prev_mytime = 0; /* ok */
	static t_InpInfo SInfo; /* ok */
	//
	TStamp mytime;
	long int rate = 0;
	char st[256];
	//
	int stat_written = -1;
	int stat_updated = -1;
	int stat_errors = -1;
	int stat_warnings = -1;
	int stat_infos = -1;
	int nbk = -1;
	LLint nb = -1;
	int stat_nsocket = -1;
	LLint stat_bytes = -1;
	LLint stat_bytes_recv = -1;
	int irate = -1;
	if (stats) {
		stat_written = stats->stat_files;
		stat_updated = stats->stat_updated_files;
		stat_errors = stats->stat_errors;
		stat_warnings = stats->stat_warnings;
		stat_infos = stats->stat_infos;
		nbk = stats->nbk;
		stat_nsocket = stats->stat_nsocket;
		irate = (int) stats->rate;
		nb = stats->nb;
		stat_bytes = stats->nb;
		stat_bytes_recv = stats->HTS_TOTAL_RECV;
	}

	if (!use_show)
		return 1;

	mytime = mtime_local();
	if ((stat_time > 0) && (stat_bytes_recv > 0))
		rate = (int) (stat_bytes_recv / stat_time);
	else
		rate = 0; // pas d'infos

	/* Infos */
	if (stat_bytes >= 0)
		SInfo.stat_bytes = stat_bytes; // bytes
	if (stat_time >= 0)
		SInfo.stat_time = stat_time; // time
	if (lien_tot >= 0)
		SInfo.lien_tot = lien_tot; // nb liens
	if (lien_n >= 0)
		SInfo.lien_n = lien_n; // scanned
	SInfo.stat_nsocket = stat_nsocket; // socks
	if (rate > 0)
		SInfo.rate = rate; // rate
	if (irate >= 0)
		SInfo.irate = irate; // irate
	if (SInfo.irate < 0)
		SInfo.irate = SInfo.rate;
	if (nbk >= 0)
		SInfo.stat_back = nbk;
	if (stat_written >= 0)
		SInfo.stat_written = stat_written;
	if (stat_updated >= 0)
		SInfo.stat_updated = stat_updated;
	if (stat_errors >= 0)
		SInfo.stat_errors = stat_errors;
	if (stat_warnings >= 0)
		SInfo.stat_warnings = stat_warnings;
	if (stat_infos >= 0)
		SInfo.stat_infos = stat_infos;

	if (((mytime - prev_mytime) > 100) || ((mytime - prev_mytime) < 0)) {
		strc_int2bytes2 strc, strc2, strc3;
		prev_mytime = mytime;

		st[0] = '\0';
		qsec2str(st, stat_time);
		vt_home();
		printf(VT_GOTOXY("1","1")
		VT_CLREOL
		STYLE_STATTEXT "Bytes saved:"
		STYLE_STATVALUES " \t%s"
		"\t"
		VT_CLREOL
		VT_GOTOXY("40","1")
		STYLE_STATTEXT "Links scanned:"
		STYLE_STATVALUES " \t%d/%d (+%d)"
		VT_CLREOL"\n"VT_CLREOL
		VT_GOTOXY("1","2")
		STYLE_STATTEXT "Time:"
		" \t"
		STYLE_STATVALUES "%s"
		"\t"
		VT_CLREOL
		VT_GOTOXY("40","2")
		STYLE_STATTEXT "Files written:"
		" \t"
		STYLE_STATVALUES "%d"
		VT_CLREOL"\n"VT_CLREOL
		VT_GOTOXY("1","3")
		STYLE_STATTEXT "Transfer rate:"
		" \t"
		STYLE_STATVALUES "%s (%s)"
		"\t"
		VT_CLREOL
		VT_GOTOXY("40","3")
		STYLE_STATTEXT "Files updated:"
		" \t"
		STYLE_STATVALUES "%d"
		VT_CLREOL"\n"VT_CLREOL
		VT_GOTOXY("1","4")
		STYLE_STATTEXT "Active connections:"
		" \t"
		STYLE_STATVALUES "%d"
		"\t"
		VT_CLREOL
		VT_GOTOXY("40","4")
		STYLE_STATTEXT "Errors:"
		STYLE_STATVALUES " \t"
		STYLE_STATVALUES "%d"
		VT_CLREOL"\n"
		STYLE_STATRESET,
		/* */
		(char*) int2bytes(&strc, SInfo.stat_bytes), (int) lien_n,
				(int) SInfo.lien_tot, (int) nbk, (char*) st,
				(int) SInfo.stat_written,
				(char*) int2bytessec(&strc2, SInfo.irate),
				(char*) int2bytessec(&strc3, SInfo.rate),
				(int) SInfo.stat_updated, (int) SInfo.stat_nsocket,
				(int) SInfo.stat_errors
		/* */
		);

		// parcourir registre des liens
		if (back_index >= 0) { // seulement si index pass�
			int j, k;
			int index = 0;
			int ok = 0; // idem
			int l; // idem
			//
			t_StatsBuffer StatsBuffer[NStatsBuffer];

			{
				int i;
				for (i = 0; i < NStatsBuffer; i++) {
					strcpybuff(StatsBuffer[i].state,"");
					strcpybuff(StatsBuffer[i].name,"");
					strcpybuff(StatsBuffer[i].file,"");
					strcpybuff(StatsBuffer[i].url_sav,"");
					StatsBuffer[i].back = 0;
					StatsBuffer[i].size = 0;
					StatsBuffer[i].sizetot = 0;
				}
			}
			for (k = 0; k < 2; k++) { // 0: lien en cours 1: autres liens
				for (j = 0; (j < 3) && (index < NStatsBuffer); j++) { // passe de priorit�
					int _i;
					for (_i = 0 + k; (_i < max(back_max*k,1)) && (index
							< NStatsBuffer); _i++) { // no lien
						int i = (back_index + _i) % back_max; // commencer par le "premier" (l'actuel)
						if (back[i].status >= 0) { // signifie "lien actif"
							// int ok=0;  // OPTI
							ok = 0;
							switch (j) {
							case 0: // prioritaire
								if ((back[i].status > 0) && (back[i].status
										< 99)) {
									strcpybuff(StatsBuffer[index].state,"receive");
									ok = 1;
								}
								break;
							case 1:
								if (back[i].status == STATUS_WAIT_HEADERS) {
									strcpybuff(StatsBuffer[index].state,"request");
									ok = 1;
								} else if (back[i].status == STATUS_CONNECTING) {
									strcpybuff(StatsBuffer[index].state,"connect");
									ok = 1;
								} else if (back[i].status == STATUS_WAIT_DNS) {
									strcpybuff(StatsBuffer[index].state,"search");
									ok = 1;
								} else if (back[i].status
										== STATUS_FTP_TRANSFER) { // ohh le beau ftp
									sprintf(StatsBuffer[index].state,
											"ftp: %s", back[i].info);
									ok = 1;
								}
								break;
							default:
								if (back[i].status == STATUS_READY) { // pr�t
									if ((back[i].r.statuscode == 200)) {
										strcpybuff(StatsBuffer[index].state,"ready");
										ok = 1;
									} else if ((back[i].r.statuscode >= 100)
											&& (back[i].r.statuscode <= 599)) {
										char tempo[256];
										tempo[0] = '\0';
										infostatuscode(tempo,
												back[i].r.statuscode);
										strcpybuff(StatsBuffer[index].state,tempo);
										ok = 1;
									} else {
										strcpybuff(StatsBuffer[index].state,"error");
										ok = 1;
									}
								}
								break;
							}

							if (ok) {
								char BIGSTK s[HTS_URLMAXSIZE * 2];
								//
								StatsBuffer[index].back = i; // index pour + d'infos
								//
								s[0] = '\0';
								strcpybuff(StatsBuffer[index].url_sav,back[i].url_sav); // pour cancel
								if (strcmp(back[i].url_adr, "file://"))
									strcatbuff(s,back[i].url_adr);
								else
									strcatbuff(s,"localhost");
								if (back[i].url_fil[0] != '/')
									strcatbuff(s,"/");
								strcatbuff(s,back[i].url_fil);

								StatsBuffer[index].file[0] = '\0';
								{
									char* a = strrchr(s, '/');
									if (a) {
										strncatbuff(StatsBuffer[index].file,a,200);
										*a = '\0';
									}
								}

								if ((l = (int) strlen(s)) < MAX_LEN_INPROGRESS)
									strcpybuff(StatsBuffer[index].name,s);
								else {
									// couper
									StatsBuffer[index].name[0] = '\0';
									strncatbuff(StatsBuffer[index].name,s,MAX_LEN_INPROGRESS/2-2);
									strcatbuff(StatsBuffer[index].name,"...");
									strcatbuff(StatsBuffer[index].name,s+l-MAX_LEN_INPROGRESS/2+2);
								}

								if (back[i].r.totalsize > 0) { // taille pr�d�finie
									StatsBuffer[index].sizetot
											= back[i].r.totalsize;
									StatsBuffer[index].size = back[i].r.size;
								} else { // pas de taille pr�d�finie
									if (back[i].status == STATUS_READY) { // pr�t
										StatsBuffer[index].sizetot
												= back[i].r.size;
										StatsBuffer[index].size
												= back[i].r.size;
									} else {
										StatsBuffer[index].sizetot = 8192;
										StatsBuffer[index].size
												= (back[i].r.size % 8192);
									}
								}
								index++;
							}
						}
					}
				}
			}

			/* LF */
			printf("%s\n", VT_CLREOL);

			/* Display current job */
			{
				int parsing = 0;
				printf("Current job: ");
				if (!(parsing = hts_is_parsing(opt, -1)))
					printf("receiving files");
				else {
					switch (hts_is_testing(opt)) {
					case 0:
						printf("parsing HTML file (%d%%)", parsing);
						break;
					case 1:
						printf("parsing HTML file: testing links (%d%%)",
								parsing);
						break;
					case 2:
						printf("purging files");
						break;
					case 3:
						printf("loading cache");
						break;
					case 4:
						printf("waiting (scheduler)");
						break;
					case 5:
						printf("waiting (throttle)");
						break;
					}
				}
				printf("%s\n", VT_CLREOL);
			}

			/* Display background jobs */
			{
				int i;
				for (i = 0; i < NStatsBuffer; i++) {
					if (strnotempty(StatsBuffer[i].state)) {
						printf(VT_CLREOL" %s - \t%s%s \t%s / \t%s",
								StatsBuffer[i].state, StatsBuffer[i].name,
								StatsBuffer[i].file,
								int2bytes(&strc, StatsBuffer[i].size),
								int2bytes(&strc2, StatsBuffer[i].sizetot));
					}
					printf("%s\n", VT_CLREOL);
				}
			}

		}

	}

	return 1;
}