supplierdeeply

Detecting keypresses and using them to change script options (uBASIC)

  • 4 Replies
  • 261 Views
Advertisements
I am working on a flashlight program (using the front AF light and the rear blue light) for the A570 IS. Currently the main code works, but getting the parameters such as backlight off, or getting the program to react to keypresses does not work. Is there any code I could use, or methods of doing so?
A570IS 101a, if that's what matters the most.

*

Offline reyalp

  • ******
  • 11541
Re: Detecting keypresses and using them to change script options (uBASIC)
« Reply #1 on: 15 / August / 2018, 01:40:15 »
I am working on a flashlight program (using the front AF light and the rear blue light) for the A570 IS. Currently the main code works, but getting the parameters such as backlight off, or getting the program to react to keypresses does not work. Is there any code I could use, or methods of doing so?
You detect key presses in ubasic, see  ubtest.bas file for example
https://app.assembla.com/spaces/chdk/subversion/source/HEAD/trunk/CHDK/SCRIPTS/TEST/ubtest.bas

I'm not sure what you mean by "getting parameters"

In case you haven't found it already https://chdk.wikia.com/wiki/CHDK_Scripting_Cross_Reference_Page is a good place to start if you are looking for script commands.
Don't forget what the H stands for.

Re: Detecting keypresses and using them to change script options (uBASIC)
« Reply #2 on: 15 / August / 2018, 03:00:12 »
Okay. By getting parameters I mean taking something like this (this might be nonsensical in uBASIC but it's designed to be human readable)...
Code: [Select]
@param a Backlight
if a is 1 then turn off backlight
if a ISN'T 1 then keep backlight on
.
For my early prototypes I had pulled a detect any keypress snippet out of a script on the wiki (read: LED light for A590), and that worked, however adapting it was difficult. I'll work with what you provided.
A570IS 101a, if that's what matters the most.

Re: Detecting keypresses and using them to change script options (uBASIC)
« Reply #3 on: 15 / August / 2018, 08:20:22 »
Okay. By getting parameters I mean taking something like this (this might be nonsensical in uBASIC but it's designed to be human readable)...
Code: [Select]
@param a Backlight
if a is 1 then turn off backlight
if a ISN'T 1 then keep backlight on
.
You've got it sort of correct.  The user parameters are simply uBASIC variables you assign a value to with the @param keyword.  You can then changed them from the Script menu.  They are used just like any other variables in the script's code.  But in your example, you can't use Backlight - it needs to be a number.

Code: [Select]
@param a 0
if a is 1 then turn off backlight
if a ISN'T 1 then keep backlight on
.

If you want to know how to determine the current state of the backlight or other camera settings, there are several different techniques.  Start with this one : CHDK Property Case

Quote
For my early prototypes I had pulled a detect any keypress snippet out of a script on the wiki (read: LED light for A590), and that worked, however adapting it was difficult. I'll work with what you provided.
I don't use uBASIC so I don't have a lot of handy examples.  However, this CHDK wiki page [  yet another DOF stacker ] has a working example of using the three uBASIC scripting functions you will need  (links):  is_key , is_pressed , wait_click
« Last Edit: 15 / August / 2018, 08:36:37 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline reyalp

  • ******
  • 11541
Re: Detecting keypresses and using them to change script options (uBASIC)
« Reply #4 on: 15 / August / 2018, 13:35:19 »
If you want to know how to determine the current state of the backlight or other camera settings, there are several different techniques.  Start with this one : CHDK Property Case
FWIW, I don't think there's any known way to get the state of the backlight. You can get the Canon display mode from a propcase. The LCD brightness might be available in a flash param, but AFAIK doesn't reflect backlight on/off.
Don't forget what the H stands for.

 

Related Topics