예제 #1
0
void ioinit(void)
{
    //1 = output, 0 = input 
    DDRB = 0b11111111 & ~((1<<BUT_UP)|(1<<BUT_DOWN)|(1<<BUT_ALARM)); //Up, Down, Alarm switch  
    DDRC = 0b11111111;
    DDRD = 0b11111111 & ~(1<<BUT_SNOOZE); //Snooze button
	

	PORTB = (1<<BUT_UP)|(1<<BUT_DOWN)|(1<<BUT_ALARM); //Enable pull-ups on these pins
	PORTD = 0b10100100; //Enable pull-up on snooze button
	PORTC = 0b00111111;

    //Init Timer0 for delay_us
	TCCR0B = (1<<CS01); //Set Prescaler to clk/8 : 1click = 0.5us(assume we are running at external 16MHz). CS01=1 
	
	//Init Timer1 for second counting
	TCCR1B = (1<<CS12)|(1<<CS10); //Set prescaler to clk/1024 :1click = 64us (assume we are running at 16MHz)
	TIMSK1 = (1<<TOIE1); //Enable overflow interrupts
    TCNT1 = 49911; //65536 - 15,625 = 49,911 - Preload timer 1 for 49,911 clicks. Should be 1s per ISR call
	
	//Init Timer2 for updating the display via interrupts
	TCCR2B = (1<<CS22)|(1<<CS21)|(1<<CS20); //Set prescalar to clk/1024 : 1 click = 64us (assume 16MHz)
	TIMSK2 = (1<<TOIE2);
	//TCNT2 should overflow every 16.384 ms (256 * 64us)
	
	hours = 88;
	minutes = 88;
	seconds = 88;

	alarm_going = FALSE;
	
	sei(); //Enable interrupts

	siren(200); //Make some noise at power up
	
	hours = 12;
	minutes = 00;
	seconds = 00;
	ampm = AM;

	hours_alarm = 11;
	minutes_alarm = 55;
	seconds_alarm = 00;
	ampm_alarm = PM;

	hours_alarm_snooze = 12;
	minutes_alarm_snooze = 00;
	seconds_alarm_snooze = 00;
	ampm_alarm_snooze = AM;
	
	snooze = FALSE;

	//Segment test
	/*while(1)
	{
		PORTD = 0;
		PORTC = 0xFF;
		delay_ms(1000);

		PORTD = 0xFF;
		PORTC = 0xFF;
		delay_ms(1000);
	}*/	
}
예제 #2
0
파일: main.c 프로젝트: annunal/IDSL
int main(int argc, char *argv[]) 
{
  struct sensorGrid readings;
  int fd, wd, idx;
  char fullname[FILENAME_MAX], tmpname[FILENAME_MAX], logCommands[4096];
  char hostname[200];
  int er=gethostname(hostname,sizeof(hostname));
  printf("Hostname=%s\n",hostname);
  readConfiguration(CONFIGFILENAME);
  
  if (argc>=2) 
  {
	if (strcasecmp(argv[1],"retry")==0)
	{   char dateName[32], currDate[32];
		if(argc==3) strcpy(dateName,argv[2]);
		else {
			
			time_t now = (time_t) time(0);
			struct tm *gmtm = (struct tm *) gmtime(&now);
			strftime(dateName, sizeof(dateName), "retry_%Y-%m-%d.txt", gmtm);
			}
		retryToTransmit(dateName);
		return;
	}
  }
  //if(argc != 3 && argc != 4) {
    //fprintf(stderr, "Usage: %s foldername filename [output]\n", argv[0]);
    //return 1;
  //}

  //if(argc == 4) {
  if(Configuration.commandSerial[0]) {
    otp = openSerialPort(Configuration.commandSerial, B9600);
    if(otp) {
      itp = otp;
    } else {
      perror( "Unable to append to output device" );
      otp = stdout;
      itp = stdin;
    }
  } else {
    otp = stdout;
    itp = stdin;
  }

  /* read configuration */
  for(idx = 0; idx < MAX_PROP; idx++) status[idx] = NULL;

  readStatus(status);

  /* set up communication with the siren */
  if (wiringPiSetupGpio () == -1)  
  {  
     perror( "Can't initialise wiringPi" );
     return -2;
  }  


  initSiren(SIREN_PIN);  
  initBigDisplay();
  readings.pressure = 0;
  readings.temperature = 0;
  readings.distance = 0;
  initSensors();  
  initServo(SERVO_PIN, itp);  
  startServo();
  
  sleep(1);  // sleep 1 s to have at least 1 sensor value
  initAnalysis();  
  
  // lcd = lcdInit (2, 16, 4, RS, STRB, 0, 1, 2, 3, 4, 5, 6, 7);

  startSensorsReading(&readings);

	if(Configuration.watchFolder[0] && Configuration.watchFile) {
		sprintf(tmpname, "%s/%s", argv[1], argv[2]);
		realpath(tmpname, fullname);
	}

  /* set up file watcher */
  fd = inotify_init ();
  if (fd < 0) {
        perror ("unable to initialize inotify");
        return -1;
  }

  if( Configuration.watchFolder[0] )
	wd = inotify_add_watch (fd, Configuration.watchFolder, IN_CLOSE_WRITE );
  else
	wd = 0;

  if (wd < 0) {
        perror ("unable to add inotify watch");
        return -2;
  }

  /* loop on file change events and execute commands */
  while( 1 ) {
    char buf[BUF_LEN];
    int len, i = 0, process = 0;
    
    len = read (fd, buf, BUF_LEN);
    if (len < 0) {
            if (errno == EINTR)
                    ;	/* need to reissue system call */
            else
                    perror ("error reading inotify stream");
    } else if (!len)
		; /* BUF_LEN too small? */
    
    while (i < len) {
            struct inotify_event *event;
    
            event = (struct inotify_event *) &buf[i];
    
            // printf ("wd=%d mask=%u cookie=%u len=%u\n",
                    // event->wd, event->mask,
                    // event->cookie, event->len);
    
            if (event->len && strcmp(argv[2], event->name) == 0)
	    	process++;
    
            i += EVENT_SIZE + event->len;
    }

    if(process) { // It doesn't matter how many times the file changed, but it is good for debugging
	char *line = NULL, *ptr, *end, **commandName, *displayLines[MAX_LINES];
	FILE *fp = 0;
	int i, len, chars, cmd, statusDirty = 0, cmdPosition = 0;
	process = 0;

	fp=fopen(fullname, "r");
	if(fp) {
		unlink(fullname);	// the name is removed from the filesystem, the file isn't until it is closed
					// if a new file is created, it accumulates event in the watcher, and we'll cycle again next round

		while ((chars = getline(&line, &len, fp)) != -1) {
			ptr = line;
			while(*ptr != ':') {
				*ptr=toupper(*ptr);
				ptr++;
			}

			for( cmd=0, ptr = *(commandName = commands); ptr; ptr=*(++commandName), cmd++)
				if( !strncmp(ptr, line, strlen(ptr)) )
				{ // the command is present in the list and can be sent to the panel: it double checks the data from php
					switch(cmd)
					{
						case 7:		// SIREN
							ptr = line + 1 + strlen(ptr);   // skip property name and colon
                                                        end = ptr + strlen(ptr);
                                                        while( *--end == 13 || *end == 10) *end = '\0';
							siren(ptr);
							if(cmdPosition + strlen(line) < 3072)
								cmdPosition += sprintf(logCommands + cmdPosition, "%s;", line );
							statusDirty = -1;
						break;
						case 8:		// SPEAKER
						break;
						case 9:		// DELETE
						break;
						case 10:	// RESET
						break;
						case 11:	// PWR
						break;
						case 12:	// TIMEZONE
						break;
						case 13:	// NAME
						break;
						case 14:	// RESTORE
						break;
						case 15:	// TIMETO
						break;
						case 16:	// IPADDR
						break;
						case 17:	// SUBNET
						break;
						case 18:	// GSM
						break;
						case 19:	// GSMRES
						break;
						default:	// set property
							if(status[cmd]) free(status[cmd]);
							ptr = line + 1 + strlen(ptr);	// skip property name and colon
							end = ptr + strlen(ptr);	// end of command to retrieve EOL
							while( *--end == 13 || *end == 10) *end = '\0';
							status[cmd] = strdup(ptr);
							statusDirty = -1;
							fprintf(otp, "%s\r\n", line);
							fflush(otp);
							if(cmdPosition + strlen(line) < 3072)
								cmdPosition += sprintf(logCommands + cmdPosition, "%s;", line );
						break;
					}
					break;
				}
		}

		if(line) free(line);
		fclose(fp);
	    } else {
		perror("Unable to open the update file");
	    }
	    if(statusDirty)
		writeStatus();
	    logCommandAsync(logCommands);
	    for( i = 0; i < MAX_LINES; i++)
		displayLines[i] = status[LINE1 + i];
	    len = 4;
	    while(i && !displayLines[--i]) len--;
	    bigDisplay(len, displayLines);
    }
  }

  return 0;
}
예제 #3
0
//Displays current time
//Brightness level is an amount of time the LEDs will be in - 200us is pretty dim but visible.
//Amount of time during display is around : [ BRIGHT_LEVEL(us) * 5 + 10ms ] * 10
//Roughly 11ms * 10 = 110ms
//Time on is in (ms)
void display_time(uint16_t time_on)
{
	//uint16_t bright_level = 1000;
	uint16_t bright_level = 50;
	//uint16_t bright_level = 100;
	
	//time_on /= 11; //Take the time_on and adjust it for the time it takes to run the display loop below
	
	for(uint16_t j = 0 ; j < time_on ; j++)
	{
		amMark++;

#ifdef NORMAL_TIME
		//Display normal hh:mm time
		if(hours > 9)
		{
			display_number(hours / 10, 1); //Post to digit 1
			delay_us(bright_level);
		}

		display_number(hours % 10, 2); //Post to digit 2
		delay_us(bright_level);

		display_number(minutes / 10, 3); //Post to digit 3
		delay_us(bright_level);

		display_number(minutes % 10, 4); //Post to digit 4
		delay_us(bright_level);
#else
		//During debug, display mm:ss
		display_number(minutes / 10, 1); 
		delay_us(bright_level);

		display_number(minutes % 10, 2); 
		delay_us(bright_level);

		display_number(seconds / 10, 3); 
		delay_us(bright_level);

		display_number(seconds % 10, 4); 
		delay_us(bright_level);
#endif
		
		//Flash colon for each second
		if(flip == 1) 
		{
			display_number(10, 5); //Post to digit COL
			delay_us(bright_level);
		}
		
		//Indicate wether the alarm is on or off
		if( (PINB & (1<<BUT_ALARM)) != 0)
		{
			display_number(11, 4); //Turn on dot on digit 4
			delay_us(bright_level);

			//If the alarm slide is on, and alarm_going is true, make noise!
			if(alarm_going == TRUE && flip_alarm == 1)
			{
				clear_display();
				siren(500);
				flip_alarm = 0;
			}
		}
		else
		{
			snooze = FALSE; //If the alarm switch is turned off, this resets the ~9 minute addtional snooze timer
			
			hours_alarm_snooze = 88; //Set these values high, so that normal time cannot hit the snooze time accidentally
			minutes_alarm_snooze = 88;
			seconds_alarm_snooze = 88;
		}
		
		//Check whether it is AM or PM and turn on dot
		if((ampm == AM)&&(amMark>=5))
		{
			amMark = 0;	// This variable is used to help dim the am/pm dot
			display_number(12, 6); //Turn on dot on apostrophe
			delay_us(bright_level);
		}

		clear_display();
		delay_us(bright_level);
	}
}
예제 #4
0
void _CYCLIC MyExampleCyclic(void)
{
	/* преобразование кода АЦП x20AI4622 .A14 в физическую величину - температура в середине бункера 1*/
	/* 4 мА - 20 мА */
	tempMidBunker_1	= convFAI4622(tempMidBunkerMin, tempMidBunkerMax, tempMidBunker1);
	tempMidBunker_2	= convFAI4622(tempMidBunkerMin, tempMidBunkerMax, tempMidBunker2);
	tempHighBunker_1 = convFAI4622(tempHighBunkerMin, tempHighBunkerMax, tempHighBunker1);
	tempHighBunker_2 = convFAI4622(tempHighBunkerMin, tempHighBunkerMax, tempHighBunker2);
	if (tempHighBunker_2 > alarmTempHighBunker)
		Alarmstatus[86] = 1;
	T_bunkdrobTF = (tempMidBunker_1 + tempMidBunker_2 + tempHighBunker_1 + tempHighBunker_2) / 4;
	/* преобразование кода АЦП x20AI4622 A15 в физическую величину - давление в системе подачи углекислого газа, в насосе пневматическом, в трубопроводе пылеудаления*/
	/* 0 мА - 20 мА */
	P_pnevmoTRANS1 = convFAI4622(pressurePumpPneumMin, pressurePumpPneumMax, P_PumpAir_Systemcontr);
	P_CO2_resiv = convFAI4622(pressureCO2Min, pressureCO2Max,P_CO2_Systemcontr );
	T_korpusMEL_ = convFAI4622(tempCaseMillMin, tempCaseMillMax,T_korpusMEL);
	P_truboprovodSystemcontr_ = convFAI4622(pressurePipelineKilnMin, pressurePipelineKilnMax,P_truboprovodSystemcontr );  	/* функция измерения давления в трубопроводе перед печью 2 */
	letdownPipelineSystemcontr_ = convFAI4622(pressureDustPeatyMin, pressureDustPeatyMax,letdownPipelineSystemcontr );   /* функция измерения разряжения в трубопроводе пылеудаления */
	/* Вызов функций ручного и автоматического режимов */
	USINT i, area;
	for (area = 0; area < 2; area++){
		if (lineMode[area] != OFF_MODE){
			if (lineMode[area] != ADJ_MODE){
				autoModeStart();
				for (i = 0; i < sizeof(objOn); i++){
					if (objOn[i]){
						dedusting(i);
						if (!adjCrushSwitch)
							Drob_handling(i);
						if (!adjMillSwitch)
							Mill_handling(i);
					}
				}
			}
		}
	}
	for (i = 0; i < sizeof(objOn); i++){
//		adjCrushStopping(i);
//		adjMillStopping(i);
		autoModeTechStop(i);
	}
	autoModeQuickStop();
	
	/* Запуск механизмов */
	siren();
	Cooler_Head_Forward_Start();
	elev_Start();
	shaftOutCrusherForward_Start();
	shaftOutCrusherBackward_Start();
	shaftInCrusherForward_Start();
	shaftInCrusherBackward_Start();
	conv_Start();
	shaftFeederElmot_Start();
	beltFeederMoveOn_Start();
	Pump_Air_Forward_Start();
	Crasher_Head_Forward_Start();
	shluzFeeder();
	schenck();
	resetCounter1();
	ripper();
	pumpPeatCheck();
	pumpAirCheck();
}