Пример #1
0
void IoInit(struct BellHnd Bell)
{
    /*initialize GPIO Bell*/
    Bell.IDBellHamH = bindOutputChannel(7, 3);       //hummer hours
    Bell.IDBellHamHH = bindOutputChannel(7, 5);      //hummer half hours
    Bell.IDBellA = bindOutputChannel(7, 9);          //bell A
    Bell.IDBellB = bindOutputChannel(7, 7);          //bell B

    if ((Bell.IDBellHamH == -1) || (Bell.IDBellHamHH == -1) || (Bell.IDBellA == -1) || (Bell.IDBellB == -1))
    {
        fprintf(stderr, "\nError: unable to access gpio resource. Exit.\n");
        exit(-1);
    }
}
Пример #2
0
int main(int argc, char **argv)
{
  char ID;
  ID=bindOutputChannel(7,38);
  setChannelState(ID,1);
  return 0;
}
Пример #3
0
int main(int argc, char **argv)	{
	/*variabili timer rtc */
	int fd, retval, irqcount = 0;
	unsigned long data;
	struct rtc_time rtc_tm;
	struct rtc_time ring_tm;
	const char *rtc = default_rtc;
	int i=0;
	int IDgreen=-1,IDbuzzer=-1,IDyellow=-1;	
	
	fprintf(stderr, "\n...fraMartino is started and run in background.");
	
	/* port J7.3 e J7.7 impostati come out */ 
	IDgreen=bindOutputChannel(7,3);
	IDyellow=bindOutputChannel(7,7);
	IDbuzzer=bindOutputChannel(7,4);

	
	if((IDgreen==-1)||(IDyellow==-1))	{
	  fprintf(stderr, "\nError: unable to access gpio resource. Exit.\n");
	  exit(-1);
	}
	
	daemonize();
	log_message(LOG_FILE,"*Started*");
	
	/* apre la comunicazione con il device RTC */
	fd = open(rtc, O_RDONLY);
	if (fd ==  -1) {
		perror(rtc);
		exit(errno);
	}
	
	/* Read the RTC time/date */
	retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
	if (retval == -1) {
		perror("RTC_RD_TIME ioctl");
		exit(errno);
	}
	fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:%02d.\n",rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);

	/*initialize alarm*/	
	/* allarme ore in punto  o 30 minuti*/
	if (rtc_tm.tm_min<30)   {
		ring_tm=setNextHalfHourAlarm(rtc_tm);
	}
	else    {
		ring_tm=setNextHourAlarm(rtc_tm);
	}

	while(1){
	    /*Set the alarm*/
	    retval = ioctl(fd, RTC_ALM_SET, &ring_tm);
	    if (retval == -1) {
		if (errno == ENOTTY) {
		    fprintf(stderr,"\n...Alarm IRQs not supported.\n");
		}
		perror("RTC_ALM_SET ioctl");
		exit(errno);
	    }

	    /* Read the current alarm settings */
	    retval = ioctl(fd, RTC_ALM_READ, &ring_tm);
	    if (retval == -1) {
		perror("RTC_ALM_READ ioctl");
		exit(errno);
	    }
	    fprintf(stderr, "Alarm time now set to %02d:%02d:%02d.\n",ring_tm.tm_hour, ring_tm.tm_min, ring_tm.tm_sec);

	    fprintf(stderr, "Waiting for alarm...");
	    fflush(stderr);
	    
	    /* Enable alarm interrupts */
	    retval = ioctl(fd, RTC_AIE_ON, 0);
	    if (retval == -1) {
		perror("RTC_AIE_ON ioctl");
		exit(errno);
	    }

	    /* This blocks until the alarm ring causes an interrupt */
	    retval = read(fd, &data, sizeof(unsigned long));
	    if (retval == -1) {
		perror("read");
		exit(errno);
	    }
	    irqcount++;
	    fprintf(stderr, " okay! Alarm rang.\n");

	    /* Read the RTC time/date */
	    retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
	    if (retval == -1) {
		perror("RTC_RD_TIME ioctl");
		exit(errno);
	    }
	    if ((rtc_tm.tm_min == 00))  {
		/*play bells*/
		for (i=0;i<(ring_tm.tm_hour>12?ring_tm.tm_hour-12:ring_tm.tm_hour);i++) {
			playBell(&IDgreen,&IDbuzzer,2,&fd);	
			printf("\n %d\n",i+1);			
		}
		log_message(LOG_FILE,"Ora piena.");
		/*set next alarm*/
		ring_tm=setNextHalfHourAlarm(rtc_tm);
	    }
	    if ((rtc_tm.tm_min == 30))  {
		/*play bells*/
		playBell(&IDyellow,&IDbuzzer,2,&fd);	
		log_message(LOG_FILE,"Ora mezza.");
		/*set next alarm*/
		ring_tm=setNextHourAlarm(rtc_tm);
	    }
	    /* Disable alarm interrupts */
	    retval = ioctl(fd, RTC_AIE_OFF, 0);
	    if (retval == -1) {
		perror("RTC_AIE_OFF ioctl");
		exit(errno);
	    }
	}
	return 0;
}