Setting X position over HTTP...

Talk about YBoxen, widgets, Propeller hacking, etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
iamalsohere
 
Posts: 5
Joined: Sun Dec 28, 2008 9:43 am

Setting X position over HTTP...

Post by iamalsohere »

Excellent kit (thankyou!), i built mine on christmas day and it worked perfectly! I followed the soldering guide and there are a few omissions but easy enough to work out.

Anyway, i've been working on a PHP class which wraps all of the formatting functions for the text output (so I can use it with the infowidget), and everything works (CRLF, Colours, clear screen, goHome etc) except for setting the column position (i.e. X axis) of the cursor. I can't seem to get it working properly - the text driver just displays symbols on the screen where the code should be changing the position. Changing the row/Y position is fine!

I checked out the tv_text.spin file and i can't see anything wrong in the code, and i can't see anything wrong in my PHP code either. Any pointers?

I'll upload the code for my PHP class when i'm done :)

User avatar
darco
 
Posts: 118
Joined: Wed Jun 04, 2008 7:54 pm

Re: Setting X position over HTTP...

Post by darco »

I'm not aware of any problems that TV_Text.spin has with the X position... Perhaps somehow the characters are being translated strangely? Have you tried setting the X position from within a spin program?

iamalsohere
 
Posts: 5
Joined: Sun Dec 28, 2008 9:43 am

Re: Setting X position over HTTP...

Post by iamalsohere »

Thanks for the reply draco - it seems to work fine from within a proper .spin program, just not when used in the infowidget. I'll persevere I guess (i'm writing an RSS reader which currently uses a modified infowidget and PHP script, might have to move it all to run inside a spin program!)

Heres a small bit of the class i'm developing...

Code: Select all

PHP5 code:

class ybox2_display {

	/*
	  '' $00 = clear screen
		'' $01 = home
		'' $08 = backspace
		'' $09 = tab (8 spaces per)
		'' $0A = set X position (X follows)
		'' $0B = set Y position (Y follows)
		'' $0C = set color (color follows)
		'' $0D = return 
	 */
	
	const CHR_CLEAR_SCREEN = 0x00;
	const CHR_HOME         = 0x01;
	const CHR_BACKSPACE    = 0x08;
	const CHR_TAB          = 0x09;
	const CHR_SET_X        = 0x0A;
	const CHR_SET_Y        = 0x0B;
	const CHR_SET_COLOUR   = 0x0C;
	const CHR_CRLF         = 0x0D;
	
	const SCREEN_COLS      = 40;
	const SCREEN_ROWS      = 13;
	const SCREEN_TABWIDTH  = 7;
	
	private $pos_x = 0;  // aka col pos
	private $pos_y = 0;  // aka row pos

	public function crlf() {
		echo chr(self::CHR_CRLF);
		$this->pos_x = 0;
		$this->pos_y++;
	}
	
	public function goHome() { 
		echo chr(self::CHR_HOME);
		$this->pos_x = 0;
		$this->pos_y = 0;
	}
	public function set_x($x) {
		echo chr(self::CHR_SET_X);
		echo chr(intval($x));
		$this->pos_x=$x;
	}
	public function set_y($y) { 
		echo chr(self::CHR_SET_Y);
		echo chr(intval($y));
		$this->pos_y=$y;
	}
	

  /**
	 * Writes a whole line of text and resets cursor position to next line
	 *
	 * @param string $line
	 * @param int $pad_type (STR_PAD_LEFT, STR_PAD_BOTH, STR_PAD_RIGHT)
	 */
	public function writeLine($line,$pad_type=STR_PAD_RIGHT) { 
		
		// chop string at max length
		if (strlen($line)>self::SCREEN_COLS) { $line=substr($line,0,self::SCREEN_COLS); } 
		
		echo (str_pad($line,self::SCREEN_COLS,' ',$pad_type));
		$this->pos_x = 0;
		$this->pos_y = $this->pos_y+1;
	}
}

User avatar
darco
 
Posts: 118
Joined: Wed Jun 04, 2008 7:54 pm

Re: Setting X position over HTTP...

Post by darco »

Something must be getting mangled between the PHP script and when the bytes are being fed to the TV_Text object.

I would recommend modifying the infowidget temporarily to print out the hex value of the incoming characters so that you can verify that the bytes aren't being mangled somehow.

iamalsohere
 
Posts: 5
Joined: Sun Dec 28, 2008 9:43 am

Re: Setting X position over HTTP...

Post by iamalsohere »

Good idea! will let you know how it pans out...

Locked
Please be positive and constructive with your questions and comments.

Return to “YBox2 (discontinued)”