Exemple #1
0
void ds1302()
{
	uchar secondold;
	uchar shi,ge,one;
	beep();
	init_ds1302();
	refreshtime();
	write7219one(2,10); write7219one(7,10); write7219one(10,10); write7219one(15,10); delay(2000);
	while(1)
	{
		second=readsecond;
		temp=readtemp();
		delay(5);
		if(second!=secondold)
		{
			write7219one(11,second/10);write7219one(12,second%10);
			if(second==0)
			refreshtime();
			secondold=second;
		}
		if(temp!=tempold)
		{
			shi=temp%1000/100;
			ge=temp%100/10;
			one=temp%10;
			write_onechar(0x00);
			write_onechar(tablecc[shi]);
			write_onechar(pointcc[ge]);
			write_onechar(tablecc[one]);
			tempold=temp;
		}
	}
}
Exemple #2
0
int commandGetCurAdc(uint8_t *buffer)
{
	int numChanel = buffer[6];
	if( (numChanel > 8) && (numChanel != 57) )
	{ //недопустимый адресс
		buffer[5] = 0x0e;
		return 6;
	}
	else
	{
		//захватим симафор АЦП
		xSemaphoreTake(semaphAdc, portMAX_DELAY);
		if( configTerem.sensorType[numChanel] != GT_SHT21 )
			tempOfDs1820 = readtemp();
		ep1_On();
		epa_On();
		uint16_t curN;
		ResultMes result;
		if( numChanel < 9 )
		{
			tempOfDs1820 += configTerem.deltaT;
			result = readSenser(numChanel, &curN);
		}
		else
			result.p = tempOfDs1820;
		epa_Off();
		ep1_Off();
		//освободим симафор АЦП
		xSemaphoreGive(semaphAdc);

		if( configTerem.sensorType[numChanel] == GT_SHT21 )
		{
			memcpy((void*)&buffer[7], (void*)&result.uClear, 4);
			memcpy((void*)&buffer[11], (void*)&result.p, 4);
			memcpy((void*)&buffer[15], (void*)&result.u, 4);
			return 19;
		}
		else
		{
			memcpy((void*)&buffer[7], (void*)&result.u, 4);
			memcpy((void*)&buffer[11], (void*)&result.p, 4);
			memcpy((void*)&buffer[15], (void*)&curN, 2);
			memcpy((void*)&buffer[18], (void*)&result.uClear, 4);
		}

		switch(numChanel)
		{
			case 57:
				buffer[17] = GT_TermoHK;
				break;
			default:
				buffer[17] = configTerem.sensorType[numChanel];
		}
		return 22;
	}
}
Exemple #3
0
void main()
{
	init_1602();
	init_24c02();
	init();
	readtemp();
	EA=1;
	ET0=1;
	TR0=0;
	while(1)
	{
		keyscan();
		if(second==0)
		{
			if(ahour==hour&&amin==minute)
			{
				display3();
				alarmflag=1;
				beep=0;
				while(alarmflag==1)
				{
					if(k1==0||k2==0||k3==0||k4==0)
					{
						alarmflag=0;
						write_com(0x01);
						beep=1;
						while(k1==0||k2==0||k3==0||k4==0);
					}
				}
			}
		}
		if(flag==0&&k3==0)
		{
			display4();
		}
		if(flag==0&&alarmflag==0)
		{
			display1();
		}
		if(flag==1&&alarmflag==0)
		{
			display2();
		}
	}
} 
Exemple #4
0
void keyscan()
{
	if(k1==0&&flag2!=0)
	{
		delay(5);
		if(k1==0&&flag2!=0)
		{
			flag=0;  flag2=0; write_com(0x0c); init(); if(num!=0&&TR0==0) ET0=0;
		}
		while(k1==0);
	} 
	if(k1==0)
	{
		delay(5);
		if(k1==0)
		{
			flag++;
			if(flag==1)
			{
				init2();
			}
			switch(flag)
			{
				case 6 : write_com(0x80+0x40+0x04); break;
				case 7 : write_com(0x80+0x40+0x07); break;
				case 8 : write_com(0x80+0x40+0x0a); break;
				case 2 : init(); write_com(0x80+0x01); write_com(0x0f); break;
				case 3 : write_com(0x80+0x06); break;
				case 4 : write_com(0x80+0x09); break;
				case 5 : write_com(0x80+0x0d); break;
				case 9 : init3(); break;
				case 10: write_com(0x80+0x09); break;
				case 11: flag=0; write_com(0x01); write_com(0x0c); break;
			}
		}
		while(k1==0);
	}
	if(k2==0)
	{
		delay(5);
		if(k2==0)
		{
			if(flag==1)
			{
				if(ET0==0)
				{
					min2=0;sec2=0;num=0;secp=0;
					for(i=0;i<max;i++)
					{
						mins[i]=0;secs[i]=0;secps[i]=0;
					}
					max=0;ET0=1;flag2++;
					while(k2==0);
				}
				if(TR0==1)
				{
					num++;
					mins[num]=min2;
					secs[num]=sec2;
					secps[num]=secp;
					TR0=0;
					ET0=0;
					max=num;
					flag2++;
					while(k2==0);
				}
			}
			switch(flag)
			{
				case 6 : if(hour<23) hour++; else hour=0; writehour; delay(5); displayhour; write_com(0x80+0x40+0x04); break;
				case 7 : if(minute<59) minute++; else minute=0;writeminute; delay(5); displayminute;  write_com(0x80+0x40+0x07); break;
				case 8 : if(second<59) second++; else second=0;writesecond; delay(5); displaysecond;  write_com(0x80+0x40+0x0a); break;
				case 2 : year++;  writeyear; delay(5); displayyear;write_com(0x80+0x01);  break;
				case 3 : if(month<12) month++; else month=1;writemonth;delay(5); displaymonth; write_com(0x80+0x06);  break;
				case 4 : if(day<31) day++; else day=1; writeday; delay(5); displayday; write_com(0x80+0x09); break;
				case 5 : if(week<8) week++; else week=2; writeweek;delay(5); displayweek; write_com(0x80+0x0d); break;
				case 9 : if(ahour<23) ahour++; else ahour=0; displaytwo(6,ahour); write_add(1,ahour); write_com(0x80+0x06); break;
				case 10: if(amin<59) amin++; else amin=0; displaytwo(9,amin); write_add(2,amin); write_com(0x80+0x09); break;
			}
		}
		while(k2==0);
	}
	if(k3==0&flag!=0)
	{
		delay(5);
		if(k3==0&flag!=0)
		{
			if(flag==1)
			{
				if(ET0==1&&TR0==1)
				{
					num++;
					flag2++;
					mins[num]=min2;
					secs[num]=sec2;
					secps[num]=secp;
					while(k3==0)
					{
						display2();
					}
				}
				if(ET0==1&&TR0==0)
					{
						TR0=1;
						flag2++;
					}
				if(ET0==0)
				{
					if(num>1)
					num--;
					min2=mins[num];
					sec2=secs[num];
					secp=secps[num];
					flag2++;
				}
			}
			switch(flag)
			{
				case 6 : if(hour>0) hour--; else hour=23; writehour;delay(5); displayhour; write_com(0x80+0x40+0x04); break;
				case 7 : if(minute>0) minute--; else minute=59; writeminute; delay(5); displayminute; write_com(0x80+0x40+0x07); break;
				case 8 : if(second>0) second--; else second=59; writesecond; delay(5); displaysecond; write_com(0x80+0x40+0x0a); break;
				case 2 : year--; writeyear; delay(5);  displayyear; write_com(0x80+0x01); break;
				case 3 : if(month>1) month--; else month=12; writemonth; delay(5); displaymonth;  write_com(0x80+0x06); break;
				case 4 : if(day>1) day--; else day=31;writeday; delay(5); displayday;  write_com(0x80+0x09); break;
				case 5 : if(week>1) week--; else week=7;writeweek; delay(5); displayweek;  write_com(0x80+0x0d); break;
				case 9 : if(ahour>0) ahour--; else ahour=23; displaytwo(6,ahour); write_add(1,ahour); write_com(0x80+0x06); break;
				case 10: if(amin>0) amin--; else amin=59; displaytwo(9,amin); write_add(2,amin); write_com(0x80+0x09); break;
			}
		}
		while(k3==0);		
	}
	if(k4==0)
	{
		delay(5);
		if(k4==0&&ET1==0&&flag!=0)
		{
			if(num<max)
			num++;
			min2=mins[num];
			sec2=secs[num];
			secp=secps[num];
			flag2++;
		}
		if(k4==0&&flag==0)
		{
			write_com(0x01);
			displaytemp(readtemp());		  
		}
	}
	while(k4==0);
}
Exemple #5
0
int main(int argc, char **argv) {
	int r, i, usbdevcount;
	char *endptr;
	int cmdline_bus = -1, cmdline_dev = -1;
	libusb_device **usbdevlist = NULL;
	struct libusb_device_descriptor desc;
	libusb_device *probe_usbdev = NULL;
	float temp;

	while ((r = getopt(argc, argv, "vb:d:qh")) != -1) {
		switch (r) {
			case 'v':
				printversion();
				break;
			case 'b':
				errno = 0;
				cmdline_bus = strtol(optarg, &endptr, 10);
				if (*endptr != 0 || errno != 0) {
					fprintf(stderr, "invalid bus number\n");
					return 1;
				}
				break;
			case 'd':
				errno = 0;
				cmdline_dev = strtol(optarg, &endptr, 10);
				if (*endptr != 0 || errno != 0) {
					fprintf(stderr, "invalid device address\n");
					return 1;
				}
				break;
			case 'q':
				debug = 0;
				break;
			case 'h':
				printusage();
				return 0;
				break;
			default:
				if (isprint(optopt))
					fprintf(stderr, "unknown option '-%c'.\n", optopt);
				else
					fprintf(stderr, "unknown option character '-%x'.\n", optopt);
				return 1;
		}
	}

	if (optind < argc || (cmdline_dev && !cmdline_bus)) {
		printusage();
		return 1;
	}

	r = libusb_init(NULL);
	if (r < 0) {
		fprintf(stderr, "error: libusb init error\n");
		return 1;
	}

	libusb_set_debug(NULL, 3);

	if (debug)
		printf("opening device vid=%.4x pid=%.4x...\n", USB_VID, USB_PID);

	usbdevcount = libusb_get_device_list(NULL, &usbdevlist);
	for (i = 0; i < usbdevcount; i++) {
		probe_usbdev = usbdevlist[i];
		r = libusb_get_device_descriptor(probe_usbdev, &desc);
		if (r >= 0 && desc.idVendor == USB_VID && desc.idProduct == USB_PID) {
			if (cmdline_bus >= 0 && libusb_get_bus_number(probe_usbdev) != cmdline_bus)
				continue;
			if (cmdline_dev >= 0 && libusb_get_device_address(probe_usbdev) != cmdline_dev)
				continue;

			r = libusb_open(probe_usbdev, &usbdevh);
			if (r >= 0 && debug)
				printf("device opened\n");
			break;
		}
	}
	if (usbdevlist)
		libusb_free_device_list(usbdevlist, 1);
	if (!usbdevh) {
		fprintf(stderr, "error: can't find device\n");
		libusb_exit(NULL);
		return 1;
	}

    if (libusb_kernel_driver_active(usbdevh, 0))
		libusb_detach_kernel_driver(usbdevh, 0);
    if (libusb_kernel_driver_active(usbdevh, 1))
		libusb_detach_kernel_driver(usbdevh, 1);

	r = libusb_set_configuration(usbdevh, 1);
	if (r < 0) {
		fprintf(stderr, "error: can't set usb configuration\n");
		return 1;
	}

	r = libusb_claim_interface(usbdevh, 0);
	if (r < 0) {
		fprintf(stderr, "error: can't claim interface 0\n");
		libusb_close(usbdevh);
		libusb_exit(NULL);
		return 1;
	}
	r = libusb_claim_interface(usbdevh, 1);
	if (r < 0) {
		fprintf(stderr, "error: can't claim interface 1\n");
		libusb_release_interface(usbdevh, 0);
		libusb_close(usbdevh);
		libusb_exit(NULL);
		return 1;
	}
	if (debug)
		printf("device claimed\n");

	r = readtemp(&temp);
	if (r >= 0) {
		if (debug)
			printf("temperature: %f°C\n", temp);
		else
			printf("%f\n", temp);
	}

	libusb_release_interface(usbdevh, 0);
	libusb_release_interface(usbdevh, 1);
	libusb_close(usbdevh);
	libusb_exit(NULL);

	return 0;
}