コード例 #1
0
ファイル: reflowControl.c プロジェクト: junglejim63/pi-reflow
/***************************************************************************
shutdown logic - turn off all pins, stop SPI devices, 
***************************************************************************/
void shutdown() {
   //close ads
   int localSemaphore = 0;
   close(ads_fd);
   //turn off LCD
   lcd_clear();
	lcd_display_string(0,"   Shut down", &localSemaphore);
	lcd_display_string(1,"*** Goodbye ***", &localSemaphore);
   close(lcd_fd);
   //turn off GPIO pins by setting them back to inputs
   INP_GPIO(SSR1_GPIO); //reset output pin to High-Z input
   INP_GPIO(BUZZER_GPIO); //reset output pin to High-Z input

   exit(0);
}
コード例 #2
0
ファイル: frame_timeout.c プロジェクト: spectrum70/gasc
static void on_button_numeric()
{
	int cmd_id = ui_get_cmd_id();

	if (cursor < 5) {
		to_sec[cursor]   = ((cmd_id - id_num_0) + 0x30);
		to_sec[cursor+1] = 0;

		cursor++;

		lcd_display_string(180, 120, to_sec, LCD_YELLOW);
	}
}
/**
 * @brief Thread function of LCD 
 * @param Not used
 * @retval None
 */
void lcd_thread(void const * argument)
{
  while (1)
  {
    osSemaphoreWait (lcd_semaphore, osWaitForever);
    if (getThreadToRun() == MODE_1)
    {
      //Accelerometer mode
      lcd_set_display_angles(getFilteredRollAngle(),getFilteredPitchAngle());
      lcd_display_string(line1, line2);
    }
  }
}
コード例 #4
0
void sig_handler(int signo)
{
  if (signo == SIGINT)
    printf("received SIGINT\n");
  if (dofile)
  {
  	fclose(outfile);
  }
  close(ads_fd);
  lcd_clear();
	lcd_display_string(1,"Bye");
  close(lcd_fd);
  printf("Bye\n");
  exit(0);
}
コード例 #5
0
ファイル: LCD.cpp プロジェクト: mkadrummond/bachelorThesis
// put int function
// the additional lines (5 to 8) are for placing the
// cursor along the right hand side of the display
void LCD::lcd_display_int(int var, int line) {
	if (line == 1)
    	lcd_write(0x80, 0);
	if (line == 2)
    	lcd_write(0xC0, 0);
	if (line == 3)
		lcd_write(0x94, 0);
	if (line == 4)
		lcd_write(0xD4, 0);
	if (line == 5)
    	lcd_write(0x90, 0);
	if (line == 6)
    	lcd_write(0xD0, 0);
	if (line == 7)
    	lcd_write(0xA4, 0);
	if (line == 8)
    	lcd_write(0xE4, 0);

	char buffer[10];

	// These if statements arrange the integer
	// nicely against the edge of the display
	if (var > 999 && var < 10000) {
		snprintf(buffer, 10, "%d", var);
	}
	if (var > 99 && var < 1000) {
		snprintf(buffer, 10, " %d", var);
	}
	if (var > 9 && var < 100) {
		snprintf(buffer, 10, "  %d", var);
	} if (var > -1 && var < 10) {
		snprintf(buffer, 10, "   %d", var);
	}

	lcd_display_string(buffer, line);

}
コード例 #6
0
ファイル: LCD.cpp プロジェクト: mkadrummond/bachelorThesis
// put float function
// the additional lines (5 to 8) are for placing the
// cursor along the right hand side of the display
void LCD::lcd_display_float(float var, int line) {
	if (line == 1)
    	lcd_write(0x80, 0);
	if (line == 2)
    	lcd_write(0xC0, 0);
	if (line == 3)
		lcd_write(0x94, 0);
	if (line == 4)
		lcd_write(0xD4, 0);
	if (line == 5)
    	lcd_write(0x90, 0);
	if (line == 6)
    	lcd_write(0xD0, 0);
	if (line == 7)
    	lcd_write(0xA4, 0);
	if (line == 8)
    	lcd_write(0xE4, 0);

	char buffer[10];

	snprintf(buffer, 10, "%.2f", var);

	lcd_display_string(buffer, line);
}
コード例 #7
0
ファイル: main.c プロジェクト: armonico/LCD22
int main(void)
{

	//DDRA=0XFF;
	//PORTA=0X00;

	//DDRE &= ~(1<<PE4);
	//PORTE &= ~(1<<PE4);	


	DDRD=0XFF;
	
	//void SPI0_Init(void)
	DDRB=0xff;			// make port as a output
	PORTB=0X00;		//disable pull-ups and make it tri state

	SPCR=0x50;          //SPI , SPI FOSC/16
	SPSR=0x00;			//setup SPI

	//  reser LCD
	PORTB &= ~(1<<PB1);		//PB6 -> PB1
	_delay_us(5);
	PORTB |= (1<<PB1);
	_delay_us(5);

	
	LCD_WRITE_COMMAND( 0x000, 0x0001 ); /* oschilliation start */
	_delay_us( 10 );
	/* Power settings */  	
	LCD_WRITE_COMMAND( 0x100, 0x0000 ); /*power supply setup*/	
	LCD_WRITE_COMMAND( 0x101, 0x0000 ); 
	LCD_WRITE_COMMAND( 0x102, 0x3110 ); 
	LCD_WRITE_COMMAND( 0x103, 0xe200 ); 
	LCD_WRITE_COMMAND( 0x110, 0x009d ); 
	LCD_WRITE_COMMAND( 0x111, 0x0022 ); 
	LCD_WRITE_COMMAND( 0x100, 0x0120 ); 
	_delay_us( 20 );

	LCD_WRITE_COMMAND( 0x100, 0x3120 );
	_delay_us( 80 );
	/* Display control */   
	LCD_WRITE_COMMAND( 0x001, 0x0100 );
	LCD_WRITE_COMMAND( 0x002, 0x0000 );
	LCD_WRITE_COMMAND( 0x003, 0x1230 );
	LCD_WRITE_COMMAND( 0x006, 0x0000 );
	LCD_WRITE_COMMAND( 0x007, 0x0101 );
	LCD_WRITE_COMMAND( 0x008, 0x0808 );
	LCD_WRITE_COMMAND( 0x009, 0x0000 );
	LCD_WRITE_COMMAND( 0x00b, 0x0000 );
	LCD_WRITE_COMMAND( 0x00c, 0x0000 );
	LCD_WRITE_COMMAND( 0x00d, 0x0018 );
	/* LTPS control settings */   
	LCD_WRITE_COMMAND( 0x012, 0x0000 );
	LCD_WRITE_COMMAND( 0x013, 0x0000 );
	LCD_WRITE_COMMAND( 0x018, 0x0000 );
	LCD_WRITE_COMMAND( 0x019, 0x0000 );

	LCD_WRITE_COMMAND( 0x203, 0x0000 );
	LCD_WRITE_COMMAND( 0x204, 0x0000 );

	LCD_WRITE_COMMAND( 0x210, 0x0000 );
	LCD_WRITE_COMMAND( 0x211, 0x00ef );
	LCD_WRITE_COMMAND( 0x212, 0x0000 );
	LCD_WRITE_COMMAND( 0x213, 0x013f );
	LCD_WRITE_COMMAND( 0x214, 0x0000 );
	LCD_WRITE_COMMAND( 0x215, 0x0000 );
	LCD_WRITE_COMMAND( 0x216, 0x0000 );
	LCD_WRITE_COMMAND( 0x217, 0x0000 );

	// Gray scale settings
	LCD_WRITE_COMMAND( 0x300, 0x5343);
	LCD_WRITE_COMMAND( 0x301, 0x1021);
	LCD_WRITE_COMMAND( 0x302, 0x0003);
	LCD_WRITE_COMMAND( 0x303, 0x0011);
	LCD_WRITE_COMMAND( 0x304, 0x050a);
	LCD_WRITE_COMMAND( 0x305, 0x4342);
	LCD_WRITE_COMMAND( 0x306, 0x1100);
	LCD_WRITE_COMMAND( 0x307, 0x0003);
	LCD_WRITE_COMMAND( 0x308, 0x1201);
	LCD_WRITE_COMMAND( 0x309, 0x050a);

	/* RAM access settings */ 
	LCD_WRITE_COMMAND( 0x400, 0x4027 );
	LCD_WRITE_COMMAND( 0x401, 0x0000 );
	LCD_WRITE_COMMAND( 0x402, 0x0000 );	/* First screen drive position (1) */   	
	LCD_WRITE_COMMAND( 0x403, 0x013f );	/* First screen drive position (2) */   	
	LCD_WRITE_COMMAND( 0x404, 0x0000 );

	LCD_WRITE_COMMAND( 0x200, 0x0000 );
	LCD_WRITE_COMMAND( 0x201, 0x0000 );
	
	LCD_WRITE_COMMAND( 0x100, 0x7120 );
	LCD_WRITE_COMMAND( 0x007, 0x0103 );
	_delay_us( 10 );
	LCD_WRITE_COMMAND( 0x007, 0x0113 );


	_delay_us(20);
	
	//while(1)
	//{
		lcd_clear_screen(WHITE);
		lcd_display_string( "Hello world!!!    ", BLACK, GREEN, 0, 0 );
		lcd_display_string( "I am Happy.^o^    ", BLACK, ORANGE, 0, 1 );
		lcd_display_string( "CPU:ATMAGE328A-AU          ", BLACK, PINK, 0, 2 );
		

	//}

	
		
         // wait for a second
	
	/*
//	_delay_ms(5000);
	while(1)
	{
		read_res=Read_Continue();
		lcd_draw_bigdot(BLACK,(touch_dot.x-20),(touch_dot.y-2));
//		for(i=0;i<100;i++)
//		{
//			lcd_draw_bigdot(BLACK,50,i);
//		}
//		lcd_draw_line(BLACK,0,0,20,20);
	
	}
	*/
}
コード例 #8
0
ファイル: main.c プロジェクト: LamDinh/smart210
int main()
{
	int fbfd = 0;
	long int screensize = 0;
	int x = 0, y = 0;
	long int location = 0;
	char date_str[22], time_str[10], date_str_tmp[22], time_str_tmp[10];
	
	rtc_dev = 0;
	/* Open the file for reading and writing */
	rtc_dev  = open("/dev/rtc", O_RDWR);
	if (rtc_dev < 0)
	{
		fprintf(stderr, "- Error: Can not open RTC device, rtc_dev = %d\n", rtc_dev);
		return -1;
	}

	fprintf(stderr, "RTC device was opened successfully.\n");

	/* Open the file for reading and writing */
	fbfd = open("/dev/fb0", O_RDWR);
	if (!fbfd) {
		fprintf(stderr, "Error: cannot open framebuffer device.\n");
		return -1;
	}
	fprintf(stderr, "The framebuffer device was opened successfully.\n");

	//Get fixed screen information
	if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo)) {
		fprintf(stderr, "Error reading fixed information.\n");
		return -1;
	}

	//Get variable screen information
	if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
		fprintf(stderr, "Error reading variable information.\n");
		return -1;
	}

	//Figure out the size of the screen in bytes
	screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

	//Map the device to memory
	fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
	if ((int)fbp == -1) {
		fprintf(stderr, "Error: failed to map frame buffer device to memory.\n");
		return -1;
	}
	fprintf(stderr, "The frame buffer device was mapped to memory successfully.\n");

//	lcd_display_picture(gImage_filmframe,0,0);
//	lcd_clear(PINK_COLOR);

	lcd_display_bmp_picture("/LAM/LoveDream.bmp", 0, 0);
	lcd_display_string("IS FROM A", FONT36, 390, 220, BLUE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/LoveAngel.bmp", 0, 0);
	lcd_display_string("SOMEWHERE IN THE WORLD...", FONT28, 120, 70, BLUE_COLOR, CURRENT_COLOR);
	lcd_display_string("GOD PREPARED A PARTNER FOR YOU.", FONT28, 40, 380, YELLOW_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/TreeCouple.bmp", 0, 0);
	lcd_display_string("AS COUPLE OF TREES", FONT28, 20, 50, RED_COLOR, CURRENT_COLOR);
	lcd_display_string("GROW UP TOGETHER", FONT28, 400, 100, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/CoupleOfSwan.bmp", 0, 0);
	lcd_display_string("AS COUPLE OF SWANS", FONT28, 20, 20, WHITE_COLOR, CURRENT_COLOR);
	lcd_display_string("SWIM SIDE BY SIDE", FONT28, 400, 70, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/CoupleOfBirds.bmp", 0, 0);
	lcd_display_string("AS COUPLE OF BIRDS", FONT28, 20, 20, WHITE_COLOR, CURRENT_COLOR);
	lcd_display_string("WELCOME SUNRISE WITH A KISS", FONT28, 180, 70, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/BookAndHeart.bmp", 0, 0);
	lcd_display_string("AND YOU ARE THE LOVE", FONT28, 20, 20, PINK_COLOR, CURRENT_COLOR);
	lcd_display_string("WHO GOD PREPARED FOR ME.", FONT28, 100, 420, BLUE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/HandInHand.bmp", 0, 0);
	lcd_display_string("WE ARE HAND IN HAND,", FONT28, 50, 390, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/LovelySky.bmp", 0, 0);
	lcd_display_string("AND WALK TOGETHER", FONT28, 50, 300, RED_COLOR, CURRENT_COLOR);
	lcd_display_string("ON THE LOVING ROAD.", FONT28, 350, 350, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/FlyingLoveMail.bmp", 0, 0);
	lcd_display_string("IT STARTED BY LOVELY MESSAGES", FONT28, 50, 50, PINK_COLOR, CURRENT_COLOR);
	lcd_display_string("EVERY DAY,", FONT36, 470, 90, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Love_Fan.bmp", 0, 0);
	lcd_display_string("AND SWEET WORDS WE SAID,", FONT28, 90, 390, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Rose.bmp", 0, 0);
	lcd_display_string("AND BEAUTIFUL ROSES.", FONT28, 50, 20, BLUE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/HappyCouple1.bmp", 0, 0);
	lcd_display_string("BESIDE YOU, I ALWAYS FEEL HAPPY,", FONT28, 50, 20, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/HappyCouple2.bmp", 0, 0);
	lcd_display_string("AND SMILE A LOT.", FONT28, 420, 410, GREEN_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/HappyCouple3.bmp", 0, 0);
	lcd_display_string("I GO WITH YOU TO THE PLACES", FONT28, 20, 10, WHITE_COLOR, CURRENT_COLOR);
	lcd_display_string("WHERE I HAVE NEVER GONE BEFORE,", FONT28, 20, 410, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/RunningBird.bmp", 0, 0);
	lcd_display_string("AND I ALSO DO", FONT28, 20, 380, GREEN_COLOR, CURRENT_COLOR);
	lcd_display_string("WHAT I HAVE NEVER DONE BEFORE,", FONT28, 90, 420, GREEN_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/GiangDien7.bmp", 0, 0);
	lcd_display_string("JUST TO SEE YOUR SMILE,", FONT28, 150, 20, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/MangoGarden.bmp", 0, 0);
	lcd_display_string("AND TO SEE YOUR HAPPINESS.", FONT28, 110, 390, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/WaterFall.bmp", 0, 0);
	lcd_display_string("LOVE IS SOMETIME AS A WATERFALL", FONT28, 50, 230, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/GiangDien3.bmp", 0, 0);
	lcd_display_string("IT IS RUGGED,", FONT28, 50, 380, RED_COLOR, CURRENT_COLOR);
	lcd_display_string("BUT MAKING US HAPPIER.", FONT28, 180, 420, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/GiangDien4.bmp", 0, 0);
	lcd_display_string("LOVE IS ALSO PEACE AS A FIELD,", FONT28, 80, 380, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Stream.bmp", 0, 0);
	lcd_display_string("WHERE WE ENJOY THE LIFE STREAM.", FONT28, 60, 420, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/GiangDien5.bmp", 0, 0);
	lcd_display_string("LOVE IS ALSO AS THE FLOWER,", FONT28, 100, 20, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/GiangDien6.bmp", 0, 0);
	lcd_display_string("MAKING OUR LIFE IS MORE BEAUTIFUL.", FONT28, 50, 80, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/SweetLove.bmp", 0, 0);
	lcd_display_string("LOVE IS SWEET,", FONT28, 260, 50, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/LoveCoffeeCup.bmp", 0, 0);
	lcd_display_string("SOMETIME ASLO BE BITTER,", FONT28, 50, 20, BLACK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Park1.bmp", 0, 0);
	lcd_display_string("BUT YOUR SMILE MAKE ME HAPPY.", FONT28, 50, 50, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/SantaCruz.bmp", 0, 0);
	lcd_display_string("WHEN I GO ANYWHERE,", FONT28, 300, 390, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/ButterFly.bmp", 0, 0);
	lcd_display_string("OR JUST LEAVE YOU A SHORT TIME,", FONT28, 50, 50, BLUE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/MissingMessage.bmp", 0, 0);
	lcd_display_string("I MISS YOU SO MUCH.", FONT28, 50, 130, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Kissing_message.bmp", 0, 0);
	lcd_display_string("MISS YOUR KISS,", FONT28, 350, 130, PINK_COLOR, CURRENT_COLOR);
	lcd_display_string("YOUR HUG,", FONT28, 100, 330, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/PrayWithBirthdayCake24.bmp", 0, 0);
	lcd_display_string("MISS YOUR INGENUITY,", FONT28, 350, 50, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Birthday25.bmp", 0, 0);
	lcd_display_string("MISS OUR SWEET MEMORIES,", FONT28, 120, 30, PINK_COLOR, CURRENT_COLOR);
	sleep(5);

	lcd_display_bmp_picture("/LAM/RiverSide.bmp", 0, 0);
	lcd_display_string("MISS THE BEAUTIFUL PLACES WE COME,", FONT28, 30, 30, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/NguyenKim.bmp", 0, 0);
	lcd_display_string("LIKE THIS,", FONT28, 325, 50, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Park2.bmp", 0, 0);
	lcd_display_string("MISS YOUR SMILE,", FONT28, 415, 410, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Lotus1.bmp", 0, 0);
	lcd_display_string("MISS YOU A LOT. . .", FONT28, 50, 20, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/Lotus2.bmp", 0, 0);
	lcd_display_string("A LOT. . .", FONT28, 190, 400, PINK_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/SunRise.bmp", 0, 0);
	lcd_display_string("DAY BY DAY, FROM SUNRISE,", FONT28, 150, 30, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/NighAndMoon.bmp", 0, 0);
	lcd_display_string("TO MOONRISE,", FONT28, 280, 220, WHITE_COLOR, CURRENT_COLOR);
	sleep(7);

	lcd_display_bmp_picture("/LAM/ILoveU.bmp", 0, 0);
	lcd_display_string("I JUST WANNA TO SAY:", FONT28, 50, 50, BLUE_COLOR, CURRENT_COLOR);
	sleep(7);

	//lcd_display_bmp_picture("/LAM/WillYouMarryMe.bmp", 0, 0);
	//sleep(100);
	lcd_display_bmp_picture("/LAM/BrideGroom1.bmp", 0, 0);
	lcd_display_string("I'M SO HAPPY", FONT28, 90, 15, RED_COLOR, CURRENT_COLOR);
	lcd_display_string("THAT I MARRIED YOU", FONT28, 10, 55, RED_COLOR, CURRENT_COLOR);
	sleep(7);

	//lcd_display_bmp_picture("/LAM/KissingCouple.bmp", 0, 0);
	lcd_display_bmp_picture("/LAM/BrideGroom2.bmp", 0, 0);	
	lcd_display_string("KEEP THE TIME WE HAVE TOGETHER", FONT28, 40, 20, PINK_COLOR, CURRENT_COLOR);
	lcd_display_string("HAPPILY", FONT36, 310, 60, PINK_COLOR, CURRENT_COLOR);
	lcd_display_character(127, FONT36, 510, 60, RED_COLOR, CURRENT_COLOR); //heart
	lcd_display_character(127, FONT36, 270, 60, RED_COLOR, CURRENT_COLOR); //heart

	memset(date_str, 0, sizeof(date_str));
	memset(time_str, 0, sizeof(time_str));
	memset(date_str_tmp, 0, sizeof(date_str_tmp));
	memset(time_str_tmp, 0, sizeof(time_str_tmp));
	lcd_draw_rectangle(0,799,420, 479, PINK_COLOR, 1);
	while(1) {
		get_date_time(date_str, time_str);
		if (strcmp(date_str, date_str_tmp) != 0) {
			lcd_display_string(date_str, FONT36, 50, 420, BLUE_COLOR, PINK_COLOR);
		}
		if (strcmp(time_str, time_str_tmp) != 0) {
			lcd_display_string(time_str, FONT36, 600, 420, BLUE_COLOR, PINK_COLOR);
		}
		memset(date_str_tmp, 0, sizeof(date_str_tmp));
		memset(time_str_tmp, 0, sizeof(time_str_tmp));
		strcpy(date_str_tmp, date_str);
		strcpy(time_str_tmp, time_str);
		memset(date_str, 0, sizeof(date_str));
		memset(time_str, 0, sizeof(time_str));
		sleep(1);
	}

	munmap(fbp, screensize);
	close(fbfd);
	close(rtc_dev);
	return 0;
}
コード例 #9
0
ファイル: reflowControl.c プロジェクト: junglejim63/pi-reflow
/***************************************************************************
main program
***************************************************************************/
int main(int argc, char* argv[]) {
   /***************************************************************************
   Initialize variables
   ***************************************************************************/
   int ret;
   unsigned int n = 0;
   //----- SET SPI MODE -----
   //SPI_MODE_0 (0,0) 	CPOL = 0, CPHA = 0, Clock idle low, data is clocked in on rising edge, output data (change) on falling edge
   //SPI_MODE_1 (0,1) 	CPOL = 0, CPHA = 1, Clock idle low, data is clocked in on falling edge, output data (change) on rising edge
   //SPI_MODE_2 (1,0) 	CPOL = 1, CPHA = 0, Clock idle high, data is clocked in on falling edge, output data (change) on rising edge
   //SPI_MODE_3 (1,1) 	CPOL = 1, CPHA = 1, Clock idle high, data is clocked in on rising, edge output data (change) on falling edge
   uint8_t lcd_spi_config = SPI_MODE_0;
 	uint8_t ads_spi_config = SPI_MODE_1;
   int ShmID;
   pid_t pid_stdin;
   pid_t pid_pwm;
   
   Controller *ctlPTR;  //this is the key structure that holds all the shared data.
   
   /***************************************************************************
   setup shared memory
   ***************************************************************************/
   ShmID = shmget(IPC_PRIVATE, sizeof(Controller), IPC_CREAT | 0666);
   if (ShmID < 0) {
		fprintf(stderr,"reflowControl Exiting - could not initialize shared memory area (shmget)\n");
      exit(1);
   }
   ctlPTR = (Controller *) shmat(ShmID, NULL, 0); //assign controller 
   if ((void *) ctlPTR == (void *) -1) {
		fprintf(stderr,"reflowControl Exiting - could not attach to shared memory area (shmat)\n");
      exit(1);
   }
   initializePID(ctlPTR);
   
   /***************************************************************************
   setup ADS, LCD, other GPIO
   ***************************************************************************/
   sleep(2); //sleep for 2 seconds at start to make sure Node program has started listening for IO streams
   //make sure output is not buffered (this program generally a child to a nodejs program) and set signal handler
   setbuf(stdout, NULL); //set stdout to not buffer output
   setbuf(stderr, NULL); //set stderr to not buffer output
   signal(SIGINT, sig_handler_main);  //capture signal interrupt ^C to cleanly shutdown
   signal(SIGTERM, sig_handler_main); //capture process termination signal to cleanly shutdown
   //Initialize GPIO - see http://elinux.org/RPi_Low-level_peripherals#C_2
   // Set up gpi pointer for direct register access
   setup_io();
   // Set GPIO pin 23 SSR1_GPIO to output
   INP_GPIO(SSR1_GPIO); // must use INP_GPIO before we can use OUT_GPIO
   OUT_GPIO(SSR1_GPIO);
   GPIO_CLR = 1<<SSR1_GPIO; //make sure output is turned off
   // Set GPIO pin 22 BUZZER_GPIO to output
   INP_GPIO(BUZZER_GPIO); // must use INP_GPIO before we can use OUT_GPIO
   OUT_GPIO(BUZZER_GPIO);
   GPIO_SET = 1<<BUZZER_GPIO; //make sure output is turned off - Buzzer is PNP, so pin high is buzzer off.
   // Set GPIO pin 17 LCD_RS_GPIO to output
   INP_GPIO(LCD_RS_GPIO); // must use INP_GPIO before we can use OUT_GPIO
   OUT_GPIO(LCD_RS_GPIO);
   // Initialize LCD
	ret = spi_open(&lcd_fd, 0, lcd_spi_config);  //initialize lcd_fd, 0 means device 0 (LCD), SPI_MODE_0
	if (ret != 0) {
		fprintf(stderr,"reflowControl Exiting - Could not initialize LCD\n");
		exit(1);
	}
	lcd_init();
	lcd_clear();					            // LCD clear
   
	lcd_display_string(0,"Reflow Start", &ctlPTR->spiSemaphore);	// display startup message
   // Initialize ADS Thermocouple chip
	ret=spi_open(&ads_fd, 1, ads_spi_config);
	if (ret != 0) {
		fprintf(stderr,"reflowControl Exiting - could not initialize ADS thermocouple chip\n");
		exit(1);
	}

   /***************************************************************************
   fork child process to manage SSR
   ***************************************************************************/
   pid_pwm = fork();
   switch(pid_pwm) {
   case -1:
		fprintf(stderr,"reflowControl Exiting - could not fork a child process for PWM (fork)\n"); exit(1);
      break;
   case 0: //child process
      child_main(ctlPTR);
      break;
   default: //main process
      printf("{\"item\": \"childProcess\", \"value\": \"PID_PWM\", \"pid\": %d}\n", pid_pwm);
      /***************************************************************************
      fork child process to manage stdin
      ***************************************************************************/
      pid_stdin = fork();
      switch(pid_stdin) {
      case -1:
         fprintf(stderr,"reflowControl Exiting - could not fork a child process for stdin (fork)\n"); exit(1);
         break;
      case 0: //child process
         stdin_main(ctlPTR);
         break;
      default: //main process
         printf("{\"item\": \"childProcess\", \"value\": \"PID_STDIN\", \"pid\": %d}\n", pid_stdin);
         while (1) {
            n++;
            delay_ms(MS_SAMPLES);
            sampleTemp(&ctlPTR->tc1, &ctlPTR->spiSemaphore);
            if (n >= NSAMPLES) {
               ctlPTR->tc1.value = sampleMean(&ctlPTR->tc1);
               ctlPTR->tc1.stdev = sampleStddev(&ctlPTR->tc1);
               printMeasurementJSON(&ctlPTR->tc1);
               ctlPTR->tc1.n = 0;
               ctlPTR->pv = ctlPTR->tc1.value;
               n = 0;
            }
         }
         break;
      }
   }
   //exit
   kill(pid_pwm, SIGKILL);
   shutdown();
   return(0);
}
コード例 #10
0
ファイル: reflowControl.c プロジェクト: junglejim63/pi-reflow
/***************************************************************************
Process Commands received by Main
***************************************************************************/
void command(char* input, Controller* ctlPtrCmd) {
   // char cmd[100];
   char *cmd;
   cmd = malloc(100 * sizeof(char));
   int int1;
   float float1;
   
   input[strlen(input)-1] = 0;  //strip off \n
   sscanf(input, "%s", cmd);
   //printf("Command: %s\n", cmd);
   if (strcmp(cmd, "beep_mode") == 0) {
      sscanf(input, "%s %d", cmd, &int1);
      ctlPtrCmd->beep_mode = int1;
      printf("{\"item\": \"Command\", \"command\": \"beep_mode\", \"value\": %d, \"string\": \"%s\"}\n", int1, input);
   } else if (strcmp(cmd, "lcd0") == 0) {
      lcd_display_string(0, input + 5, &ctlPtrCmd->spiSemaphore);
      printf("{\"item\": \"Command\", \"command\": \"lcd0\", \"value\": \"%s\", \"string\": \"%s\"}\n", input + 5, input);
   } else if (strcmp(cmd, "lcd1") == 0) {
      lcd_display_string(1, input + 5, &ctlPtrCmd->spiSemaphore);
      printf("{\"item\": \"Command\", \"command\": \"lcd1\", \"value\": \"%s\", \"string\": \"%s\"}\n", input + 5, input);
   } else if (strcmp(cmd, "mode") == 0) {
      sscanf(input, "%s %d", cmd, &int1);
      ctlPtrCmd->mode = int1;
      printf("{\"item\": \"Command\", \"command\": \"mode\", \"value\": %d, \"string\": \"%s\"}\n", int1, input);
   } else if (strcmp(cmd, "out") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->out = limit(ctlPtrCmd->outLo, float1, ctlPtrCmd->outHi);
      printf("{\"item\": \"Command\", \"command\": \"out\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->out, input);
   } else if (strcmp(cmd, "sp") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->sp = limit(ctlPtrCmd->SPLo, float1, ctlPtrCmd->SPHi);
      printf("{\"item\": \"Command\", \"command\": \"sp\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->sp, input);
   } else if (strcmp(cmd, "Kp") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->Kp = float1;
      printf("{\"item\": \"Command\", \"command\": \"Kp\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->Kp, input);
   } else if (strcmp(cmd, "Ti") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->Ti = limit(0.0, float1, 10000.0);
      printf("{\"item\": \"Command\", \"command\": \"Ti\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->Ti, input);
   } else if (strcmp(cmd, "Td") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->Td = limit(0.0, float1, 300.0);
      printf("{\"item\": \"Command\", \"command\": \"Td\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->Td, input);
   } else if (strcmp(cmd, "Bias") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->Bias = limit(ctlPtrCmd->outLo, float1, ctlPtrCmd->outHi);
      printf("{\"item\": \"Command\", \"command\": \"Bias\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->Bias, input);
   } else if (strcmp(cmd, "outHi") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->outHi = limit(ctlPtrCmd->outLo + FLOAT0, float1, 10000.0);
      printf("{\"item\": \"Command\", \"command\": \"outHi\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->outHi, input);
   } else if (strcmp(cmd, "outLo") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->outLo = limit(0.0, float1, ctlPtrCmd->outHi - FLOAT0);
      printf("{\"item\": \"Command\", \"command\": \"outLo\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->outLo, input);
   } else if (strcmp(cmd, "SPHi") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->SPHi = limit(ctlPtrCmd->SPLo + FLOAT0, float1, 1000000.0);
      printf("{\"item\": \"Command\", \"command\": \"SPHi\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->SPHi, input);
   } else if (strcmp(cmd, "SPLo") == 0) {
      sscanf(input, "%s %f", cmd, &float1);
      ctlPtrCmd->SPLo = limit(-1000000.0, float1, ctlPtrCmd->SPHi - FLOAT0);
      printf("{\"item\": \"Command\", \"command\": \"SPLo\", \"value\": %f, \"string\": \"%s\"}\n", ctlPtrCmd->SPLo, input);
   } else {
      printf("{\"item\": \"Command\", \"command\": \"INVALID\", \"value\": null, \"string\": \"%s\"}\n", input);
   }
   return;
}
コード例 #11
0
int
main(int argc, char* argv[])
{
	int ret;
	int i;
	uint8_t spi_config=0;
	double tval;
	int repeat=0;
	int period=1;
	char fname[128];
	char tstring[128];
	char tstring2[128];
	time_t mytime;
	time_t desiredtime;
	struct timespec tstime;
	int not_finished=1;
	int elapsed=0;
	int showtime=0;
	
	// initialise GPIO
	setup_io();
	INP_GPIO(LCD_RS_GPIO); // must use INP_GPIO before we can use OUT_GPIO
  OUT_GPIO(LCD_RS_GPIO);
	
	// parse inputs
	dofile=0;
	if (argc>2)
	{
		if (strcmp(argv[1], "msg")==0) // print to the lcd
		{
			spi_config=0;
			ret=spi_open(&lcd_fd, 0, spi_config);
			if (ret!=0)
			{
				printf("Exiting\n");
			exit(1);
			}
			lcd_display_string(0,argv[2]);
			close(lcd_fd);
			exit(0);
		}
	}
	if (argc>1)
	{
		if (strcmp(argv[1], "-h")==0) // print help
		{
			printf("%s [sec] [filename]\n", argv[0]);
			printf("%s msg <message in quotes>\n", argv[0]);
			exit(0);
		}
		if (strcmp(argv[1], "lcdinit")==0) // initialize the LCD display
		{
			spi_config=0;
			ret=spi_open(&lcd_fd, 0, spi_config);
			if (ret!=0)
			{
				printf("Exiting\n");
				exit(1);
			}
			lcd_init();
			close(lcd_fd);
			exit(0);
		}
		if (strcmp(argv[1], "withtime")==0)
		{
			showtime=1;
		}
		else
		{
			sscanf(argv[1], "%d", &period); // period between measurements
			repeat=1;
		}
		if (argc>3)
		{
			if (strcmp(argv[2], "msg")==0) // print to the lcd
			{
				spi_config=0;
				ret=spi_open(&lcd_fd, 0, spi_config);
				if (ret!=0)
				{
					printf("Exiting\n");
					exit(1);
				}
				lcd_init();
				lcd_display_string(0,argv[3]);
				lcd_initialised=1;
			}
		}
	}
	if (argc>2)
	{
		strcpy(fname, argv[2]); // file name
		dofile=1;
		if (argc>4)
		{
			if (strcmp(argv[3], "msg")==0) // print to the lcd
			{
				spi_config=0;
				ret=spi_open(&lcd_fd, 0, spi_config);
				if (ret!=0)
				{
					printf("Exiting\n");
					exit(1);
				}
				lcd_init();
				lcd_display_string(0,argv[4]);
				lcd_initialised=1;
			}
		}
	}
	
	if (dofile)
	{
		outfile=fopen(fname, "w");
	}
	
	// open SPI for ADS1118
	spi_config |= SPI_CPHA;
	ret=spi_open(&ads_fd, 1, spi_config);
	if (ret!=0) // SPI error
	{
		printf("Exiting\n");
		exit(1);
	}

	if (repeat==0)
	{
		// display a single measurement and exit
		tval=get_measurement();
		if (showtime)
		{
			mytime = time(NULL);
			sprintf(tstring, "%d", mytime);
			unixtime2string(tstring, tstring2);
			printf("%s %#.1f\n", tstring2, tval);
		}
		else
		{
			printf("%#.1f\n", tval);
		}
		close(ads_fd);
		exit(0);
	}
	
	// open up SPI for LCD
  spi_config=0;
	ret=spi_open(&lcd_fd, 0, spi_config);
	if (ret!=0)
	{
		printf("Exiting\n");
		exit(1);
	}

	if (lcd_initialised==0)
		lcd_init();
	
	if (dofile)
	{
		// line 1 of the output file will contain the three column descriptions
		fprintf(outfile, "Time HH:MM:SS,Elapsed Sec,Temp C\n");
	}
	
	// Align on an integer number of seconds and get current time
  mytime = time(NULL);
  tstime.tv_sec=mytime+1;
  tstime.tv_nsec=0;
  clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &tstime, NULL);
  mytime++;
  desiredtime=mytime;

	signal(SIGINT, sig_handler);
	
	while(not_finished)
	{
		tval=get_measurement();
		for (i=1; i<10; i++)
		{
			delay_ms(10);
			tval=tval+get_measurement_fast();
		}
		tval=tval/10;
		
		// print the time, elapsed counter and temperature
		sprintf(tstring, "%d", mytime);
		unixtime2string(tstring, tstring2);
		if (mytime==desiredtime)
		{
			printf("%s %d %#.1f\n", tstring2, elapsed, tval);
			if (dofile)
			{
				fprintf(outfile, "%s,%d,%#.1f\n", tstring2, elapsed, tval);
				fflush(outfile);
			}
			desiredtime=desiredtime+period;
		}
		sprintf(tstring, "%s %#.1f", tstring2, tval);
		lcd_display_string(1, tstring);
		// now we sleep for a certain time
		mytime++;
		tstime.tv_sec=mytime;
		elapsed++;
		clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &tstime, NULL);
	}
	
  close(ads_fd);
    
  // LCD requires opposite clock polarity
  spi_config=0;
	ret=spi_open(&lcd_fd, 0, spi_config);
	if (ret!=0)
	{
		printf("Exiting\n");
		exit(1);
	}


	lcd_init();
	lcd_clear();					// LCD clear
	lcd_display_string(0,"Hello");	// display "ADS1118"
  
  close(lcd_fd);
  
  return(0);
}
コード例 #12
0
ファイル: lcd.c プロジェクト: janstrohbeck/pic24template
void lcd_display_long_string (c8_t *pac8string, uint16_t u16delay)
{
    // Used later to remember the passed string.
    static c8_t *pc8char = NULL;
    // Array to hold our single lines
    static c8_t *ac8buf[30];
    // Line count
    static uint8_t u8count = 0;
    // Array index
    uint8_t u8index = 0;
    // If the string hasn't already been parsed
    if (pc8char == NULL || pc8char != pac8string)
    {
        pc8char = pac8string;

        // Split string by using linebreaks as delimiters
        pc8char = strtok (pac8string, "\n");

        // While there are still linebreaks in the string
        while (pc8char != NULL)
        {
            // Store the line in the array
            ac8buf[u8index++] = pc8char;
            // Get next line in string
            pc8char = strtok (NULL, "\n");
            // Increment Line count
            u8count++;
        }
        // Remember this string
        pc8char = pac8string;
    }

    u8index = 0;
    // to handle two \n's in sequence: Insert a newline
    bool b8skipline = false;
    // Iterate over the lines
    while (u8index < u8count)
    {
        lcd_clear ();
        // If the line does not have to be clear because of a second newline
        if (!b8skipline)
            // Display the line
            lcd_display_string (ac8buf[u8index]);
        // Go to the second line
        lcd_set_cursor (1, 0);
        // If the previous line didn't have to be clear
        if (!b8skipline)
            // Look if the line has a second \n
            if (*(ac8buf[u8index+1]-1) == '\n')
                // Then skip this line and next time, put this line in the second line
                b8skipline = true;
            else
                // Otherwise display the line
                lcd_display_string (ac8buf[++u8index]);
        else
        {
            // Otherwise display the line in the second line instead of the first line.
            lcd_display_string (ac8buf[++u8index]);
            // Finally done.
            b8skipline = false;
        }
        delayMs (u16delay);
    }
}
コード例 #13
0
ファイル: lcd.c プロジェクト: janstrohbeck/pic24template
void lcd_display_number (int16_t i16num)
{
    c8_t ac8buf[17];
    sprintf (ac8buf, "%-6d %4x", i16num, i16num);
    lcd_display_string (ac8buf);
}
コード例 #14
0
ファイル: banner.c プロジェクト: StylonWang/lcd-1602
int main(int argc, char **argv)
{
    char *dev = "/dev/i2c-2";
    int fd = open(dev, O_RDWR);
    int ret;
    uint8_t address = 0x27;
    char ip[32];
    char fortune[128];
    int scroll_delay = 200;

    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);

    if(fd<0) {
        printf("open: %s\n", strerror(errno));
        exit(1);
    }

    ret = ioctl(fd, I2C_SLAVE, address);
    if(ret<0) {
        printf("set i2c address: %s\n", strerror(errno));
        exit(1);
    }

    lcd_init(fd);

    while(!g_quit) {
        char tmp_fortune[16+1];
        int i;

        get_ip(ip, sizeof(ip));
        get_fortune(fortune, sizeof(fortune));
        
        //strncpy(tmp_fortune, fortune, 16);
        snprintf(tmp_fortune, sizeof(tmp_fortune), "%s", fortune);

        printf("display fortune: %s\n", fortune);
        lcd_display_string(fd, tmp_fortune, 1);
        printf("display ip: %s\n", ip);
        lcd_display_string(fd, ip, 2);
        msleep(900); 

        // no scrolling if fit in one line
        if( strlen(fortune)<=16) {
            msleep(2000);
            continue;
        }

        // do scrolling text if unable to fit in one line
        printf("scroll start: %s\n", fortune);
        for(i=1; i<=strlen(fortune) && !g_quit ; ++i) {
            // shift the string to the left by 1 character
            snprintf(tmp_fortune, sizeof(tmp_fortune), "%s", fortune+i); 
       
            lcd_display_string(fd, tmp_fortune, 1);
            msleep(scroll_delay);
        }
        printf("scroll end: %s\n", fortune);

    }

    lcd_clear(fd);
    close(fd);
    return 0;
}