Ejemplo n.º 1
0
void adjBacklight()
{
	static const char *const stra = "      Light on      ";
	static const char *const strb = "      Light off     ";
	static const char *const strd = "  Press [2] again   ";
	static const char *const stre = " Press Enter to end ";

	auto char inkey;
	auto unsigned int slite;

	dispClear();
	dispGoto(0,2); dispPrintf("%s", strd);
	dispGoto(0,3); dispPrintf("%s", stre);

	do {
		do {
			keyProcess ();
			} while (!(inkey = keyGet()));

			if (inkey== '2') {
				dispBacklight(slite = slite ? 0:1); //turn on/off LCD backlight
				}

			if (slite) {
				dispGoto(0,0); dispPrintf("%s", stra);
				}
			else {
				dispGoto(0,0); dispPrintf("%s", strb);
				}
		} while (inkey != EXITKEY);

	dispClear();
}
Ejemplo n.º 2
0
/*===================================================================
===================================================================*/
void adjCursor()
{
	static const char *const stra = "        [4]         ";
	static const char *const strb = "[8]  Press keys  [0]";
	static const char *const strc = "        [9]         ";
	static const char *const stre = " Press Enter to end ";

	auto char inkey;
	auto int xdir, ydir;

	dispClear();
	dispGoto(0,0); dispPrintf("%s", stra);
	dispGoto(0,1); dispPrintf("%s", strb);
	dispGoto(0,2); dispPrintf("%s", strc);
	dispGoto(0,3); dispPrintf("%s", stre);

	xdir=9;
	ydir=1;
	dispGoto(xdir,ydir);
	dispCursor(DISP_CURBLINK);

	do {
		costate {									//	Process Keypad Press/Hold/Release
			keyProcess ();
			waitfor ( DelayMs(10) );
			}

		costate {
			waitfor ( inkey = keyGet() );		//	Wait for Keypress
			switch (inkey) {
				case '4':
					ydir--;
					if (ydir < 0)
						ydir=3;
					break;
				case '8':
					xdir--;
					if (xdir < 0)
						xdir=19;
					break;
				case '9':
					ydir++;
					if (ydir > 3)
						ydir=0;
					break;
				case '0':
					xdir++;
					if (xdir > 19)
						xdir=0;
					break;
				default:
					break;
				}
			dispGoto(xdir,ydir);
			}
		} while (inkey != EXITKEY);

	dispClear();
	dispCursor(DISP_CUROFF);
}
Ejemplo n.º 3
0
/*===================================================================
===================================================================*/
void adjContrast()
{
	static const char *const stra = "      Press [1]     ";
	static const char *const strb = " for more contrast  ";
	static const char *const strc = "      Press [6]     ";
	static const char *const strd = " for less contrast  ";
	static const char *const stre = " Press Enter to end ";

	auto char inkey;
	auto unsigned int scontrast;

	scontrast=BCONTRAST;

	dispClear();
	dispGoto(0,3); dispPrintf("%s", stre);

	do {
		costate {								//	Process Keypad Press/Hold/Release
			keyProcess ();
			waitfor ( DelayMs(10) );
			}

		costate {
			dispGoto(0,0); dispPrintf("%s", stra);
			dispGoto(0,1); dispPrintf("%s", strb);
			waitfor (DelaySec(2));
			yield;
			dispGoto(0,0); dispPrintf("%s", strc);
			dispGoto(0,1); dispPrintf("%s", strd);
			waitfor (DelaySec(2));
			yield;
			}

		costate {
			waitfor ( inkey = keyGet() );		//	Wait for Keypress
			switch (inkey) {
				case '1':
					if (scontrast > HICONTRAST)
						scontrast-=8;
					break;
				case '6':
					if (scontrast <= LOCONTRAST)
						scontrast+=8;
					break;
				default:
					break;
				}
			dispContrast (scontrast);
			}

		} while (inkey != EXITKEY);

	dispClear();
	dispContrast (BCONTRAST);
}
Ejemplo n.º 4
0
/*
 * Receive a message.  The socket is re-opened and message read.  The need
 * for a response is indicated.  tcp_tick() fails if peer closed socket.
 */
void RecvMessage(tcp_Socket* tcpSock, int* respond)
{
	auto char buffer[500];
	auto int numBytes;

	tcp_listen(tcpSock, PORT, 0, 0, NULL, 0);
	dispClear();

	/* Wait for connection. */
	while( ! tcp_established( tcpSock ) ) {
		if( ! tcp_tick( (sock_type *) tcpSock ) ) {
			dispPrintf( "ERROR: listening: %s\n", tcpSock->err_msg );
			exit( 99 );
		}
	}

	/*  Wait for some data to appear, or an error... */
	while( 0 == (numBytes = sock_fastread(tcpSock, buffer, sizeof(buffer))) ) {
		if( ! tcp_tick( tcpSock ) ) {
	bad_read:
			dispPrintf( "ERROR: read: %s\n", tcpSock->err_msg );
			exit( 99 );
		}
	}
	if (numBytes == -1) {
		goto bad_read;
	}

	buffer[numBytes] = '\0';
	dispPrintf("%s", buffer);
	*respond = 1;	// Indicate the need for a response

}   /* end RecvMessage() */
Ejemplo n.º 5
0
// Initialization routine normally called only from the constructor, but may be used in "emergencies"
void MAX72::initChip() {
  writeRegister(SHUTDOWN, 0x0);         // Shut down the display while initializing things...
  writeRegister(SCANLIMIT, _numDigits - 1);	// Set the scan limit (Register values 0-7 for 1-8 digits) for the chip to scan
  writeRegister(DECODEMODE, 0x0);	      // Set no BCD segment decoding
  writeRegister(INTENSITY, 0xf);	      // Start at maximum brightness
  dispClear();				                  // Blank the display
  writeRegister(SHUTDOWN, 0x1);		      // Turn the display back on
}
Ejemplo n.º 6
0
/*
 * Send the response to the remote machine.  Close the socket.
 */
void SendMessage(tcp_Socket *tcpSock, unsigned key, char* messages[])
{
	auto char * p;
	auto int 	len;

	/* Use sock_fastwrite() here to encourage good programming practices. */

	sock_write(tcpSock, messages[key-1], strlen(messages[key-1])+1);
	sock_close(tcpSock);
	while (tcp_tick(tcpSock) != 0);
	dispClear();
	dispPrintf("Response sent");
}
Ejemplo n.º 7
0
void rundemo()
{
	char inkey;
	int i,j,k,m;

	brdInit();					//initialize controller
	keypadDef();
	dispContrast (BCONTRAST);
	dispBacklight(1); 		//turn on LCD backlight

 	dointro();

	while (1) {
		dispClear ();
		//dispContrast(wC);
		dispGoto(0,0);  dispPrintf("%s", "Press [1] Contrast ");
		dispGoto(0,1);  dispPrintf("%s", "Press [2] Backlight");
		dispGoto(0,2);  dispPrintf("%s", "Press [3] Speaker  ");
		dispGoto(0,3);  dispPrintf("%s", "Press [4] Cursor   ");

		do {
			keyProcess();
			} while (!(inkey = keyGet()));

		switch (inkey) {
			case '1':
				adjContrast();
				break;
			case '2':
				adjBacklight();
				break;
			case '3':
				adjSpeaker();
				break;
			case '4':
				adjCursor();
				break;
			default:
				break;
			} //end switch
		} //end forever while
}
Ejemplo n.º 8
0
/*===================================================================
===================================================================*/
void dointro()
{
	auto unsigned int i, slite;

	static const char str0[][] = {	"     Z-World's      ",
												" INTELLICOM SERIES  ",
												"  A C-Programmable  ",
												"Intelligent Terminal"
											};

	static const char str1[][] = {	"   In addition to   ",
												"  Z-World standard  ",
												" features, here are ",
												"   a few more...    "
											};

	static const char str2[][] = {	"    >>>>>>>>>>>>    ",
												"     Adjustable     ",
												"      Contrast      ",
												"    <<<<<<<<<<<<    "
											};

	static const char str3[][] = {	"    ************    ",
												"     Backlight      ",
												"      Support       ",
												"    ************    "
											};

	static const char str4[][] = {	"    ::::::::::::    ",
												"      Speaker       ",
												"      Control       ",
												"    ::::::::::::    "
											};

	static const char str5[][] = {	"    ++++++++++++    ",
												"       Cursor       ",
												"      Movement      ",
												"    ++++++++++++    "
											};

	static const char str6[][] = {	"                    ",
												"    Now You Try!    ",
												"                    ",
												"                    "
											};

	/// main intro
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str0[i]);
		}
	sdelay(5);

	/// intro
	scrnfadeout();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str1[i]);
		}
	scrnfadein();
	sdelay(3);

	/// show off contrast
	scrnfadeout();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str2[i]);
		}
	scrnfadein();
	docontrast();
	sdelay(3);

	/// show off backlight
	scrnfadeout();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str3[i]);
		}
	scrnfadein();
	slite=0;
	for (i=0; i<=8; i++) {
		dispBacklight(slite=slite?0:1);
		sdelay(1);
		}
	dispBacklight(1);
	sdelay(3);

	/// show off speaker
	scrnfadeout();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str4[i]);
		}
	scrnfadein();
	for (i=0; i<3; i++) {
		spkrOut (200, 3 );		// output to speaker
		mdelay(500);
		spkrOut (500, 0);
		mdelay(50);

		spkrOut (500, 3 );		// output to speaker
		mdelay(800);
		spkrOut (500, 0);
		mdelay(50);

		spkrOut (1800, 3 );		// output to speaker
		mdelay(1000);
		spkrOut (1000, 3);
		mdelay(500);

		spkrOut (600, 3);
		mdelay(800);
		}
	spkrOut (0, 0);
	sdelay(3);

	/// show off cursor movement
	scrnfadeout();
	dispClear();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str5[i]);
		}
	scrnfadein();
	pong();
	sdelay(3);

	/// show off interactive
	scrnfadeout();
	for (i=0; i<=3; i++) {
		dispGoto ( 0,i );
		dispPrintf ("%s", str6[i]);
		}
	scrnfadein();
	sdelay(5);
}
Ejemplo n.º 9
0
/*===================================================================
===================================================================*/
void adjSpeaker()
{
	auto unsigned int aFreq, aAmp, wKey, akey, validkey;

	aFreq = LOSPEAKER;
	aAmp = 0;
	wKey=akey='0';
	validkey = 1;

	dispClear();

	dispGoto(0,0);
	dispPrintf("Volume:  Press 1-4  ");
	dispGoto(0,1);
	dispPrintf("Freq: Press 5 or 0  ");

	dispGoto(0,2);
	dispPrintf("Volume level %c     ", wKey);
	dispGoto(0,3);
	dispPrintf("Freq level    %d  ", aFreq);

	do {
		do	{
			keyProcess ();
			} while (!(wKey = keyGet()));

		switch (wKey) {
			case	'1':
				aAmp = 0;		// no volume
				akey=wKey;
				break;
			case	'2':
				aAmp = 2;		// level 1
				akey=wKey;
				break;
			case	'3':
				aAmp = 1;		// level 2
				akey=wKey;
				break;
			case	'4':
				aAmp = 3;		// level 3
				akey=wKey;
				break;
			case	'5':
				if (aFreq < HISPEAKER)
					aFreq+=100;    // increase frequency
				break;
			case	'0':
				if (aFreq > LOSPEAKER)
					aFreq-=100;		// decrease frequency
				break;
			default:
				validkey = 0;
				break;
			}

		if (validkey) {
			dispGoto(13,2);
			dispPrintf("%c", akey);
			dispGoto(13,3);
			dispPrintf("%4d", aFreq);
			spkrOut (aFreq, aAmp );		// output to speaker
			}
		else
			validkey=1;
		} while (wKey != EXITKEY);

	dispClear();
	spkrOut (0, 0);		// output off to speaker
}