CHDK - virtual keyboard - testers needed! - page 12 - General Discussion and Assistance - CHDK Forum

CHDK - virtual keyboard - testers needed!

  • 150 Replies
  • 48015 Views
Re: CHDK - virtual keyboard - testers needed!
« Reply #110 on: 21 / January / 2012, 04:32:40 »
Advertisements
Ahh... I said a long time ago that the charmap should be an array of arrays without "|" separator and so on... I'll try to implement this, but this is a lot of work now :/

My ideas:

1. The charmaps in this version should be:

Code: (c) [Select]
const char *tbox_chars_default[][4] =
    {
        {"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"123","456","789","0+-=*/"},
        {".,;?!","@#$%^&","()[]{}","<>\"'`~"}
    };
const char *tbox_chars_russian[][4] =
    {
        {"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"ÀÁÂÃÄÅÆ","ÇÈÉÊËÌÍ","ÎÏÐÑÒÓÔ","ÕÖ×ØÙÛÜÝÞß"},
        {"àáâãäåæ","çèéêëìí","îïðñòóô","õö÷øùûüýþÿ"},
        {"123","456","789","0+-=*/"},
        {".,;?!","@#$%^&","()[]{}","<>\"'`~"}
    };


2. We don't need that:
Code: (c) [Select]
const char **charmaps[] = { tbox_chars_default, tbox_chars_russian };

We rather need a numbered list (array) of available charmaps, like:
charmaps={"default", "russian", "polish", "german"}
and then on init we just need to do something like switch/case based on tconf value, where appropriate charmap is loaded:
Code: [Select]
...
case "russian" {
    charmap=tbox_chars_russian
}

I know it's not correct way to load an array to arra, this is just an idea with pseudocode ;)

I'm not sure if whole rewrite would be not better idea, than fixing existing code...

EDIT
Or maybe instead of switch/case with loading array to array it is possible to do a pointer to appropriate array? Ehh... I'm a chemist, not a programmer so there is a lot of unclear things here to mee...
« Last Edit: 21 / January / 2012, 06:34:31 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

Re: CHDK - virtual keyboard - testers needed!
« Reply #111 on: 21 / January / 2012, 07:55:00 »
That's a god idea but if found subgroup_offs and then it should work without arrays. :D
I'm trying to implement it but there comes the error:
Code: [Select]
Der Befehl "which" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.
"**** GCC 4.4.0 : BUILDING CHDK-CHDK, #1.1.0 FOR sx230hs-100c"
"i" ist syntaktisch an dieser Stelle nicht verarbeitbar.
gmake: *** [all-recursive] Error 255
It means in English:
The command "which" isn't typed correct or not found
and then:
"i" could syntactically not be processed at this point.

I don't know why this comes (yesterday I could compile).  :( :( :(


-- EDIT: --
The error is solved.
Also I've made a better version, where all lines are correctly centered and cleared. (without charmap as array)
« Last Edit: 21 / January / 2012, 10:18:55 by TobiMarg »

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: CHDK - virtual keyboard - testers needed!
« Reply #112 on: 22 / January / 2012, 04:25:04 »
1. The charmaps in this version should be:

Code: (c) [Select]
const char *tbox_chars_default[][4] =
    {
        {"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"123","456","789","0+-=*/"},
        {".,;?!","@#$%^&","()[]{}","<>\"'`~"}
    };
const char *tbox_chars_russian[][4] =
    {
        {"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"ÀÁÂÃÄÅÆ","ÇÈÉÊËÌÍ","ÎÏÐÑÒÓÔ","ÕÖ×ØÙÛÜÝÞß"},
        {"àáâãäåæ","çèéêëìí","îïðñòóô","õö÷øùûüýþÿ"},
        {"123","456","789","0+-=*/"},
        {".,;?!","@#$%^&","()[]{}","<>\"'`~"}
    };


2. We don't need that:
Code: (c) [Select]
const char **charmaps[] = { tbox_chars_default, tbox_chars_russian };

We rather need a numbered list (array) of available charmaps, like:
charmaps={"default", "russian", "polish", "german"}
and then on init we just need to do something like switch/case based on tconf value, where appropriate charmap is loaded:
Code: [Select]
...
case "russian" {
    charmap=tbox_chars_russian
}

Unfortunately C does not have multi-dimensional arrays, you can simulate them with pointers to pointers and the compiler will kindly enough allow you to define what look like multi-dimension arrays. But things get messy when you want to pass them around or assign them.

To do what you are proposing you could use:
Code: [Select]

typedef char    *cmap[][4];

// Char maps
cmap tbox_chars_default =
    {
        {"ABCDEF","GHIJKL","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"123","456","789","0+-=/"},
        {".,:;?!","@#$%^&","()[]{}","<>\"'`~"},
        {0}
    };
cmap tbox_chars_russian =
    {
        {"ABCDEF","GKLHIJ","MNOPQRS","TUVWXYZ"},
        {"abcdef","ghijkl","mnopqrs","tuvwxyz"},
        {"ÀÁÂÃÄÅÆ","ÇÈÉÊËÌÍ","ÎÏÐÑÒÓÔ","ÕÖ×ØÙÛÜÝÞß"},
        {"àáâãäåæ","çèéêëìí","îïðñòóô","õö÷øùûüýþÿ"},
        {"123","456","789","0+-="},
        {" .:,",";/\\","'\"*","#%&"},
        {0}
    };

cmap *charmaps[] = { &tbox_chars_default, &tbox_chars_russian };

But then to access one of the map strings you need to use:
Code: [Select]
    (*charmaps[tconf.char_map])[line][group];

This line will return you the map string for the given line and group within the line (of the currently selected map).

Whether this makes things any easier or not is debatable.

Phil.

CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: CHDK - virtual keyboard - testers needed!
« Reply #113 on: 22 / January / 2012, 07:38:24 »
Thank you for all your patience!

According to Lua textbox command I suggest more complex interface:

Code: (c) [Select]
static int luaCB_textbox( lua_State* L ) {
    // Disconnect button input from script so buttons will work in the textbox
    state_kbd_script_run = 0;
    if (module_tbox_load())
    {
        // Push textbox action onto stack - will loop doing nothing until textbox exits
        action_push(AS_TEXTBOX);
        // Switch to textbox gui mode. Text box prompt should be passed as param.
        module_tbox_load()->textbox_init(
                         (int)luaL_optstring( L, 1, "Text box" ),        //title
                         (int)luaL_optstring( L, 2, "Enter a text" ),    //message
                         luaL_optstring( L, 3, ""  ),                    //default string
                         luaL_optnumber( L, 4, 30),                      //max size of a text
                         return_string_selected);
    }
    else
        return_string_selected(0);

    // Yield the script so that the action stack will process the AS_TEXTBOX action
    return lua_yield(L, 0);
}

However I get warning:

Code: [Select]
luascript.c: In function 'luaCB_textbox':
luascript.c:856:41: warning: passing argument 3 of 'module_tbox_load()->textbox_init' discards qualifiers from pointer target type
luascript.c:856:41: note: expected 'char *' but argument is of type 'const char *'

and not sure how to change char to const char...
« Last Edit: 22 / January / 2012, 07:40:51 by outslider »
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick


*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: CHDK - virtual keyboard - testers needed!
« Reply #114 on: 22 / January / 2012, 13:56:04 »
and not sure how to change char to const char...

This will answer the question asked:
Code: [Select]
                         (const char*)luaL_optstring( L, 3, ""  ),                    //default string

but as pelrun pointed out this will fix the warning - but is not the best solution, updating the function signature would be preferable
Code: [Select]
                         (char*)luaL_optstring( L, 3, ""  ),                    //default string

Phil.
« Last Edit: 22 / January / 2012, 22:01:13 by philmoz »
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: CHDK - virtual keyboard - testers needed!
« Reply #115 on: 22 / January / 2012, 21:41:28 »
You have it backwards; the value being passed in is const char*, and the function is expecting char*.

You really shouldn't cast away const-ness except in exceptional circumstances (usually where the underlying implementation is non-const but it passes through an interface that shouldn't be allowed to change it directly).

Since that parameter isn't modified by the function (if it's non-null, it's strcpy'ed into another buffer), then the function should be changed to expect const char*. The compiler will happily let you pass either char* or const char* to a const char* parameter without comment.

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: CHDK - virtual keyboard - testers needed!
« Reply #116 on: 22 / January / 2012, 22:03:42 »
You have it backwards; the value being passed in is const char*, and the function is expecting char*.

You really shouldn't cast away const-ness except in exceptional circumstances (usually where the underlying implementation is non-const but it passes through an interface that shouldn't be allowed to change it directly).

Since that parameter isn't modified by the function (if it's non-null, it's strcpy'ed into another buffer), then the function should be changed to expect const char*. The compiler will happily let you pass either char* or const char* to a const char* parameter without comment.

Thanks, I didn't look closely at the error message; just answered the question posed :)

Yes updating the function signature would be better and in this case easy as the function is not used a lot.
The use of 'const' is a bit hit and miss across the CHDK code, so casting is sometimes easier than updating every usage of a function.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: CHDK - virtual keyboard - testers needed!
« Reply #117 on: 23 / January / 2012, 00:47:39 »
Update: Another problem with the 'charmap' file implementation is that once you select the 'russian.key' file there is no way to go back to the default except by resetting all settings in the Visual Settings menu.
Just select any empty file and charmap will be reset to default.

One additional reason to have charmap are alternate textbox implementation. For example touch-screen based. Which one module will process tbox is defined in first line of charmap.


*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: CHDK - virtual keyboard - testers needed!
« Reply #118 on: 23 / January / 2012, 02:28:37 »
Update: Another problem with the 'charmap' file implementation is that once you select the 'russian.key' file there is no way to go back to the default except by resetting all settings in the Visual Settings menu.
Just select any empty file and charmap will be reset to default.

Didn't happen when I tested it - reset was the only way to get rid of it.

Quote
One additional reason to have charmap are alternate textbox implementation. For example touch-screen based. Which one module will process tbox is defined in first line of charmap.

So far only one touch screen camera has any form of touch screen input enabled (the IXUS310).
Based on the negligible feedback this is not a very popular camera and there are few CHDK users.

Given how infrequently text input is needed (for the average user), and the difficulty of using such a small touch screen (I have one and it's a pain to use), I doubt very much anyone would bother to implement such an interface - I know I won't be.

If it did happen then there are other ways to integrate it into the system that aren't as complex - this dual purpose use of the charmap file is overly complicated in my opinion.

I think the implementation in the tbox_test branch is cleaner and easier to use.

I suggest we take a vote on which is preferred - trunk or tbox_text, then move on.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

Re: CHDK - virtual keyboard - testers needed!
« Reply #119 on: 23 / January / 2012, 05:10:45 »
I'd vote on new implementation (in tbox_text branch). I think that it's good idea to give the user only names of charmaps instead of files. It gives away some freedom (not everybody could do his own charmap) but now I see it's rare situation.

I only don't know, wheter is better to have tbox submenu, since it has only entry (charmap). However, who knows, wheter there will be other settings for this module (key layout? colors?).

Also in a case of moving to the trunk Lua implementation should be updated.
if (2*b || !2*b) {
    cout<<question
}

Compile error: poor Yorick

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal