Shop OBEX P1 Docs P2 Docs Learn Events
New to prop plz help - PS2_HIDEngine — Parallax Forums

New to prop plz help - PS2_HIDEngine

LA3QMALA3QMA Posts: 13
edited 2010-09-14 10:29 in Propeller 1
Trying to get to know SPIN :idea:

So i have been trying to use PS2_HIDEngine
I'm using Propeller Demo Board.

Reading the documentation for PS2_HIDEngine i have to start the engine.
The demoboard is using 26 and 27 for the keyboard.

Trying this code:
CON
  _clkmode = xtal1 + pll16x ' Crystal and PLL settings
  _xinfreq = 5_000_000 ' 5 MHz crystal x 16 = 80 MHz
OBJ
   keyb : "PS2_HIDEngine"

PUB Main
  keyb.HIDEngineStart(27, 26, -1, -1, %001, 0, 0)
  keyb.keyboardReady
  if result == true
    LED_Flash(16,30,5)
  
PUB LED_Flash(Pin, Duration, Count)

Duration := clkfreq / 100 * Duration
dira[16..23]~~

repeat Count * 2
  !outa[Pin]
  waitcnt(Duration + cnt)

I'm expecting to get the LED flashing if the keyboard is connected and ok.
"Returns true if the keyboard is present and ready and false if not."

I just need a kick in the b*t to get started...

Comments

  • John AbshierJohn Abshier Posts: 1,116
    edited 2010-09-13 15:27
    I would like to help but I don't know where the code fro PS2_HIDEngine is located. In the propeller tool select file-archive-project. That will create a zip file with all you code. You can then attach it with your question.

    John Abshier
  • Cluso99Cluso99 Posts: 18,069
    edited 2010-09-13 15:58
    LA3QMA: Welcome to the Forum. You will have a great time with the prop.

    I don't know about the PS2 engine of Kye's. However, that should not be a problem to track down your problem.

    Have you tried commenting out the 3 lines (2 with keyb.xxx and the if line) and replace the if line with "repeat". This way you will just flash the led permanently.

    Now, your clkfreq = 80,000,000 (probably) so...
    duration := 80,000,000 / 100 * 30
    := 800,000 * 30
    := 24,000,000
    So you are going to flash the led for
    24,000,000 * 12.5ns = 300ms or ~1/3 second which you should see.

    Personally, I prefer to use
    DIR[Pin]:=1

    After this works, then remove the repeat and put all lines back and just before the if line insert
    result := true

    This way you will prove if the PS2 engine is returning true or not true.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2010-09-13 23:10
    Assuming you expect the method keyboardReady to return True, then the line:
    keyb.keyboardReady
    

    should be changed to:
    result := keyb.keyboardReady
    

    As your code is now, result would still be zero.

    Many methods do not return TRUE on sucessful. TRUE is also -1 ($FFFFFFFF). The method rxcheck in FullDuplexSerial returns -1 (TRUE) if no new byte was received.

    Follow Cluso99's advice if adding "result :=" doesn't fix things (I don't think Cluso99 noticed it was missing in your code) .

    Cluso99's advice has a typo. He left out the A in DIRA.

    As your code is now:
    dira[16..23]~~
    

    Will not set "Pin" to and output if the parameter (Pin) is outside of the range 16 to 23.

    Duane
  • LA3QMALA3QMA Posts: 13
    edited 2010-09-13 23:54
    Ok so then i have to check "PS2_HIDEngine" to see what it returns as true/false

    Browsing the code i can see that it should return something in "result".

    I have tried this:
    result := keyb.keyboardReady
    

    So i guess the first ting is to check what the PS2_HIDEngine is actually returning.

    Regarding the DIRA[] this was just added because i don't like the "debugger". Is is possible to send "debug" information to something other than the parallax serial terminal? I liked the BS2 editor better.

    Tnx for the help so far... I'm probably going to post more newbequestions to get to learn the SPIN better.
  • AribaAriba Posts: 2,690
    edited 2010-09-14 00:19
    LA3QMA wrote: »
    Browsing the code i can see that it should return something in "result"....

    result is a local variable inside a methode (subroutine) which holds the value that the methode returns. You can't access this variable outside the methode with "if result == true".
    You can assign the returned value to a variable:
    varX := keyb.keyboardReady

    or you use the methode inside an expression:
    if keyb.keyboardReady == true

    you even can write:
    if keyb.keyboardReady
        LED_Flash(16,30,5)
    

    Andy
  • LA3QMALA3QMA Posts: 13
    edited 2010-09-14 10:29
    I would like to say tnx once more...

    PS2_HIDEngine has been abandoned for now.

    So i'm using the original parallax "Keyboard" object and my "advanced" code actually works. The object is a bit limited but it's enough to get me started.

    I can always use PS2_HIDEngine or similar later but i don't want to use more time on this now...

    So problem solved.... so stay tuned for my next questions :smilewinkgrin:
Sign In or Register to comment.