コード例 #1
0
ファイル: wb.c プロジェクト: crpalmer/pi_lib
int
main(int argc, char **argv)
{
    int bank;

    if (wb_init() < 0) {
	fprintf(stderr, "Failed to initialize wb\n");
	exit(1);
    }

    if (argc == 3 && strcmp(argv[1], "--out") == 0 && sscanf(argv[2], "%d", &bank) == 1) {
	if (bank < 1 || bank > 2) {
	     fprintf(stderr, "Invalid output bank, must be either 0 or 1\n");
	     exit(1);
	}
	output_test(bank);
    } else if (argc != 1) {
	fprintf(stderr, "usage: [--out bank]\n");
	exit(1);
    } else {
	input_test();
    }
    exit(0);
}
コード例 #2
0
int main()
{
	
	avrinit();

	//
	// this is not the official way of figuring out whether the RSTDISBL fuse has been programmed,
	//	but it is a good substitute!
	//	(just don't press the button while powering on)
	//

	// immediately we poll switch - if it "seems" on (i.e. low), then probably it isn't working!  (leave it disabled)
	input_test(F_LINE);	// dummy read
	NOP();
	if (input_test(F_LINE) != 0) {		// enable switch (i.e. F_LINE) if this reads high
		FLineEnabled = 1;
	}


	// debug
	if (FLineEnabled) {
		blinkn(4);
	} else {
		blinkn(3);
	}
	
	//mydelay10(20);

	{
		uint8_t tmp, width;
		uint8_t tmpb;
		uint8_t i, j;
		
		uint8_t buttonevent = 0;
		uint8_t prevbuttonpress = 0;
		uint8_t buttonpress;

		uint8_t msgnum = 0;		// this is "toggled" by a button press
		//uint8_t msglen = 0;

		uint8_t len = 0;

		//
		// change this string!
		// the "str" array below sets the current message.
		// you can use cap letters, numbers, and a limited set of punctuation.
		//
		// check font.c to see all the chars that are available, or possibly add more.
		//

		// List of messages, we're toggling through. Only uppercase.
		static const char *messages[] = {
		  "HENNER   ",
		  "I \xF0 NOISEBRIDGE  ",
		  "HACKER  ",
		};

		// static const unsigned char str[]   = "I \xF0 SOLDERING  ";
		//static const unsigned char str[]   = "HELLO  ";  // Dosa from Toorcamp 2012

		//static const unsigned char str[]   = "MORE BASS  ";   // -zarina
		//static const unsigned char str[]   = "SAN FRANCISCO 2012  ";
		//static const unsigned char str[]   = "HAPPY 53  ";    // -mio

		//static const unsigned char str[]   = "ABCDEFGHIJKLMONOPQRSTUVWXYZ1234567890\xF0!. ";
		//static const unsigned char str[]   = "PEACE ON EARTH  ";
		//static const unsigned char str[]   = "INTERNET PREDATOR  ";
		//static const unsigned char str[]   = "EFFE IS YOU AND ME  ";
		//static const unsigned char str[]   = "HELLO WORLD!  ";
		//static const unsigned char str[]   = "I \xF0 PIZZA  ";
		//static const unsigned char str[]   = "I \xF0 CATS  ";
		//static const unsigned char str[]   = "GO ERIN!  ";
		//static const unsigned char str[]   = "GYRE AND GIMBLE  ";
		//static const unsigned char str[]   = "POSTAGRAM  ";
		//static const unsigned char str[]   = "DANCE YURKOSAURUS DANCE  \xF0  ";
        //static const unsigned char str[]   = "HI I AM HEATHER!  ";
        //static const unsigned char str[]   = "HELLO!  ";
		//static const unsigned char str[]   = "I \xF0 OAKLAND  ";
		//static const unsigned char str[]   = "I \xF0 MEGGIE!  ";
		//static const unsigned char str[]   = "I HELLA \xF0 OAKLAND  ";
		//static const unsigned char str[]   = "RED BURNS ROCKS!   I \xF0 ITP  ";

		const uint8_t rep = 35;	// adjusts scrolling speed (higher number == slower, 35-40 seems about right)

		while (1)  {  /* infinite loop */
		     const char *str = messages[msgnum];
		     uint8_t strlength = strlen(str);

			// toggle message if we see a button event (press)
			if (buttonevent) {
			        msgnum++;
				msgnum %= sizeof(messages) / sizeof(const char*);
				len = 0;
				buttonevent = 0;	// clear event flag
			}
			

			//
			// this loads the pixels for a letter (c) into the global FontChar array, and sets FontWidth.
			//
			uint8_t c;
			c = str[len];
			loadfontchar(c);
			
			len++;
	
			if (len >= strlength) {
				len = 0;
			}
			//if (len >= msglen)  len = 0;		// XXX handles 3 chars + 2 spaces
	
			width = FontWidth & 0xf;
	
			for (j = 0; j < width; j++) {		// do "width" times...
				for (i = 0; i < 5; i++) {			// for each row of the display...
					if (FontChar[i] & 0x80) {
						tmpb = 1;
					} else {
						tmpb = 0;
					}
					
					tmp = FontChar[i] << 1;
					FontChar[i] = tmp;
					
					tmp = Disp[i] << 1;
					Disp[i] = tmp;
					if (tmpb) {
						Disp[i]++;
					}
				}
	
				//swapbuffers();
				for (i = 0; i < rep; i++) {
				
					// catch button press "event" (also use Refresh as a "delay")
					if (FLineEnabled) {
						if (input_test(F_LINE) == 0) {
							buttonpress = 1;
						} else {
							buttonpress = 0;
						}
						if (!prevbuttonpress && buttonpress) {		// detect transition from unpressed to pressed
							buttonevent = 1;						// and set event flag
						}
						prevbuttonpress = buttonpress;
					}

					Refresh();  // "refresh" LEDs
					
					// XXX for a button event, may need to wait here until button is released
					if (buttonevent) {
						break;
					}
				}
	
			}
		}
	}

}
コード例 #3
0
// draw (i.e. "refresh") the display buffer (see Disp array).
void Refresh()
{
	uint8_t i;
	uint8_t del1 = 1;	// delay between "pixel groups" (there are 6)

	uint8_t a,b,c,d,e;
	
	//uint8_t blank = 0;					// determines whether part (or all) of display is "blanked" (i.e. turned off)
	uint8_t blankEn = FLineEnabled;		// check global flag whether F_LINE should be looked at or not


	for (i = 0; i < 6; i++) {

		switch (i) {

		case 0:
			// decide which pixels are on
			a = Disp[0] & 0x10;
			b = Disp[0] & 0x08;
			c = Disp[0] & 0x04;
			d = Disp[0] & 0x02;
			e = Disp[0] & 0x01;
			
			// first, poll switch - switch pin is active low (i.e. low if pressed)
			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
				if (a) setpixel(0, 0, 1);
				if (b) setpixel(1, 0, 1);
				if (c) setpixel(2, 0, 1);
				if (d) setpixel(3, 0, 1);
				if (e) setpixel(4, 0, 1);
			}
			mydelay1(del1);
			if (a) setpixel(0, 0, 0);
			if (b) setpixel(1, 0, 0);
			if (c) setpixel(2, 0, 0);
			if (d) setpixel(3, 0, 0);
			if (e) setpixel(4, 0, 0);
			break;
		
		case 1:
			b = Disp[1] & 0x08;
			c = Disp[1] & 0x04;
			d = Disp[1] & 0x02;
			e = Disp[1] & 0x01;

			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
			if (b) setpixel(1, 1, 1);
			if (c) setpixel(2, 1, 1);
			if (d) setpixel(3, 1, 1);
			if (e) setpixel(4, 1, 1);
			}
			mydelay1(del1);
			if (b) setpixel(1, 1, 0);
			if (c) setpixel(2, 1, 0);
			if (d) setpixel(3, 1, 0);
			if (e) setpixel(4, 1, 0);
			break;
		
		case 2:
			a = Disp[1] & 0x10;
			c = Disp[2] & 0x04;
			d = Disp[2] & 0x02;
			e = Disp[2] & 0x01;
			
			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
			if (a) setpixel(0, 1, 1);
			if (c) setpixel(2, 2, 1);
			if (d) setpixel(3, 2, 1);
			if (e) setpixel(4, 2, 1);
			}
			mydelay1(del1);
			if (a) setpixel(0, 1, 0);
			if (c) setpixel(2, 2, 0);
			if (d) setpixel(3, 2, 0);
			if (e) setpixel(4, 2, 0);
			break;
			
		case 3:
			a = Disp[2] & 0x10;
			b = Disp[2] & 0x08;
			d = Disp[3] & 0x02;
			e = Disp[3] & 0x01;

			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
			if (a) setpixel(0, 2, 1);
			if (b) setpixel(1, 2, 1);
			if (d) setpixel(3, 3, 1);
			if (e) setpixel(4, 3, 1);
			}
			mydelay1(del1);
			if (a) setpixel(0, 2, 0);
			if (b) setpixel(1, 2, 0);
			if (d) setpixel(3, 3, 0);
			if (e) setpixel(4, 3, 0);
			break;

		case 4:
			a = Disp[3] & 0x10;
			b = Disp[3] & 0x08;
			c = Disp[3] & 0x04;
			e = Disp[4] & 0x01;

			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
			if (a) setpixel(0, 3, 1);
			if (b) setpixel(1, 3, 1);
			if (c) setpixel(2, 3, 1);
			if (e) setpixel(4, 4, 1);
			}
			mydelay1(del1);
			if (a) setpixel(0, 3, 0);
			if (b) setpixel(1, 3, 0);
			if (c) setpixel(2, 3, 0);
			if (e) setpixel(4, 4, 0);
			break;
		
		case 5:
			a = Disp[4] & 0x10;
			b = Disp[4] & 0x08;
			c = Disp[4] & 0x04;
			d = Disp[4] & 0x02;

			input_test(F_LINE);	// dummy read
			NOP();
			if (blankEn && (input_test(F_LINE) == 0)) {
				;
			} else {
			if (a) setpixel(0, 4, 1);
			if (b) setpixel(1, 4, 1);
			if (c) setpixel(2, 4, 1);
			if (d) setpixel(3, 4, 1);
			}
			//blank = 0;	/* clear blanking flag at the last row (here) */

			mydelay1(del1);
			if (a) setpixel(0, 4, 0);
			if (b) setpixel(1, 4, 0);
			if (c) setpixel(2, 4, 0);
			if (d) setpixel(3, 4, 0);
			break;
		}
	}
}