Comments and suggestions for improvement of demo object
average joe
Posts: 795
Hi Everyone!
I have just finished translating the EarthLCD - ezLCD 301 app note for the BS2 into SPIN and I am looking for comments and suggestions for improvement. I intend on posting this in the OBEX when finished and would like this object to be self-explanatory and easy to use. The object is thoroughly tested and works like a charm. Any help would be appreciated!
I have just finished translating the EarthLCD - ezLCD 301 app note for the BS2 into SPIN and I am looking for comments and suggestions for improvement. I intend on posting this in the OBEX when finished and would like this object to be self-explanatory and easy to use. The object is thoroughly tested and works like a charm. Any help would be appreciated!
{{ ''******************************************** ''* ezLCD-301 application note from bs2 * ''* Author: * ''* Translated to SPIN by Joe Heinz * ''* Copyright (c) 2012 EarthLCD.com * ''* See end of file for terms of use. * ''******************************************** }} {-----------------REVISION HISTORY----------------- v1.0 - x/x/2012 first official release. } ezLCDtx = 1 'The ezLCD tx pin (RX pin on prop) , change as needed ezLCDrx = 0 'The ezLCD rx pin (TX pin on prop) , change as needed ezLCDbaud = 9600 'the ezLCD baud-rate , change as needed pinOut = 22 'This is the pin to toggle on and off , change as needed pstBaud = 115200 'This is the baud-rate for Parallax Serial Terminal Debugger , change as needed VAR byte serStr[6], idx, c 'define a 6-byte string array for storing the data received from ezLCD OBJ serial : "FullDuplexSerial" 'This object does the actual serial communication with the display *Thanks Chip Gracey, Jeff Martin wait : "timing" 'This object is for simple timing *Thanks Parallax pst : "parallax serial terminal" 'This object is for debugging to PC, comment out if not used *Thanks Jeff Martin, Andy Lindsay, Chip Gracey PUB BOOT ''This method runs at startup serial.start(ezLCDrx,ezLCDtx, 0, ezLCDbaud) 'Start fullDuplex serial driver with ezLCD pins @ ezLCDbaud, mode 0. Returns false if no cog available. pst.start(pstBaud) 'Start Parallax Serial Terminal @ pstBaud, comment out if used dira[pinOut] ++ 'Make pinOut an output serial.str(string("cls black")) 'Clears the display to black CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("theme 1 9 3 0 0 0 8 8 8 8")) 'Defines Theme 1 for button 1 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("theme 2 5 20 3 3 3 4 4 4 4")) 'Defines Theme 2 for button 2 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("fontw 1 sans72")) 'define font for button 1 widget CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("fontw 2 sans72")) 'defines font for button widget 2 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("string 1 ON")) 'defines string for button 1 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("string 2 OFF")) 'defines string for button2 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("button 1 10 40 185 140 1 0 25 1 1")) 'defines button 1 CR_LF 'Send Carriage Return + Line Feed wait.pause1ms(10) 'Wait 10ms serial.str(string("button 2 205 40 185 140 1 0 25 2 2")) 'defines button 2 CR_LF 'Send Carriage Return + Line Feed wait.pause1s(3) 'Wait 3 Seconds for ezLCD to finish sending feedback about it's displays serial.rxflush 'Clear serial receive buffer pst.clear 'Clear parallax Serial Terminal, comment out if not used ' Main Loop starts here repeat 'Repeat loop starts here idx ~ 'Clear idx repeat while (c:= serial.rx) <> 13 'Copy serial receive buffer into c and repeat until Carriage Return is received, CR signifies end of string from display serStr[idx++] := c 'Move receive buffer into serStr then increment idx, serStr[idx] ~ 'Set last byte to 0, for 0 terminated string to Parallax Serial Terminal pst.str(@serStr) 'Send serStr to Parallax serial Terminal, comment out if not used pst.newline 'Send newline to Parallax Serial Terminal, comment out if not used if serStr[0] == "B" and serStr[1] == "P" and serStr[2] == "1" 'If received data is BP1 which means button 1 pressed outa[pinOut] := 1 'then set pinOut high if serStr[0] == "B" and serStr[1] == "P" and serStr[2] == "2" 'If received data is BP2 which means button 2 pressed outa[pinOut] ~ 'then set pinOut low serial.rxflush 'clear serial receive buffer for next iteration bytefill(@serStr,6,0) 'clear serString for next iteration PUB CR_LF ''Send Carriage Return + Line Feed serial.tx(13) ' Send Carriage Return to display serial.tx(10) ' Send Line Feed to display
Comments
I am also working on a low-level driver for the ez-lcd301 and been getting stuck. The object basically parses space-delimited, ASCII commands and parameters to something a bit easier to work with in spin. I keep getting strange errors with the returns and can't quite figure out what's going on. Full object : The problem is: Returns from this work But this does not return anything? They should either both work, or neither. Why one works, and the other one doesn't has me confused. Any help would be appreciated as always!
http://www.parallaxsemiconductor.com/goldstandard
For your question, if CID<200 and CID > -1 then there is no assignment to result? Your first example is also missing such an assignment, but perhaps you don't have a test case for the first condition.
about the assignment, if CID<200 and CID > -1, then you are writing CID to the display, setting the display to use that color. Same thing with the backlight. If you send your setting the backlight to 80%. If you send this should return the current backlight setting and place it in BacklightSetting. *and does, in a round about way returning the SIZE, and placing the actual value in the buffer* does NOT behave properly and returns 0, or no string? The command seems to be getting lost, but seems to work everywhere else it's used. I'm just scripting the RETURN sections of the code now. You can send data to the display with what I posted, but getting data from the display *by calling the same method with the first parameter set to -1* is proving more difficult than anticipated!
Thanks again and I will keep you updated!