Shop OBEX P1 Docs P2 Docs Learn Events
Quick Media Player (new touchscreen for Quickstart!) - Page 3 — Parallax Forums

Quick Media Player (new touchscreen for Quickstart!)

13

Comments

  • skylightskylight Posts: 1,915
    edited 2013-03-22 10:58
    Rayman you must have posted at the same time as myself, see post above yours on page 3 :smile:
  • RaymanRayman Posts: 14,665
    edited 2013-03-22 11:08
    Hurray! I was running out of ideas...
  • skylightskylight Posts: 1,915
    edited 2013-03-22 11:55
    And now that i've got passed the hurdle i've adapted the code again to include a pause button instead of the green glowing play button, both bitmaps included in case you wish to use either. save bitmaps to root of uSD along with wav files
    Artist and album title can be changed to whatever is needed.


    Read the readme txt for further info

    The play button changes to a pause button but the code needs to be written to toggle the bitmaps back and forth and also to pause the wavs

    I think that this will involve putting the touchscreen code in another cog so a repeat loop can run indefinitely and pass presses to the main program this will also make it easier to have toggles like the backlight on and off

    I checked the current draw with the player and all leds running and it came out to approx 155ma running at 4.5 V on battery power, is this ok for an unpowered USB port? Noticed the usb plug that goes into the laptop gets warm.


    One question does the screen allow support for using an alpha channel on the bitmaps as it would save having to change the bitmaps backgrounds whenever the main background is changed.
  • RaymanRayman Posts: 14,665
    edited 2013-03-22 12:46
    The screen does not have alpha channel support. You could probably add this with code, but it would be slow...
    Using square buttons would probably solve this problem.
    Another way might be to use 4 or 8 bit bitmaps with the background color forced to be some constant color number. Then, you could just change the palette so the image background color matched the screen background.
    All a lot of work compared to using rectangular button areas...
  • skylightskylight Posts: 1,915
    edited 2013-03-22 13:05
    Its no problem to edit the controls with an editor using fill so not an issue
    an editor like zoner photo studio allows you to enter the RGB values that you chose for the background to the bitmap fill

    I'm trying to understand from the code how the touchscreen area for the play button is worked out. so that could be applied to the different controls

    Is this done with a square over the button or does the code work out the shape and size of the button?
  • RaymanRayman Posts: 14,665
    edited 2013-03-22 13:14
    I figured it out by drawing a white rectangle on top of the screen and playing with the coordinates until it was where I wanted it...
    (Probably not the best way). You can probably still find, commented out, the line that draws the rectangle.
  • skylightskylight Posts: 1,915
    edited 2013-03-22 13:20
    I wonder if coordinates that use a centre and a formula for diameter could also work out the area for circular objects like the play/pause button? Probably easier with the rectangle though

    I'll look for the code and experiment a bit

    Found the code but why are there dashes between the last three numbers 240-51-20 rather than commas are those numbers being subtracted from 240 and which number corresponds to the correct buttonPlay array variable?

    sorry to keep asking questions but with this knowledge I can look at creating touchscreen areas for the other controls in advance of the code for actually doing something with the press.

    That's if you don't mind me doing so
    bmp(50,240-51-20,string("PlayBG.bmp"))  'Play button with light green background
      'lcd.DrawRectangle(lcd#rgb_white,buttonPlay[0],buttonPlay[2],buttonPlay[1],buttonPlay[3])  'see where button is
    
  • RaymanRayman Posts: 14,665
    edited 2013-03-22 13:38
    no problem. The dashes are minus signs... I started with 240 and the tried moving it up 51 pixels and then moved it up another 20 pixels..
    Was being lazy...
  • skylightskylight Posts: 1,915
    edited 2013-03-22 16:26
    Thanks for that info it's enabled me to work out the coords of the stop button(to the pixel) , some of the coords are negative numbers is that ok?
    buttonStop byte -171,-181,189,199,1  'coords of stop button
    
    what does the 1 at the end do I tried increasing this when drawing the rectangle as I presumed it was thickness of the line but changing it did nothing?
  • RaymanRayman Posts: 14,665
    edited 2013-03-22 16:34
    That last number, "1", is what the "GetButton" function will return when button is pushed.

    The other numbers are x and y coordinates of the button on the screen. X should be between 0 and 319 and Y should
    be between 0 and 239. negative numbers won't give an error, but shouldn't be used...
  • skylightskylight Posts: 1,915
    edited 2013-03-22 17:49
    Ah Clever stuff, you've certainly worked out the structure of this code in advance!
    I can use 2 to denote the stop button which I am in the process of designing for pressed or set
    I'll redo the code to get rid of the neg numbers should be a doddle now to map the Next track and previous track buttons too

    The action code will take me a time to work out unless you are already on the case with that?
    What about the idea about the touchscreen and relevant code in a different cog and perhaps in it's own object, would that be necessary to allow touches whilst the wav plays?

    Edit: New coordinate for stopbutton without neg numbers:
    buttonStop byte 75,85,189,199,2  'coords of stop button  2=stopbutton
    

    Thanks Rayman for those snippets about the code it's really helping me to understand it
    Like in the Draw rectangle code the way you can just name the colour rather than having to type in the RGB values
    Is there a table of what colours you can use that way with the screen? Is that the eight colours mentioned in the paint code?

    Worked out the problem with sorting the tracks, load them one at a time in order rather than copying them altogether to the uSD

    New designed Stop Button(Thank heaven for the clone button feature in zoner photo studio, used to get gradiant for curve effect from adjacent button)
    Going to have to make several versions for diffent scenarios such as play button stop unset play set to pause and stop button either set or not etc etc
    or will I be able to draw a bitmap at a location like you can draw a rectangle? then it would just be a case of saving button bitmaps rather than the whole control bar for each scenario.
    , will have to change coords in the code before posting for it tomorrow too tired to do that tonight:

    Stop.JPG
    561 x 360 - 7K
  • RaymanRayman Posts: 14,665
    edited 2013-03-23 07:00
    I'll work on makeing the player and touchscreen interface better for this application...
  • skylightskylight Posts: 1,915
    edited 2013-03-23 08:58
    Have created a WavPlayerLoopControls.spin to show the sequence of button pushes from the play button to the pause button after 5 secs and then 5 secs later the stop button depresses which very quickly returns back to the start. I put this in a continuous loop in order to show what the controls look like in the intended sequence of use
    If you get a chance please have a look as I'd like comments about whether you think it looks ok or not., the three bitmaps are included in the archive and you need to click the play button to start the sequence.

    Bitmaps for next and prev buttons to follow later
    I'll work on makeing the player and touchscreen interface better for this application...

    Thanks Rayman I appreciate that


    Another question, does the bitmap draw wipe the entire screen ie if I drew a bitmap for a frame and then drew a bitmap for the controls would the controls bitmap erase the entire screen or only the portion of screen below where it's placed? The answer will decide which way to go in designing the Wavplayer screen
  • RaymanRayman Posts: 14,665
    edited 2013-03-23 10:22
    The draw bitmap function doesn't erase the screen... So, you can draw a background image and then put buttons on top of it...
  • skylightskylight Posts: 1,915
    edited 2013-03-23 13:37
    Thats great, it opens up options for different frames and controls
  • skylightskylight Posts: 1,915
    edited 2013-03-24 03:45
    Noticed another problem when trying to display a 320x240 bmp.
    I created a frame bmp at 320x240 resolution
    It displays corrupted, so tried the turtle.bmp and same corrupted, thought it was the uSD playing up so reformatted and reloaded files , same corrupted so thought try with the Gfx demo.spin and the frame bmp displays fine and also the turtle bmp also, so from this I'm assuming it's to do with the wavplayer code not liking big files at 320x240? the smaller bmp for the playbutton shows ok in the wavplayer so the issue just seems to be with larger files or I should say larger resolutions
  • RaymanRayman Posts: 14,665
    edited 2013-03-24 03:55
    I see the problem... Please remove this line from the BMP routine:

    biWidth:=214

    Don't know how that got in there.... Must have been while troubleshooting something...
  • skylightskylight Posts: 1,915
    edited 2013-03-24 04:12
    Thanks Rayman for the very quick response, i'll try that

    Edit: It works great now thanks
  • skylightskylight Posts: 1,915
    edited 2013-03-27 09:13
    Adapted Rayman's Paint program code to give ability to choose 1 of 16 line thickness's
  • RaymanRayman Posts: 14,665
    edited 2013-03-27 16:33
    Looks great, thanks for sharing. QMP Paint could definitely use more features...
    PSB and PTP Paint let you do things like switch between line and pixel mode and set background, etc...
  • skylightskylight Posts: 1,915
    edited 2013-03-27 17:24
    Thanks Rayman,

    As I think of new ideas or functions and they are within my programming ability I will add them.

    Have now added the ability to change the colour scheme or look by the touch buttons.

    Hint: hold down either the Home icon or the Email icon and wait as there are sometimes gaps between different schemes where it looks like the screen is dark but it's still scrolling through various screen layouts, it's just some are dark
    tap the note icon to accept the look and continue to the paint program.

    Screen now shows what colour paint has been selected
  • skylightskylight Posts: 1,915
    edited 2013-04-01 09:11
    Hi Rayman, I thought I might be getting somewhere with the wavplayer code in creating the coords for the stop button and assigning decimal 2 as the result for pressing it with the code snippet below:
    DAT 'define on-screen buttons
    nButtons byte 1
    Buttons byte
    buttonPlay byte 152,193,173,216,1        'x1,x2,y1,y2,handler 1=playbutton result in Getbutton routine
    buttonStop byte 75,85,189,199,2           'coords of stop button  2=stopbutton
    
    That last number, "1", is what the "GetButton" function will return when button is pushed.

    But it seems that the repeat loop
    repeat        'wait until play button pushed
        WaitStylusDown
        WaitStylusUp
        Ser.tx("*")
        ser.dec(touchx)
        ser.tx(" ")
        ser.dec(touchy)
        ser.str(string(" Button pressed= "))
        ser.dec(Buttons)
      until  GetButton==1
      ser.dec(Buttons)
    
    in main which I assumed from the statement above would return 2 is not doing so?
    As you will see I added the ser.str and ser.dec(Buttons) to see what was going on.

    In PST it showed that pressing the stop button returned decimal 152, ok fair enough I thought I'll write a routine that says 152 is the stop button instead of 2
    Until I tried several different touches around the screen and they all returned decimal 152, not good!

    Touching the play button returns 152152

    So question is where is the 1 for the play button touch being stored? As the repeat loop does quit with 1 .
    Or is the repeat loop just quitting because 1 is the equivalent of TRUE ie the DAT code above is not doing what I assumed it was supposed to from the quote above?
  • RaymanRayman Posts: 14,665
    edited 2013-04-01 14:51
    It's the "GetButton" function that will return 0, 1, or 2 depending on what is pushed.
    "Buttons" just equals the first byte defined here:

    Buttons byte
    buttonPlay byte 152,193,173,216,1

    which is 152.

    Maybe try ser.dec(GetButton) instead of ser.dec(Buttons)...
  • skylightskylight Posts: 1,915
    edited 2013-04-02 12:51
    Yes I realised my mistake today but havn't been able to try it out till tonight, have replace buttons with GetButton it does return a 1 when the play button is pressed but the stop button returns 0 not 2? Perhaps my coords are wrong? I'll try mapping the stop button again
  • RaymanRayman Posts: 14,665
    edited 2013-04-02 13:20
    I may have a commented out line of code that draws a white rectangle around the button area.
    That might be useful to see where it is...

    Haven't actually tried it with 2 buttons, but hopefully it works...
  • skylightskylight Posts: 1,915
    edited 2013-04-02 13:34
    Yes I've been using that line of code except to see the difference I made the rectangle red
    lcd.DrawRectangle(lcd#rgb_red,buttonStop[0],buttonStop[2],buttonStop[1],buttonStop[3])
    

    clicking within the red rectangle which is perfectly aligned over the stop button just returns 0(zero) every time

    with the code above am I correctly reading the DAT for the Stop button below? The red rectangle does appear in the correct position so it must be correct yet it returns only zero??
    DAT 'define on-screen buttons
    nButtons byte 1
    Buttons byte
    buttonPlay byte 152,193,173,216,1  'x1,x2,y1,y2,handler 1=playbutton result in Getbutton routine
    buttonStop byte 75,85,189,199,2  'coords of stop button  2=stopbutton
    

    To stop the wav player playing each time I tried clicking around the screen I also tried changing the 1 in the buttonPlay byte line to another number 3 and when clicking on the play button 3 was returned correctly in PST
  • RaymanRayman Posts: 14,665
    edited 2013-04-02 13:44
    Change:
    nButtons byte 1
    To:
    nButtons byte 2

    The nButtons variable tells the code how many buttons to look at...
  • skylightskylight Posts: 1,915
    edited 2013-04-02 13:45
    ok will try that

    Edit:
    That was it! am getting a returned value of 2 now although I need to expand the rectangle a little as it's a bit too small and the stylus doesn't always hit the sweet spot.
    Thanks very much Rayman, with this knowledge I can now dabble a bit more and map all the buttons and hopefully write a routine to action the button presses, will let you know how I progress.
  • skylightskylight Posts: 1,915
    edited 2013-04-04 12:54
    Made a few cosmetic changes to the look of the Wav Player.

    I am having trouble trying to work out how to get the stop button to control the wav player, I thought of just using cogstop but that didn't seem to work the way intended.

    The way I understand the code so far is that the main program including the touchscreen control is in the first cog and then the PlayWav method opens a second cog,
    so two cogs are running (not sure about the other objects opening any more cogs)

    So if we just take the it that main and PlayWav ( or is the Pasm bit running in it's own cog?) are in different cogs running together I'm having problems working out how to break into the Playwav routine to stop playing the wav file, It looks like the method fills two buffers with the wav's data and plays in two repeat loops until the buffers are empty.

    I've tried to quit the two loops by putting repeat until getbuttons==2 at the start of both loops but the trouble I'm having is getting the getbuttons method to look at the touchscreen input whilst the PlayWav method is running, I tried putting the touchscreen section in it's own method called CheckTouch and calling that within the two loops but all that does is interrupt the playing of the wav??

    I tried inserting the call to CheckTouch at different places within the two loops but had no luck each time it just stopped it playing the wav and you just get a buzz in the earphones.

    So question is how to get the program to look at the touchscreen input without interrupting the player?

    I'm at a loss as to how to progress with my limited knowledge, so meantime have been playing around with the cosmetics, so I hope you like the new look. :smile:
  • RaymanRayman Posts: 14,665
    edited 2013-04-04 17:23
    Looking pretty good!
    You can use the bTouchDown function (returns true or false) to tell if the screen is being touched.
    You can then use the code from WaitStylusDown to get x and y values...

    But really, we are probably going to need another cog, dedicated to looking at the touchscreen for this.
    It may be too unreliable to juggle checking the touchscreen and filling the play buffers from SD...

    I have some ideas on how to do this a lot better, just not the time yet...
Sign In or Register to comment.