HiJack In the Box – Part 3 – iPhone HiJack Tutorial

August 21, 2011

Part 1 | Part 2 | Part 3

Now that our setup is done let us get on with the code!

From the HiJack readme we would do just a couple of things and “The simplest way is to open the project, and make it. Then, add the libHiJack.a and HiJackMgr.h to your iPhone application to easily integrate the HiJack lib to our app. But from Part 2 of our tutorial, I think I had experienced otherwise.

For those of you who would like to view the code and follow through, you can download it from here:

https://github.com/wendellinfinity/HiJackInTheBox

Anyway, to start, let us go to the HiJackInTheBoxAppDelegate.h file and then add in the delegate and the instance variable:

24 $ Pasted Graphic

Then going to our HiJackInTheBoxAppDelegate.mm file, we will have to initialize the hiJackMgr instance variable:

25 $ Pasted Graphic

Of course, it won’t be complete withouth deallocating it, so here we go:

26 $ Pasted Graphic

Then let us implement the (int) receive delegate still on our HiJackInTheBoxAppDelegate.mm file:

27 $ Pasted Graphic

Let us test our code and build it, I hope you’d get the a success:

28 $ Pasted Graphic

We can now move on to our view! But first, how can we pass our sensor’s value to the view? We can create a new “(float) sensorValue” property on our HiJackInTheBoxViewController.h file:

29 $ Pasted Graphic

and synthesize it on our implementation file HiJackInTheBoxViewController.m:

30 $ Pasted Graphic

Going back to our HiJackInTheBoxViewController.m code, we can look for the code that makes the gradient box bounce:

31 $ Pasted Graphic

and replace it with our sensorValue property:

32 $ Pasted Graphic

Hmmm.. now we have a clue that the transY variable is the one that calls the shots! So let us find more of it and replace it with our sensorValue variable:

33 $ Pasted Graphic

to this:

34 $ Pasted Graphic

Now let us run the app! Be sure to plug in your HiJack to your iOS device and when you do, turn up the volume too. Hmmm.. but wait, if you are running it you now would notice that there is no movement from the box. It is because that our implementation before for the (int) receive delegate is not yet complete. Here it is now going back to the HiJackInTheBoxAppDelegate.mm source:

35 $ Pasted Graphic

Why divide? Since the value of UInt8 may range from 0 to 255, we can get a “percentage” value instead and pass this to the viewController.

So try it now and run it!
Here is a video showing the action:

 

I hope you can now control the box, up and down a little. But there is a bit of a snag with it because it does not respond quickly. I will contact the HiJack lib developers about this and keep you posted.

Here is the link to the code again:
https://github.com/wendellinfinity/HiJackInTheBox

I hope you have enjoyed this 3 part tutorial! Comments are very welcome.

;


About these ads

37 Responses to “HiJack In the Box – Part 3 – iPhone HiJack Tutorial”

  1. mads said

    Great work, It is hard to guess all those special settings!

    did you ever try to get the speed up ?

    • Thanks Madz. For the speed up, I made the lib as a class and not a delegate. However I am still trying out to execute the code on another thread. I have not yet committed the change in git though.

      • Mads said

        hi,

        I meant if you have accomplished the 8.82 Khz mentioned instead of the very low bit rate used by the original software ?

        br,
        Mads

  2. Ow I am not into it because I am also having a bit of a challenge with the TinyOS firmware loaded on the HiJack to add more ports (and also means to alter the ‘protocol’ used in the libhijack code).

  3. That was very helpful! Thanks!

  4. tom said

    hey great writeup. im thinking of using a sensor with this great device though the sensor uses 100ma(max120) to start up. can this circuitry run such current?

    • Hello Tom,

      Thanks for that. From the project site, it tells that it “… can supply 7.4 mW to a load …” and from that we can compute for the load of your sensor given it is: max 120ma; assuming it will operate on the max voltage of the hijack module which is 3.3V; we can get that the load of your sensor is 0.396 watt (Volts x Current) or 396mW. We can say that it is beyond the supply of the hijack module. However it may depend on the voltage requirement of your sensor, if it is < 1V then we can try it anyway. In my opinion, maybe we can only use resistive sensors like the temp or light for now.

      Hope it helps,
      Wendell;

      • tom said

        hmmm. thanks for the reply. what about using this circuit for charging a super capacitor say a “Super capacitor 5.5V 0.22F” what would be the charge times etc??

  5. tom said

    oh and here are the specs of the sensor i would like to use

    heater voltage = 0.9v +or- 0.1v
    loop voltage <6vdc

    heater current 120ma
    sensor consumption <10mw

    • hello there Tom,
      My apologies for the late reply.

      @capacitor: I’m afraid I cannot give you accurate answers but from the looks of it, when working with that low output, you might need maybe a super capacitor charging IC as it will be easier, short of making an energy harvester thing (here: http://www.sparkfun.com/products/9946)

      @sensor: Hmm this kinda looks like an smoke sensor or alcohol sensor, if I may guess but I’m sorry if I did. Since I may fail you with my comment above about the cap, then I may help you on how to power the sensor, though I failed in trying, maybe you can have a better implementation of hooking up a coin cell battery instead to power up the big sensor. You can use analog optoisolators between the sensor circuit and the main board too.

      I hope it makes sense;

  6. tom said

    not a problem you have been a great help. its a methane sensor. using a supercap might be the way to go. i really do appreciate your help, i will let you know my progress :)

  7. I already have my HiJack Pack and I test part 1 of this tutorial. The problem is when i want to download the firmware. I follow the step one but in the second steep says “Insert the programmer into the USB port of PC. The red LED D1 should be lit. Then change the USB serial Port to COM1″ in my devices doesn’t apper something like that :S Another question is if I can modify the program in the mainboard. Thank you

  8. J said

    Hi Wendell – fantastic tutorial! I was just wondering if you ever managed to get the speed up to scratch in your code. I looked at some of the code in the HijackMgr.mm which seems to have some commented out sections that might make the transmission faster.

    In particular it mentions a sampling rate as well as the number of stop bits to transmit. Also, I was wondering if you’d tried (I’m sure you have) altering the hardware sampling rate using AudioSessionSetProperty. I haven’t got my Hijack device yet so I’m unable to test whether this works – was just wondering what you thought of those ideas.

    • Hello J, my apologies for the late reply. I have not tried to alter the sampling rate, but from the top of my head, changing this will have an impact to the behavior of the Manchester encoding protocol because it relies on the sampling rate on how to determine the edges when transmitting 1 or 0.

  9. iqbal said

    i just want to know what values are coming from potentiometer. i mean asci of numerical values are sent .

  10. grundyoso said

    As I began adding the HiJackMgr.mm instance calls with my AppDelegate.h file I started getting some weird build errors:

    Unknown type name ‘class'; did you mean ‘Class’?

    http://stackoverflow.com/questions/8588734/unknown-type-name-class-did-you-mean-class

    To fix I changed the following build settings under Project->BuildSettings->Language->Compile Sources As to “Objective-C++”

    I’m using Xcode4.3.2 with iOS SDK 5.1

  11. Cong said

    From the paper of Hijack, it said the phone’s headset ports as follows:
    +++
    The right channel pro- vides power to the energy harvesting circuit. The left chan- nel provides data output from the phone to the microcontroller. The microphone provides data input from the microcontroller to the phone.
    +++

    As for the energy harvesting from right channel always is not with enough power, I would remove those part from circuits. Is there any side effect if I do this?
    Also, I would ask the advice which code is for this handling?
    – energy harvesting.

    What kind of signals is output from left channel? And what kind of output microphone will get if the A6 input is changed?

    Thanks,

  12. Dev said

    Fantastic tutorial.

    I have a basic question. When HiJack is connected to the phone and is in operation, can I still play regular audio via phone’s speakers? Is there a trick for it?

    • For now, I am not aware of any approach (albeit not possible) on how to simultaneously play audio on the loudspeaker while the headphone jack is being used. This behavior is controlled by iOS itself. My apologies if I am not able to help you out on this.

      • Dev said

        Thanks for the reply. Can there be an intermittent solution, so while playing audio on the speaker, HiJack is paused/stopped/disabled ( and/or audio jack is not detected) and then when audio is stopped, HiJack resumes again ?

        In the HiJack code, there are interrupts routine for kAudioSessionEndInterruption and kAudioSessionBeginInterruption . Is HiJack interrupted when audio from other App or incoming call is played ?

        • Yes indeed the HiJack output is stopped as when the Audio Session is initialized (AudioSessionInitialize) the audio interrupt handler is also put in place (the code you were referring to). It will stop the audio from the app and then resume if the interruption ended. You may plug in your code there. For the audio jack event, you may look at the usage of “kAudioSessionProperty_AudioRouteChange”, “kAudioSessionRouteChangeReason_OldDeviceUnavailable” and “kAudioSessionRouteChangeReason_NewDeviceAvailable”. Hope it helps.

  13. find out said

    I like the helpful info you provide in your articles.
    I’ll bookmark your blog and check again here
    frequently. I’m quite certain I’ll learn a lot of new stuff right here!
    Good luck for the next!

  14. Kaiser said

    If I want to use hijack lib on iOS7, do I need some special concern?

  15. VIP wholesale cheap Red Wings jerseys china

  16. Verla said

    I was curious if you ever thought of changing the structure of your
    site? Its very well written; I love what youve got to say.

    But maybe you could a little more in the way of content so people
    could connect with it better. Youve got an awful lot of text
    for only having one or two pictures. Maybe you could
    space it out better?

  17. Elissa said

    We stumbled over here by a different page and thought I may
    as well check things out. I like what I see so
    now i’m following you. Look forward to finding out about
    your web page repeatedly.

  18. This change is due to the personalized results that Google uses as a way to provide you
    with relevant search results. Keeping all these factors in mind, you should shortlist a couple
    of SEO providers and accordingly select the one that is most conducive to your budget.

    Using CSS sprites is the best way to develop the
    web page performance by dropping the number of HTTP requests which are required
    for rendering images, but it requires lots of measuring,
    planning, and coding if the work is to be done manually.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: