diff options
Diffstat (limited to 'apps/plugins/lua/rocklib.c')
-rw-r--r-- | apps/plugins/lua/rocklib.c | 219 |
1 files changed, 154 insertions, 65 deletions
diff --git a/apps/plugins/lua/rocklib.c b/apps/plugins/lua/rocklib.c index 44eb549dae..5995fd89e9 100644 --- a/apps/plugins/lua/rocklib.c +++ b/apps/plugins/lua/rocklib.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * | 9 | * |
10 | * Copyright (C) 2008 Dan Everton (safetydan) | 10 | * Copyright (C) 2008 Dan Everton (safetydan) |
11 | * Copyright (C) 2009 Maurus Cuelenaere | 11 | * Copyright (C) 2009 Maurus Cuelenaere |
12 | * Copyright (C) 2018 William Wilgus | ||
12 | * | 13 | * |
13 | * This program is free software; you can redistribute it and/or | 14 | * This program is free software; you can redistribute it and/or |
14 | * modify it under the terms of the GNU General Public License | 15 | * modify it under the terms of the GNU General Public License |
@@ -62,27 +63,44 @@ RB_WRAP(current_tick) | |||
62 | return 1; | 63 | return 1; |
63 | } | 64 | } |
64 | 65 | ||
65 | RB_WRAP(kbd_input) | 66 | #ifdef HAVE_SCHEDULER_BOOSTCTRL |
67 | RB_WRAP(schedule_cpu_boost) | ||
66 | { | 68 | { |
67 | luaL_Buffer b; | 69 | bool boost = luaL_checkboolean(L, 1); |
68 | luaL_buffinit(L, &b); | ||
69 | |||
70 | const char *input = lua_tostring(L, 1); | ||
71 | char *buffer = luaL_prepbuffer(&b); | ||
72 | 70 | ||
73 | if(input != NULL) | 71 | if(boost) |
74 | rb->strlcpy(buffer, input, LUAL_BUFFERSIZE); | 72 | rb->trigger_cpu_boost(); |
75 | else | 73 | else |
76 | buffer[0] = '\0'; | 74 | rb->cancel_cpu_boost(); |
77 | 75 | ||
78 | if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE)) | 76 | return 0; |
79 | { | 77 | } |
80 | luaL_addstring(&b, buffer); | 78 | #endif |
81 | luaL_pushresult(&b); | 79 | |
82 | } | 80 | RB_WRAP(current_path) |
81 | { | ||
82 | return get_current_path(L, 1); | ||
83 | } | ||
84 | |||
85 | |||
86 | /* DEVICE INPUT CONTROL */ | ||
87 | |||
88 | RB_WRAP(get_plugin_action) | ||
89 | { | ||
90 | static const struct button_mapping *m1[] = { pla_main_ctx }; | ||
91 | int timeout = luaL_checkint(L, 1); | ||
92 | int btn; | ||
93 | |||
94 | #ifdef HAVE_REMOTE_LCD | ||
95 | static const struct button_mapping *m2[] = { pla_main_ctx, pla_remote_ctx }; | ||
96 | bool with_remote = luaL_optint(L, 2, 0); | ||
97 | if (with_remote) | ||
98 | btn = pluginlib_getaction(timeout, m2, 2); | ||
83 | else | 99 | else |
84 | return 0; | 100 | #endif |
101 | btn = pluginlib_getaction(timeout, m1, 1); | ||
85 | 102 | ||
103 | lua_pushinteger(L, btn); | ||
86 | return 1; | 104 | return 1; |
87 | } | 105 | } |
88 | 106 | ||
@@ -98,23 +116,42 @@ RB_WRAP(action_get_touchscreen_press) | |||
98 | return 3; | 116 | return 3; |
99 | } | 117 | } |
100 | 118 | ||
101 | RB_WRAP(touchscreen_set_mode) | 119 | RB_WRAP(touchscreen_mode) |
102 | { | ||
103 | enum touchscreen_mode mode = luaL_checkint(L, 1); | ||
104 | rb->touchscreen_set_mode(mode); | ||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | RB_WRAP(touchscreen_get_mode) | ||
109 | { | 120 | { |
110 | lua_pushinteger(L, rb->touchscreen_get_mode()); | 121 | int origmode = rb->touchscreen_get_mode(); |
122 | if(!lua_isnoneornil(L, 1)) | ||
123 | { | ||
124 | enum touchscreen_mode mode = luaL_checkint(L, 1); | ||
125 | rb->touchscreen_set_mode(mode); | ||
126 | } | ||
127 | lua_pushinteger(L, origmode); | ||
111 | return 1; | 128 | return 1; |
112 | } | 129 | } |
130 | |||
113 | #endif | 131 | #endif |
114 | 132 | ||
115 | RB_WRAP(current_path) | 133 | RB_WRAP(kbd_input) |
116 | { | 134 | { |
117 | return get_current_path(L, 1); | 135 | luaL_Buffer b; |
136 | luaL_buffinit(L, &b); | ||
137 | |||
138 | const char *input = lua_tostring(L, 1); | ||
139 | char *buffer = luaL_prepbuffer(&b); | ||
140 | |||
141 | if(input != NULL) | ||
142 | rb->strlcpy(buffer, input, LUAL_BUFFERSIZE); | ||
143 | else | ||
144 | buffer[0] = '\0'; | ||
145 | |||
146 | if(!rb->kbd_input(buffer, LUAL_BUFFERSIZE)) | ||
147 | { | ||
148 | luaL_addstring(&b, buffer); | ||
149 | luaL_pushresult(&b); | ||
150 | } | ||
151 | else | ||
152 | return 0; | ||
153 | |||
154 | return 1; | ||
118 | } | 155 | } |
119 | 156 | ||
120 | static const char ** get_table_items(lua_State *L, int pos, int *count) | 157 | static const char ** get_table_items(lua_State *L, int pos, int *count) |
@@ -189,6 +226,9 @@ RB_WRAP(do_menu) | |||
189 | return 1; | 226 | return 1; |
190 | } | 227 | } |
191 | 228 | ||
229 | |||
230 | /* DEVICE AUDIO / PLAYLIST CONTROL */ | ||
231 | |||
192 | RB_WRAP(playlist) | 232 | RB_WRAP(playlist) |
193 | { | 233 | { |
194 | /* just passes NULL to work with the current playlist */ | 234 | /* just passes NULL to work with the current playlist */ |
@@ -391,8 +431,33 @@ RB_WRAP(pcm) | |||
391 | rb->yield(); | 431 | rb->yield(); |
392 | return 1; | 432 | return 1; |
393 | } | 433 | } |
434 | |||
435 | RB_WRAP(mixer_frequency) | ||
436 | { | ||
437 | unsigned int result = rb->mixer_get_frequency(); | ||
438 | |||
439 | if(!lua_isnoneornil(L, 1)) | ||
440 | { | ||
441 | unsigned int samplerate = (unsigned int) luaL_checkint(L, 1); | ||
442 | rb->mixer_set_frequency(samplerate); | ||
443 | } | ||
444 | lua_pushinteger(L, result); | ||
445 | return 1; | ||
446 | } | ||
394 | #endif /*CONFIG_CODEC == SWCODEC*/ | 447 | #endif /*CONFIG_CODEC == SWCODEC*/ |
395 | 448 | ||
449 | /* DEVICE LIGHTING CONTROL */ | ||
450 | RB_WRAP(backlight_onoff) | ||
451 | { | ||
452 | bool on = luaL_checkboolean(L, 1); | ||
453 | if(on) | ||
454 | rb->backlight_on(); | ||
455 | else | ||
456 | rb->backlight_off(); | ||
457 | |||
458 | return 0; | ||
459 | } | ||
460 | |||
396 | SIMPLE_VOID_WRAPPER(backlight_force_on); | 461 | SIMPLE_VOID_WRAPPER(backlight_force_on); |
397 | SIMPLE_VOID_WRAPPER(backlight_use_settings); | 462 | SIMPLE_VOID_WRAPPER(backlight_use_settings); |
398 | 463 | ||
@@ -409,32 +474,35 @@ SIMPLE_VOID_WRAPPER(buttonlight_use_settings); | |||
409 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | 474 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS |
410 | RB_WRAP(backlight_brightness_set) | 475 | RB_WRAP(backlight_brightness_set) |
411 | { | 476 | { |
412 | int brightness = luaL_checkint(L, 1); | 477 | if(lua_isnoneornil(L, 1)) |
413 | backlight_brightness_set(brightness); | 478 | backlight_brightness_use_setting(); |
479 | else | ||
480 | { | ||
481 | int brightness = luaL_checkint(L, 1); | ||
482 | backlight_brightness_set(brightness); | ||
483 | } | ||
414 | 484 | ||
415 | return 0; | 485 | return 0; |
416 | } | 486 | } |
417 | SIMPLE_VOID_WRAPPER(backlight_brightness_use_setting); | ||
418 | #endif | 487 | #endif |
419 | 488 | ||
420 | RB_WRAP(get_plugin_action) | 489 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
490 | RB_WRAP(buttonlight_brightness_set) | ||
421 | { | 491 | { |
422 | static const struct button_mapping *m1[] = { pla_main_ctx }; | 492 | if(lua_isnoneornil(L, 1)) |
423 | int timeout = luaL_checkint(L, 1); | 493 | buttonlight_brightness_use_setting(); |
424 | int btn; | ||
425 | |||
426 | #ifdef HAVE_REMOTE_LCD | ||
427 | static const struct button_mapping *m2[] = { pla_main_ctx, pla_remote_ctx }; | ||
428 | bool with_remote = luaL_optint(L, 2, 0); | ||
429 | if (with_remote) | ||
430 | btn = pluginlib_getaction(timeout, m2, 2); | ||
431 | else | 494 | else |
432 | #endif | 495 | { |
433 | btn = pluginlib_getaction(timeout, m1, 1); | 496 | int brightness = luaL_checkint(L, 1); |
497 | buttonlight_brightness_set(brightness); | ||
498 | } | ||
434 | 499 | ||
435 | lua_pushinteger(L, btn); | 500 | return 0; |
436 | return 1; | ||
437 | } | 501 | } |
502 | #endif | ||
503 | |||
504 | |||
505 | /* DEVICE STRING / FILENAME MANIPULATION */ | ||
438 | 506 | ||
439 | RB_WRAP(strip_extension) | 507 | RB_WRAP(strip_extension) |
440 | { | 508 | { |
@@ -482,25 +550,53 @@ RB_WRAP(utf8encode) | |||
482 | return 1; | 550 | return 1; |
483 | } | 551 | } |
484 | 552 | ||
553 | RB_WRAP(strncasecmp) | ||
554 | { | ||
555 | int result; | ||
556 | const char * s1 = luaL_checkstring(L, 1); | ||
557 | const char * s2 = luaL_checkstring(L, 2); | ||
558 | if(lua_isnoneornil(L, 3)) | ||
559 | result = rb->strcasecmp(s1, s2); | ||
560 | else | ||
561 | result = rb->strncasecmp(s1, s2, (size_t) luaL_checkint(L, 3)); | ||
562 | |||
563 | lua_pushinteger(L, result); | ||
564 | return 1; | ||
565 | } | ||
566 | |||
485 | #define RB_FUNC(func) {#func, rock_##func} | 567 | #define RB_FUNC(func) {#func, rock_##func} |
568 | #define RB_ALIAS(name, func) {name, rock_##func} | ||
486 | static const luaL_Reg rocklib[] = | 569 | static const luaL_Reg rocklib[] = |
487 | { | 570 | { |
488 | /* Kernel */ | 571 | /* Kernel */ |
489 | RB_FUNC(current_tick), | 572 | RB_FUNC(current_tick), |
573 | #ifdef HAVE_SCHEDULER_BOOSTCTRL | ||
574 | RB_FUNC(schedule_cpu_boost), | ||
575 | #endif | ||
576 | |||
577 | RB_FUNC(current_path), | ||
490 | 578 | ||
491 | /* Buttons */ | 579 | /* DEVICE INPUT CONTROL */ |
580 | RB_FUNC(get_plugin_action), | ||
492 | #ifdef HAVE_TOUCHSCREEN | 581 | #ifdef HAVE_TOUCHSCREEN |
493 | RB_FUNC(action_get_touchscreen_press), | 582 | RB_FUNC(action_get_touchscreen_press), |
494 | RB_FUNC(touchscreen_set_mode), | 583 | RB_FUNC(touchscreen_mode), |
495 | RB_FUNC(touchscreen_get_mode), | ||
496 | #endif | 584 | #endif |
497 | |||
498 | RB_FUNC(kbd_input), | 585 | RB_FUNC(kbd_input), |
499 | |||
500 | RB_FUNC(current_path), | ||
501 | RB_FUNC(gui_syncyesno_run), | 586 | RB_FUNC(gui_syncyesno_run), |
502 | RB_FUNC(do_menu), | 587 | RB_FUNC(do_menu), |
503 | 588 | ||
589 | /* DEVICE AUDIO / PLAYLIST CONTROL */ | ||
590 | RB_FUNC(audio), | ||
591 | RB_FUNC(playlist), | ||
592 | #if CONFIG_CODEC == SWCODEC | ||
593 | RB_FUNC(pcm), | ||
594 | RB_FUNC(mixer_frequency), | ||
595 | #endif | ||
596 | |||
597 | /* DEVICE LIGHTING CONTROL */ | ||
598 | RB_FUNC(backlight_onoff), | ||
599 | |||
504 | /* Backlight helper */ | 600 | /* Backlight helper */ |
505 | RB_FUNC(backlight_force_on), | 601 | RB_FUNC(backlight_force_on), |
506 | RB_FUNC(backlight_use_settings), | 602 | RB_FUNC(backlight_use_settings), |
@@ -517,25 +613,22 @@ static const luaL_Reg rocklib[] = | |||
517 | 613 | ||
518 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS | 614 | #ifdef HAVE_BACKLIGHT_BRIGHTNESS |
519 | RB_FUNC(backlight_brightness_set), | 615 | RB_FUNC(backlight_brightness_set), |
520 | RB_FUNC(backlight_brightness_use_setting), | ||
521 | #endif | 616 | #endif |
522 | 617 | ||
523 | RB_FUNC(get_plugin_action), | 618 | #ifdef HAVE_BUTTONLIGHT_BRIGHTNESS |
619 | RB_FUNC(buttonlight_brightness_set), | ||
620 | #endif | ||
524 | 621 | ||
622 | /* DEVICE STRING / FILENAME MANIPULATION */ | ||
525 | RB_FUNC(strip_extension), | 623 | RB_FUNC(strip_extension), |
526 | RB_FUNC(create_numbered_filename), | 624 | RB_FUNC(create_numbered_filename), |
527 | |||
528 | RB_FUNC(audio), | ||
529 | RB_FUNC(playlist), | ||
530 | #if CONFIG_CODEC == SWCODEC | ||
531 | RB_FUNC(pcm), | ||
532 | #endif | ||
533 | |||
534 | RB_FUNC(utf8encode), | 625 | RB_FUNC(utf8encode), |
626 | RB_FUNC(strncasecmp), | ||
535 | 627 | ||
536 | {NULL, NULL} | 628 | {NULL, NULL} |
537 | }; | 629 | }; |
538 | #undef RB_FUNC | 630 | #undef RB_FUNC |
631 | #undef RB_ALIAS | ||
539 | 632 | ||
540 | extern const luaL_Reg rocklib_aux[]; | 633 | extern const luaL_Reg rocklib_aux[]; |
541 | 634 | ||
@@ -546,7 +639,7 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
546 | { | 639 | { |
547 | luaL_register(L, LUA_ROCKLIBNAME, rocklib); | 640 | luaL_register(L, LUA_ROCKLIBNAME, rocklib); |
548 | luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux); | 641 | luaL_register(L, LUA_ROCKLIBNAME, rocklib_aux); |
549 | 642 | ||
550 | static const struct lua_int_reg rlib_const_int[] = | 643 | static const struct lua_int_reg rlib_const_int[] = |
551 | { | 644 | { |
552 | /* useful integer constants */ | 645 | /* useful integer constants */ |
@@ -555,10 +648,12 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
555 | RB_CONSTANT(LCD_DEPTH), | 648 | RB_CONSTANT(LCD_DEPTH), |
556 | RB_CONSTANT(LCD_HEIGHT), | 649 | RB_CONSTANT(LCD_HEIGHT), |
557 | RB_CONSTANT(LCD_WIDTH), | 650 | RB_CONSTANT(LCD_WIDTH), |
651 | RB_CONSTANT(SCREEN_MAIN), | ||
558 | #ifdef HAVE_REMOTE_LCD | 652 | #ifdef HAVE_REMOTE_LCD |
559 | RB_CONSTANT(LCD_REMOTE_DEPTH), | 653 | RB_CONSTANT(LCD_REMOTE_DEPTH), |
560 | RB_CONSTANT(LCD_REMOTE_HEIGHT), | 654 | RB_CONSTANT(LCD_REMOTE_HEIGHT), |
561 | RB_CONSTANT(LCD_REMOTE_WIDTH), | 655 | RB_CONSTANT(LCD_REMOTE_WIDTH), |
656 | RB_CONSTANT(SCREEN_REMOTE), | ||
562 | #endif | 657 | #endif |
563 | 658 | ||
564 | RB_CONSTANT(FONT_SYSFIXED), | 659 | RB_CONSTANT(FONT_SYSFIXED), |
@@ -572,12 +667,6 @@ LUALIB_API int luaopen_rock(lua_State *L) | |||
572 | RB_CONSTANT(PLAYLIST_PREPEND), | 667 | RB_CONSTANT(PLAYLIST_PREPEND), |
573 | RB_CONSTANT(PLAYLIST_REPLACE), | 668 | RB_CONSTANT(PLAYLIST_REPLACE), |
574 | 669 | ||
575 | |||
576 | RB_CONSTANT(SCREEN_MAIN), | ||
577 | #ifdef HAVE_REMOTE_LCD | ||
578 | RB_CONSTANT(SCREEN_REMOTE), | ||
579 | #endif | ||
580 | |||
581 | #ifdef HAVE_TOUCHSCREEN | 670 | #ifdef HAVE_TOUCHSCREEN |
582 | RB_CONSTANT(TOUCHSCREEN_POINT), | 671 | RB_CONSTANT(TOUCHSCREEN_POINT), |
583 | RB_CONSTANT(TOUCHSCREEN_BUTTON), | 672 | RB_CONSTANT(TOUCHSCREEN_BUTTON), |