Shop OBEX P1 Docs P2 Docs Learn Events
IR RxTx PropGCC code. — Parallax Forums

IR RxTx PropGCC code.

I have been working with my Badges, and it looks like I need to add another system to the mix, a QuickStart (QS) + Human Interface Board (HIB). I was hoping I could do this all in C.

I looked in the OBEX, did not find any C code for IR that I could use with the QS+HIB, now I am wondering if I missed something there. I did find some Spin code, jm_irtxserial.spin, but that is only half of what I would need. Besides, I would have to run it through spin2cpp; still wondering if there is some pure C code for the IR rx/tx, that could be used as a function.

After looking at the Spin code, jm_irtxserial, I noticed it contained some PASM code. If you were doing something like this in C, would it need the PASM code included with the C code to make it all work. In other words, can an IR driver be made strictly in C, without having to use PASM code? I am hoping a discussion about this could lead to a small IR rx/tx driver written in C.

Ray

Comments

  • I created C++ wrappers for JonnyMac's IR code for the DefCon-22 badge. I've attached a zip file containing the code along with his Spin code. I use the PASM part of his code with my C++ code. There is also a SimpleIDE project that should build all of it.
  • Thanks David.

    I found jm_ir_hdserial.spin, and since I recommended, in another thread, the use of spin2cpp, I ran this Spin file through spin2cpp. Their is something different about the latest spin2cpp v1.93, in the way it handles and or creates the functions.

    In the resulting C file, I am seeing functions like 'int32_t ir_start(ir *self, int32_t rxd, int32_t txd, int32_t baud, int32_t freq)'. The thing that I cannot figure out is 'ir *self', what is this reffering to, the rest of the variables are almost self explanatory. Maybe I should take back that recommendation to use spin2cpp.

    The last time I used spin2cpp, it was pretty straight forward, and the resulting functions were relatively easy enough to use in your program. In the above, I renamed jm_ir_hdserial.spin to ir.spin, I thought the shortened name would be easier to deal with. Anybody have clue what the 'ir *self', is or is doing? I also used 'spin2cpp -ccode ir.spin', to create just the functions, and not a result with a 'main'.

    Ray
  • Heh, that's someone trying to write use object-oriented principles in C :P

    the `ir` type is likely a struct with variables related to the ir functions. So `ir *self` is a pointer to all of the variables needed for any ir function. If it were a class, `self` would simply be referred to as `this` and the variables in the `ir` struct would simply be member variables of the `ir` class.
  • And to use it, you might write some code like so:
    ir my_ir_instance;
    int32_t success = ir_start(&my_ir_instance, 0, 1, 9200, 10)
    

    (I'm taking a wild guess on the return value of `ir_start`... it might not return success/fail)
Sign In or Register to comment.