コード例 #1
0
ファイル: text.c プロジェクト: Mircho/glcd
void glcd_draw_string_xy_P(uint8_t x, uint8_t y, const char *str)
{
	uint8_t width;

	if (y > (GLCD_LCD_HEIGHT - font_current.height - 1)) {
		// character won't fit
		return;
	}

	while (1) {
#if defined(GLCD_DEVICE_AVR8)		
		char c = pgm_read_byte(str++);
#else
		char c = *(str++);
#endif
		if (!c)
			return;
					
		width = glcd_draw_char_xy(x,y,c);
		x += (width + 1);
		// ignore section - up to user to make sure text does not overflow display width
		//if (x+width >= GLCD_LCD_WIDTH) {
		//	return;
		//}		
		c++;
	}		
}
コード例 #2
0
ファイル: text.c プロジェクト: Mircho/glcd
void glcd_draw_string_xy(uint8_t x, uint8_t y, char *c)
{
	uint8_t width;

	if (y > (GLCD_LCD_HEIGHT - font_current.height - 1)) {
		// character won't fit
		return;
	}

	while (*c) {
		width = glcd_draw_char_xy(x,y,*c);
		x += (width + 1);
		// ignore section - up to user to make sure text does not overflow display width
		//if (x+width >= GLCD_LCD_WIDTH) {
		//	return;
		//}
		c++;
	}		
}
コード例 #3
0
ファイル: main.c プロジェクト: f16falcona46/PSoC
int main() {
	
	int noteBuffer[SONG_SIZE];
	int accidentals[SONG_SIZE];
	int octaveBuffer[SONG_SIZE];
	
	memcpy(noteBuffer, rom_notes, SONG_SIZE*sizeof(int));
	memcpy(accidentals, rom_accidentals, SONG_SIZE*sizeof(int));
	memcpy(octaveBuffer, rom_octaves, SONG_SIZE*sizeof(int));
	const int buf_size = SONG_SIZE;
    
    //uint8 selected;
	initHardware();
	int start = 0;
	while (1) {
		//glcd_clear();
		glcd_tiny_set_font(Font5x7,5,7,32,127);
		update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
		if (start > 0) {
			glcd_draw_string_xy(13*6,0,"^");
		}
		if (start+4 < buf_size) {
			glcd_draw_string_xy(13*6,5*8,"v");
		}
		glcd_draw_char_xy(13*6,1*8,(start/4+1)/100%10+'0');
		glcd_draw_char_xy(13*6,2*8,(start/4+1)/10%10+'0');
		glcd_draw_char_xy(13*6,3*8,(start/4+1)%10+'0');
		glcd_write();
		/*
		start+=4;
		if (start > 24) start = 0;
		*/
		
		int reading = 0;
		not_scroll:
		reading = Keypad_1_GetButton();
		switch (reading) {
			case 7:
				if (start+4 < buf_size) start+=4;
				break;
			case 15:
				if (start > 0) start-=4;
				break;
			case 3:
				play_song(noteBuffer, accidentals, octaveBuffer, buf_size);
				break;
			case 0:
				for (int i = 0; i < 4; ++i) {
					glcd_invert_area(i*18, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					int button = 7;
					while (button > 6) {
						button = keycode_to_note[Keypad_1_GetButton()];
					}
					noteBuffer[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
					glcd_invert_area(i*18+6, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					button = 2;
					while (button > 1) {
						button = keycode_to_accidental[Keypad_1_GetButton()];
						if (button == 99) goto cancel_edit;
					}
					accidentals[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
					glcd_invert_area(i*18+12, 0, 6, 8);
					glcd_write();
					CyDelay(200);
					button = 10;
					while (button > 9) {
						button = keycode_to_octave[Keypad_1_GetButton()];
						if (button == 99) goto cancel_edit;
					}
					octaveBuffer[start+i] = button;
					update_notes(noteBuffer, accidentals, octaveBuffer, start, buf_size);
				}
				cancel_edit:
				break;
			case 1:
				glcd_clear();
				glcd_draw_string_xy(0,0,"Saving...");
				glcd_write();
				int fail = 0;
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)noteBuffer, (void*)rom_notes, SONG_SIZE*sizeof(int));
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)accidentals, (void*)rom_accidentals, SONG_SIZE*sizeof(int));
				fail += CYRET_SUCCESS!=Em_EEPROM_Write((void*)octaveBuffer, (void*)rom_octaves, SONG_SIZE*sizeof(int));
				if (fail) {
					glcd_draw_string_xy(0,8,"Failed!");
					glcd_write();
					CyDelay(1000);
				}
				else {
					glcd_draw_string_xy(0,8,"Success!");
					glcd_write();
					CyDelay(300);
				}
				break;
			default:
				goto not_scroll;
		}
		CyDelay(50);
	}
}