Shop OBEX P1 Docs P2 Docs Learn Events
In PUB and out PUB — Parallax Forums

In PUB and out PUB

nicolad76nicolad76 Posts: 164
edited 2008-08-05 21:53 in Propeller 1
HEEEELPPP!!!!
It is driving me crazy!!!!

I have the following code
 
PUB Main        '' Start main public method

    [noparse][[/noparse]some code] 

    DisplayMenu 

                    '' End main Public method
 
 

PUB DisplayMenu    '' Start Menu

eink.Text(179, 35,string("DISPLAY"),72) 
eink.Text(179,155,string("VIEW GPS INFO"),72) 
eink.Text(179,275,string("SETTINGS"),72) 
eink.Text(179,395,string("DEMO"),72) 

eink.Draw
                         '' END Menu



The output is confused, it seems like the strings are passed to the Text method incorrectly.


If I use below code, everything works:

 
PUB Main        '' Start main public method

    [noparse][[/noparse]some code] 

    eink.Text(179, 35,string("DISPLAY"),72) 
    eink.Text(179,155,string("VIEW GPS INFO"),72) 
    eink.Text(179,275,string("SETTINGS"),72) 
    eink.Text(179,395,string("DEMO"),72) 

    eink.Draw

                    '' End main Public method
PUB DisplayMenu    '' Start Menu


                         '' END Menu


What the difference could be from the interpreter point of view?
THANKSS!!!!!

Comments

  • jazzedjazzed Posts: 11,803
    edited 2008-08-04 23:54
    Spin is a white-space sensitive language. The indents mean the code is executed as part of main. In the first example, if you indent the lines under DisplayMenu, that should work too.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 00:00
    I have adjusted all indentation and it still does not work
    [noparse]:([/noparse]((
  • jazzedjazzed Posts: 11,803
    edited 2008-08-05 00:06
    You mentioned that the second example works.
    PUB, PRI, OBJ, VAR, CON, DAT symbols should all start on column 0.
    Code associated with those symbols should start on column 1+ (indented).
    Code meant to be part of an "IF" and other statements should be indented.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-05 00:22
    Also the part marked "[noparse][[/noparse] some code ]" may affect the rest of the code. You'd have to list it.
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 00:27
    this is the entire code

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
     
      EEProm_01         = %10100000
      EEProm_02         = %10100100
      EEProm_03         = %10100110
      EEProm_04         = %10101000
      EEProm_05         = %10101100
      EEProm_06         = %10101110
      
    OBJ
      eink : "PVIEW"
    
     
    VAR
     
     long byteCounter
     long startTime, endTime 
    
    PUB Main      
         Show                                 
                                           
                                
    PUB Show     
     
     
         if eink.Start== TRUE
        
           eink.InitDisplay
           repeat until eink.IsDone
           eink.Portrait
           repeat until eink.IsDone
         
           eink.SetDepthBW
           repeat until eink.IsDone
         
           eink.CLR_White
           repeat until eink.IsDone
         
           eink.NegativePicture
           repeat until eink.IsDone              
         
           SplashScreen
        
           
           StartMenu
         
           waitcnt(clkfreq * 5 + cnt)
    
           eink.CLR_White
           repeat until eink.IsDone
          
           eink.Stop
      
      
    PUB SplashScreen
    
     
         eink.BitMap(EEprom_03, $0000, 3618,180-1,264-1,612-1,332-1)
     
     
    PUB StartMenu                          
        
          eink.Text(179, 35,string("DISPLAY"),72)
          eink.Text(179,155,string("VIEW GPS INFO"),72)
          eink.Text(179,275,string("SETTINGS"),72)
          eink.Text(179,395,string("DEMO"),72)
          eink.Draw     
     
         
    
    

    The method "SplashScreen" works great.
    Do you think I should look for the problem on the definition of "Text" method?
  • Jay KickliterJay Kickliter Posts: 446
    edited 2008-08-05 00:40
    Sorry, too inexperienced to help you, but what kind of display is this code for, ePaper?
  • tpw_mantpw_man Posts: 276
    edited 2008-08-05 00:46
    Can you show the code for the 'eink' object?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I am 1011, so be surprised!


    Advertisement sponsored by dfletch:
    Come and join us on the Propeller IRC channel for fast and easy help!
    Channel: #propeller
    Server: irc.freenode.net or freenode.net
    If you don't want to bother installing an IRC client, use Mibbit. www.mibbit.com
    tongue.gif
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 01:08
    exactly...that's an eInk display from PView.
    The eink objects contains only the routines to send a bitmap to the display. Afterall, its driver accepts only bitmap.
    Once completed it will be my pleasure to publish it...
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 01:10
    the TEXT method is like this:
    PUB Text(x,y,strtext, size) | c
      if objCount < MaxObjects
        objects[noparse][[/noparse]objCount].SetObjectType(OBJ_TEXT)
        objects[noparse][[/noparse]objCount].SetDimension(x,y,x,y+size)   '' x2 not really necessary
        objects[noparse][[/noparse]objCount].SetBodyText(strtext)
        objCount++
    

    I believe part of the problem is in that piece of code but I do not see problems there. It is also true that I am a beginner smurf.gif
  • hippyhippy Posts: 1,981
    edited 2008-08-05 03:14
    The problem for anyone willing to look at your code and offer suggestions or help you find what's wrong is that if they cannot see what the code is they won't really be able to help, only guess.

    "Like this" doesn't cut it, people need to see what you do have, not something like it, and if there's something wrong in that PUB Text method, it's probably something in one of the objects[noparse]/noparse methods, so what does that code look like ?

    I can appreciate no one likes to post half finished code, but sometimes one just has to show it in order to get others interested enough to help. Of course, if it's too complex those who could help might not have the stamina to wade through what you have. The best approach there is to trim the code to a bare minimum to show what problem you're having.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-08-05 03:43
    As an aside, and FYI, you do not need to indent the main body of a method relative to the PUB or PRI header. Aligning to the left margin is fine, viz:

    PUB Start | i
    
    i := 1
    ...
    
    
    


    That said, and as a matter of style, it probably looks a little better if you do indent it.

    -Phil

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    'Still some PropSTICK Kit bare PCBs left!
  • jazzedjazzed Posts: 11,803
    edited 2008-08-05 04:17
    Learn something new every day [noparse]:)[/noparse] Consistency doesn't have to be important.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • RaymanRayman Posts: 14,162
    edited 2008-08-05 09:35
    When code doesn't work that should, I've found that it's usually 1 of 2 things... 1. Stack space issues launching a new cog. 2. Code memory is being overwritten.
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 11:21
    hi guys..I have attached the code...I didn't want to put to much code on the page to do not create confusion... [noparse]:)[/noparse]

    How does the interpreter habdle calls to PUB and PRI? I experienced different result if I use PRI StartMenu or PUB StartMenu


    Thanks guys!!!
  • hippyhippy Posts: 1,981
    edited 2008-08-05 13:00
    The Spin Interpreter handles a call to PRI exactly as it does to PUB. The only difference is that in the table of methods it keeps, links to PUB's are placed before PRI's.

    It sounds like something is writing to the wrong location(s) in Hub and corrupting your program.
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 14:28
    yhea...I am sure about that but I am not skilled enough to find out where it happens.

    ·
  • hippyhippy Posts: 1,981
    edited 2008-08-05 17:38
    The solution to that is to pepper your code with reports which show what's being written and to where. You can use a TV display or perhaps better still via serial ( the PropPlug itself is handy for that ) so you can capture and store the data.

    Work your way through the code seeing what does work and what's anomalous. Eventually you'll find something which is wrong, then you have to back-track to find what's causing it.

    Sometimes it's a good idea to put what code you have to one side and start again, building that code up incrementally while testing it at every stage, adding checks that writes to memory are in the right range, values are as expected, even a routine which compares Eeprom to Ram to show what data changed.

    It's a long hard slog at times but part and parcel of being a programmer.
  • TimmooreTimmoore Posts: 1,031
    edited 2008-08-05 17:52
     
    byte body [noparse][[/noparse]30]
     
    Pub SetBodyText(bdtext)
      body:=bdtext
    

    Pub GetBodyText
      return body
    

    bdtext is string("text")
    How does spin handle this? if·it·just save a byte of the bdtext address in body[noparse][[/noparse]0] then this will not work
  • Mike GreenMike Green Posts: 23,101
    edited 2008-08-05 18:06
    You're right. string("text") returns the 16 bit address of the string "text" which won't fit in a byte. You probably meant to do:
    byte body[noparse][[/noparse]30]
    
    PUB SetBodyText(bdtext)
       bytemove(@body,bdtext,strsize(bdtext)+1)
    
    PUB GetBodyText
       return @body
    
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 20:24
    Hi Hippy...thanks...I already do that but when you have bugs like this one...you do not get any output...
    As soon as I get home I'll try your suggestion....I should stop thinking like I am programmi in VB [noparse]:)[/noparse] [noparse]:)[/noparse] [noparse]:)[/noparse]
    Thanks
  • nicolad76nicolad76 Posts: 164
    edited 2008-08-05 21:53
    Thanks guys...it did work!!!!!!
Sign In or Register to comment.