예제 #1
0
int main (int argc, char *argv []) 
{
  lcd_init();
  
  SetChrMode(); 
  lcd_text("hello world!");
  SetCmdMode();
  lcd_gotoxy(1,2);
  SetChrMode();
  lcd_text("Luis");
  return 0 ;
}
/**
Wrtie some text on screen
**/
void lcd_text(char *s)
{
	SetChrMode();
	while(*s)
	lcd_byte(*s++);
	SetCmdMode();
}
예제 #3
0
파일: lcd.c 프로젝트: abyman/garage
void lcd_text(mraa_gpio_context *g, char *s, int line)
{
   SetCmdMode(g); // set to cmd mode to send line cmd
   if(line == 1) 
      lcd_byte(g, 0x80); // line 1
   else
      lcd_byte(g, 0xC0); // line 2
   SetChrMode(g); // set to char mode to send text
   while(*s) 
      lcd_byte(g, *s++);
}
예제 #4
0
파일: lcd.c 프로젝트: abyman/garage
void lcd_init(mraa_gpio_context *g)
{
   // set up pi pins for output
   g[0] = mraa_gpio_init(LCD_E);
   g[1] = mraa_gpio_init(LCD_RS);
   g[2] = mraa_gpio_init(LCD_D4);
   g[3] = mraa_gpio_init(LCD_D5);
   g[4] = mraa_gpio_init(LCD_D6);
   g[5] = mraa_gpio_init(LCD_D7);
   for(int i = 0; i < 6; i++) { 
      mraa_gpio_dir(g[i], MRAA_GPIO_OUT);
   }
   // initialise LCD
   SetCmdMode(g); // set for commands
   lcd_byte(g,0x33); // 2 line mode
   lcd_byte(g,0x32); // 2 line mode
   lcd_byte(g,0x06); // 2 line mode
   lcd_byte(g,0x0C); // 2 line mode
   lcd_byte(g,0x28); // display on, cursor off, blink off
   lcd_byte(g,0x01);  // clear screen
   usleep(3000);       // clear screen is slow!
   SetChrMode(g);
}
/**
* Program pooling a directory, and doing a scheduling.
**/
int main (int argc, char** argv)
{

	initPins();
	adc_init();
	lcd_init();
	
	/** The status does not exist at the launch of the schduler prgram*/
	clearFile();
	int pid=readPid();	
	stopIfPidExists(pid);
	writePid();
	
	SetChrMode();
	int nbSecond;
	int remainingSeconds;
	uchar intensity;
	uchar tmpintensity;
    int i;
	int valueInFile;
	time_t whenItsComplete ;
	char timestr[7];
	
	pinMode (RELAY_IN, OUTPUT);
	// Permanent loop checking file.
	int cycle=0;
	
	
	while(1){
		valueInFile=getCoundownValue();
		#ifndef PROD
		printf("pause:%d,valueInFile:%d\n",pauseSt,valueInFile);
		#endif
	
		if(valueInFile>=0){
			nbSecond=valueInFile;
		// The countdown
			whenItsComplete = time(NULL)+nbSecond;
			remainingSeconds=whenItsComplete-time(NULL);
		}
		else{remainingSeconds=-1;}
		#ifndef PROD
		printf("nbsecond:%d\n",nbSecond);
		#endif
	
	
		do {
	
	   /**
	   * Do a regular reset of the LCD
	   **/
		if(cycle%500==0){
		 lcd_init();
		}
		else if(cycle%60==0){
			resetLcd();
		}
		/**
		* Write the remaining seconds
		**/
		if(cycle%60==0){
		 writeRemaining(remainingSeconds);
		}
		

		/**
		* Increment only if not in pause (Cycle increments will be at the end of the cycle loop.
		**/	

		
		updateStandbyStatus();
		cycle++;

		
		
		if(remainingSeconds>-1){
		if(pauseSt==IS_RUNNING){
				remainingSeconds=whenItsComplete-time(NULL);
		}else{
			    whenItsComplete=remainingSeconds+time(NULL);
		}


				openRelay();
				if(lastImmobileState==0||(time(NULL)-lastImmobileState)<NBSECONDBEFORECREENSHUTDOWN){
				digitalWrite (TRANSISTOR, LOW);
				}
				else{
				digitalWrite (TRANSISTOR, HIGH);
				}
				int seconds=remainingSeconds%60;
				int hours=remainingSeconds/3600;
				int minutes=remainingSeconds/60%60;
			
				sprintf(timestr,"%02d:%02d:%02d",hours,minutes,seconds);
					
				goHome();
				lcd_text(timestr);
				#ifndef PROD
				printf("%s\n",timestr);
				#endif
				sleep(1);
		}
			/**
			* Block measuring intensity
			*/
			if(cycle%20==0){
				intensity=get_ADC_Result();
				#ifndef PROD
				printf("Intensite: %d\n",intensity);
				#endif
			}
			#ifndef PROD
			printf("Remaining seconds %d,cycle=%d\n",remainingSeconds,cycle);
			#endif

	} while ( remainingSeconds>0&& !isFilePresent());
	
		#ifndef PROD
	//	printf("Sortie boucle décompte\n");
		#endif
			
		/**
		* Every 10 ccyle there is a full reset of the screen. Otherwise it is  light reset.
		**/
	
		if(cycle%100==0){
			lcd_init();
		}
		nbSecond=0;
		/**
		*
		**/
		if(valueInFile==NO_FILE){
			goHome();
			closeRelay();
			digitalWrite (TRANSISTOR, HIGH);
			lcd_text("Expire    " );
			#ifndef PROD
			printf("Expire\n");
			#endif
		}
			else if(valueInFile==TV_ON){
			goHome();
			openRelay();
			digitalWrite (TRANSISTOR, LOW);
			lcd_text("Tele on      " );
			}
		else if(valueInFile==TV_OFF){
			goHome();
			digitalWrite (TRANSISTOR, HIGH);
			closeRelay();
			lcd_text("Tele off      " );
		}
		sleep(3);
	}
}