Lua script for text input - LUA Scripting - CHDK Forum

Lua script for text input

  • 9 Replies
  • 15073 Views
*

Offline msl

  • *****
  • 1280
  • A720 IS, SX220 HS 1.01a
    • CHDK-DE links
Lua script for text input
« on: 26 / October / 2008, 06:25:51 »
Advertisements
hi CHDK friends,

this is a little demo script in Lua. :)

You can input a text as a folder name. If you want the folder will be create (A/name).

In the script parameter menu you can control the keyboard delay for repeating.

Using the script:

first consol menu

[<-][->]  select a char in 1 step
[zoom in/out]  select a char in 5 steps
[SET]  write a char
[+/-]  delete a char
[UP]  Selection uppercase, lowercase and special cases
[DOWN] return to first char (a)
[MENU]  ready and go to the second Menu

second consol menu

display the input

[SET]  return to new input
[DISP] write the input name as folder and close the script
[MENU] close the script


Attention: use not a illegal folder name - you can lose your datas

Code: (lua) [Select]
--[[
@title char input
@param f key delay
@default f 200
]]

key_delay = f
output=""

function button()
 local x = 0
 repeat
 wait_click(key_delay)
  if is_pressed "remote" then
   key = "REMOTE"
   x = 1
  end
  if is_pressed "set" then
   key = "SET"
   x = 1
  end
  if is_pressed "erase" then
   key = "ERASE"
   x = 1
  end
  if is_pressed "display" then
   key = "DISP."
   x = 1
  end
  if is_pressed "menu" then
   key = "MENU"
   x = 1
  end
  if is_pressed "up" then
   key = "UP"
   x = 1
  end
  if is_pressed "down" then
   key = "DOWN"
   x = 1
  end
  if is_pressed "left" then
   key = "LEFT"
   x = 1
  end
  if is_pressed "right" then
   key = "RIGHT"
   x = 1
  end
  if is_pressed "zoom_in" then
   key = "ZOOM_IN"
   x = 1
  end
  if is_pressed "zoom_out" then
   key = "ZOOM_OUT"
   x = 1
  end
 until  x == 1
 set_led (8,1)
 sleep (10)
 set_led (8,0)
end

function tabToStr()
output=table.concat(word)
end

function input()

abc_lower = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p",
"q","r","s","t","u","v","w","x","y","z"}
abc_upper = {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P",
"Q","R","S","T","U","V","W","X","Y","Z"}
abc_spec = {"0","1","2","3","4","5","6","7","8","9",",",".","-",";",":","_",
"/",".JPG",".CRW",".CR2",".THM",".WAV",".LUA",".BAS",".TXT"," "}
word = {}
a=0
b=0
actChar=""
repeat
print("[<-][->][SET] [+/-][MENU]")
print("[ZOOM in/out]  [UP][DOWN]")
button()
    cls()
    if key == "RIGHT" then a=a+1 end
    if key == "LEFT" then a=a-1 end
    if key == "UP" then b=b+1 end
    if key == "DOWN" then a=1 end
    if key == "ZOOM_IN" then a=a+5 end
    if key == "ZOOM_OUT" then a=a-5 end
    if a >= 27 then a=1 end
    if a <= 0  then a=26 end
    if b>=3 then b=0 end
    if b==0 then
actChar=abc_lower[a]
char_info="lower case"
end
if b==1 then
actChar=abc_upper[a]
char_info="upper case"
end
if b==2 then
actChar=abc_spec[a]
char_info="special char"
end
print(char_info..": "..actChar)
    if key == "SET" then table.insert(word,actChar) end
    if key == "ERASE" then table.remove(word) end
    tabToStr()
    print("input: "..output)
    print (" ")
  until key == "MENU"
end

function make_dir(dirname)
os.mkdir(dirname)
end


x=0
repeat
  input()
  cls()
  print("INPUT: "..output)
  print("[SET]  new input")
  print("[DISP] make dir and stop")
  print("[MENU] stop")
  button()
  if key == "SET" then cls() end
  if key == "DISP." then
  dir = "A/"..output
  make_dir(dir)
  print "ready"
  sleep(3000)
  x=1
  end
  if key == "MENU" then
print "ready"
  sleep(3000)
  x=1
  end
until x==1

--[[

***possible commands***

function make_dir(dirname)
os.mkdir(dirname)
end

function delete_dir(dirname)
os.remove(dirname)
end

function rename_file(old_filename, new_filename)
os.rename(old_filename, new_filename)
end

function delete_file(filename)
os.remove(filename)
end

***missing commands***

-os.list_dir

]]

CHDK-DE:  CHDK-DE links

*

Offline fbonomi

  • ****
  • 469
  • A570IS SD1100/Ixus80
    • Francesco Bonomi
Re: Lua script for text input
« Reply #1 on: 26 / October / 2008, 07:13:40 »
sweet!!
a little tihing to play with :-)

*

Offline PhyrePhoX

  • *****
  • 2254
  • make RAW not WAR
    • PhyreWorX
Re: Lua script for text input
« Reply #2 on: 26 / October / 2008, 08:45:31 »
Tested,works like a charm on the s3 :)

*

Offline fe50

  • ******
  • 3152
  • IXUS50 & 860, SX10 Star WARs-Star RAWs
    • fe50
Re: Lua script for text input
« Reply #3 on: 26 / October / 2008, 17:16:26 »
Hi msl,
successfully tested with the SD870 1.00C !

A very nice script to demonstrate the power of Lua, also a nice toy - not only to play with...
It can be used in combination with the file browser, e.g. cut & paste, to manage files...

Well done !

PS: I put your Lua scripts (this one & the universal Tv script) in the CHDK wikia (here) to bring Lua to the people and to give more sample stuff to the 'scripters'


*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lua script for text input
« Reply #4 on: 28 / October / 2008, 19:22:28 »
Tried it on my a570is, appears to work... Pretty neat!

With Lua expanding our scripting power, we'll soon need ways to give Lua more power over the display. I think even being able to temporarily resize the script console to cover more LCD area would be a significant improvement.


*

Offline sylikc

  • **
  • 66
  • SX230HS 1.00c, SD750 1.02a ;)
Re: Lua script for text input
« Reply #5 on: 20 / December / 2008, 09:08:22 »
oh, this is an AWESOME script... though I can't figure out what it's doing down at the * 32 part.

Can someone explain how TV is calcualated?  I see something about setting the shutter property to the selected int * 32...
> TV = tv_input * 32

Does it have anything to do with the comment on PropertyCase - CHDK Wiki that says
262 RW Tv (for next shot, updates on half-shoot), 96 per 1 stop

... of course I don't get what 1 stop means either.

Could someone help explain it? :P  I'm hoping I can turn msl's sample script to become the end-all problem of the bracketing issues on the SD750 and probably be one of those universal bracketing scripts that works on every single camera.


/sylikc
props to TPC + PhyrePhox for SD750 work: IXUS75/SD750 1.01a | 1.00b | 1.02a Thread
props to quietschi for multipartition support + button fixes!
SD750 bracketing issues

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lua script for text input
« Reply #6 on: 20 / December / 2008, 10:38:48 »
... of course I don't get what 1 stop means either.

"Full stop" mean one full exposure value unit. See for example http://en.wikipedia.org/wiki/Exposure_value. A full stop is equivalent to for example doubling or halving exposure time or ISO.

Internally our cameras calculate with finer integer numbers, dividing a full ev stop in 96 tiny steps. For sparser +-1/3 Ev steps (which is the resolution of in-camera exposure compensation via the +/- button if you have one) this means +-32 per 1/3 Ev step.

Fyi, the Tv propcase is centered around zero == Tv 1 second.

*

Offline sylikc

  • **
  • 66
  • SX230HS 1.00c, SD750 1.02a ;)
Re: Lua script for text input
« Reply #7 on: 20 / December / 2008, 18:27:49 »
i read the wikipedia page... sorta makes more sense.

However... now I don't quite get the +-1/3 Ev steps part.  I didn't think that adjusts the shutter speed at all does it?  I thought it was an in-camera post-processing adjustment... but, ok just tested it, first time i notice shutter changes.

So using the +-EV steps is telling the camera to add/subtract (32 * (1/3 steps) ) from it's internal calculations?  So if I wanted to know what the camera itself has guess the EV to be, I'd just read from prop 262 after doing half shutter, does that sound about right?

Thanks... an LUA bracketing script would be pretty cool if I can figure it out haha

/sylikc
props to TPC + PhyrePhox for SD750 work: IXUS75/SD750 1.01a | 1.00b | 1.02a Thread
props to quietschi for multipartition support + button fixes!
SD750 bracketing issues

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Lua script for text input
« Reply #8 on: 20 / December / 2008, 19:42:18 »
So using the +-EV steps is telling the camera to add/subtract (32 * (1/3 steps) ) from it's internal calculations?  So if I wanted to know what the camera itself has guess the EV to be, I'd just read from prop 262 after doing half shutter, does that sound about right?

Yes, exposure compensation affects the decision of metering, before shooting. Metering is done during half shooting. So to override in a script, you half shoot, wait for get_shoot_state() to change and then write the propcase. And note that you shouldn't use propcase numbers in scripts, prefer the mechanism provided by CHDK/LUALIB/propcase.lua for compatibility across different camera models.

And there's also a bunch of commands named set_tv* you can try.

*

Offline foofighter69

  • *
  • 15
  • Canon A470
Re: Lua script for text input
« Reply #9 on: 29 / May / 2009, 19:57:27 »
Real killer script for A470. :) It always kill my cam.
« Last Edit: 29 / May / 2009, 20:03:20 by foofighter69 »

 

Related Topics


SimplePortal © 2008-2014, SimplePortal