Results 1 to 12 of 12
  1.    #1  
    Is there a way to call shell scripts from homebrew apps through the Mojo framework or something like that?

    I ask because I've been working on a simple flashlight application. Here's how it works:
    - I installed the appWeb embedded web server from the optware package.
    - I dropped a small shell script into the web folder to flip the flashlight on and off.
    - I've written a very simple homebrew app where you can hit a switch and it sends an AJAX request to the script.
    - The flashlight turns on!

    Is this a stupid hacky way to do it or should I keep going? I'm hoping to add a brightness slider and maybe some kind of timer in the future. I think forcing the light to turn off after a certain period would be a good idea also until we know what extended use does to the light.
  2. bspesq's Avatar
    22 Posts
    Global Posts
    25 Global Posts
    You rock for working on a flashlight application. Had that on my old phone and it's shocking how much I'd come to depend on it.

    For this and all other hacks currently circulating, can't these instructions just be modified?

    Just make a new app/icon, and then dig into that app's config and just change whatever binary it's launching to just execute a shell script containing the code you've created to start the flashlight?

    Are you sure this is the way you'd want to develop it, though? Because you'd then need to have an app that launches with a 'turn off' button, or another icon, that would kill the flashlight process (or an if-else clause in the shell script that kills the flashlight if running, or turns it on if it's not running.)

    Wouldn't it make more sense to hook into button presses? On my old phone, you pressed an external key (volume) once, and depressed it again. So long as it was depressed, the light stayed on. This might be more work (you'll have to dig into the triggers for button presses), but it sounds like you're already playing with hardware function calls anyway, right?
  3.    #3  
    Ahh, see that's the problem. The apps themselves don't run binaries as far as I can tell, they're just web apps. I have a feeling Mojo won't let me run shell scripts, since that would be considered low-level access, but maybe it will let me turn the light on through the API, without accessing the shell. I guess we won't know until an SDK is released. I had a look at the camera app and couldn't see anything useful.

    I like the button idea, but I'm not sure I can just intercept button presses and have WebOS not respond to them. I'm pretty sure I can respond to button presses while the card for my app is open, but then having the button doesn't help much since you need the app on screen anyway.

    I'm going to go ahead and write the app with the appWeb server. The only thing is it's a bit of a pain if you have to install the web server, set it up correctly, THEN add my homebrew app. Also, sometimes it doesn't respond right away, you hit the button and it takes a few seconds. It seems to happen the first time I run the app after the phone starts.

    Anyway, the fact that my phone has a web server running on it is incredibly awesome, I need to think of more uses for it.
  4. #4  
    My guess is that you're going to have to use what's in the SDK to do your talking to the hardware.

    It appears that /usr/palm/applications/ $contains$ $a$ $lot$ / $most$ $of$ $the$ $calls$ $needed$ $to$ $turn$ $the$ $flash$/$LED$ $on$ $the$ $back$ $of$ $the$ $device$ $on$ $and$ $off$.

    The flash appears to have three modes: Off, Auto, and On. So, I would guess you would use the "On" mode to use it like a flashlight.

    I really wish I had my Pre already so I could test some of this out for you, but alas, the wait continues.

    Here's an example of how they use the flash in the camera app. In particular, what happens when you press the flash button in the camera app:

    if ( (this.flashState < CaptureAssistant.FLASH_OFF) || (this.flashState >= CaptureAssistant.FLASH_ON) ){
    // Cycle order is off, auto, on.
    this.flashState = CaptureAssistant.FLASH_OFF;
    else {
    Browsing a little further in the source, you may need an instance of the camera object to make your hardware calls. See the following:

    var camera = this.cameraControl.getCameraInstance();
    camera.flash = Camera.FLASH_ON;
    Last edited by whatsit2002; 06/19/2009 at 02:19 PM. Reason: new information
  5. bspesq's Avatar
    22 Posts
    Global Posts
    25 Global Posts
    And if you wanted to build an app, you'd follow this:

    And probably work with the javascript file that whatsit just mentioned?
  6. phwelo's Avatar
    527 Posts
    Global Posts
    553 Global Posts
    i know very little about javascript but i'd love to see this work. maybe this link could help? Javascript -> Shell Script - Web Programming, Web 2.0 and Mashups - The UNIX and Linux Forums
    for any questions or to send a donation:
  7. phwelo's Avatar
    527 Posts
    Global Posts
    553 Global Posts
    regarding the info that whatsit posted: it seemed to me more like that was a modifier for when the camera was actually used. like "flash: on" would mean that flash would be used when the camera was called to actually take the picture.
    for any questions or to send a donation:
  8.    #8  
    Yeah, that's how I read it. I searched the whole app for "flash" and it just seems to pass a preference (on, off or auto) to the API, which controls the camera.
  9. #9  
    I'm actually having a little trouble figuring out where _cameraInstance is defined. That would tell us what is actually getting set since that is what getCameraInstance() returns. However, I'm a little lost in the code at the moment. :P

    In addition, I'm not sure what Flash: On actually does. When you open the camera on the phone and turn the flash on, does the LED on back come on before you hit the shutter button to capture a frame? Does it stay on until you close the camera? Like I said, I don't have a phone to play with, right now.

    ANYWAY: back to the original question. The community has obviously figured out a lot about the /sys/class/i2c-adapter/i2c-2/2-0033 device. But, the only other way I can think of to get lower level access to that Linux device is through a plug-in. If you make your application a plug-in (similar to the "Native Applications" section of the "Application Framework" in the wiki h t t p:// you might be able to talk to the hardware easier... maybe.

    Of course, the plug-in approach requires even more work than an SDK call since you'll need to actually compile your application.

    Anyway, good luck and if anyone else has an idea about how to get "command line" access through javascript calls, please let us all know.
  10. phwelo's Avatar
    527 Posts
    Global Posts
    553 Global Posts
    why don't you guys take a look at how the 'graphical shell' works. it clearly accesses the shell from a browser window. pre dev wiki: Graphical Shell

    also isn't the thing turned on via editing a few files: mode, torch_current, and avin?

    wouldn't it be simpler to write the script in java and call to edit these files and place the necessary values in them?
    Last edited by phwelo; 06/19/2009 at 04:33 PM.
    for any questions or to send a donation:
  11. #11  
    Does anyone know where we can get a list of all the services like palm://com.palm.vibrate, etc? Maybe theres one like that for flash.
  12. #12  
    Just to kind of bring closure to this thread for future searchers, see this post for how to call out to the shell from webOS javascript:

Posting Permissions