lua misc tweaks and cleanup
checks button_status in rockev strpbrk_n custom implementation allows setting max search len in source string add some branch prediction where appropriate fix formatting in splash_scroller script Change-Id: Id5d8e9d83f4b3e361ccb67b403af8f9a8a31b8f0
This commit is contained in:
parent
f3ae48f552
commit
1aa739e3c3
6 changed files with 25 additions and 24 deletions
|
@ -27,6 +27,7 @@
|
|||
#include "lib/pluginlib_actions.h"
|
||||
|
||||
extern long strtol(const char *nptr, char **endptr, int base);
|
||||
extern const char *strpbrk_n(const char *s, int smax, const char *accept);
|
||||
|
||||
#if (CONFIG_PLATFORM & PLATFORM_NATIVE)
|
||||
int errno = 0;
|
||||
|
@ -58,7 +59,7 @@ int splash_scroller(int timeout, const char* str)
|
|||
const int max_lines = LCD_HEIGHT / ch_h - 1;
|
||||
const int wrap_thresh = (LCD_WIDTH / 3);
|
||||
const char *ch;
|
||||
char *brk;
|
||||
const char *brk;
|
||||
|
||||
const int max_ch = (LCD_WIDTH / ch_w - 1) * 2;
|
||||
char line[max_ch + 2]; /* display buffer */
|
||||
|
@ -98,9 +99,10 @@ int splash_scroller(int timeout, const char* str)
|
|||
rb->lcd_getstringsize(line, &w, NULL);
|
||||
|
||||
/* try to not split in middle of words */
|
||||
if (w + wrap_thresh >= max_w && strpbrk (&line[linepos], break_chars))
|
||||
if (w + wrap_thresh >= max_w &&
|
||||
strpbrk_n(ch, 1, break_chars))
|
||||
{
|
||||
brk = strpbrk(ch+1, break_chars);
|
||||
brk = strpbrk_n(ch+1, max_ch, break_chars);
|
||||
chars_next_break = (brk - ch);
|
||||
if (chars_next_break < 2 || w + (ch_w * chars_next_break) > max_w)
|
||||
{
|
||||
|
|
|
@ -272,7 +272,8 @@ static void rev_timer_isr(void)
|
|||
{
|
||||
evt = ev_data.cb[i];
|
||||
|
||||
if ((i == ACTEVENT || i == BTNEVENT) && rb->button_queue_count())
|
||||
if ((i == ACTEVENT || i == BTNEVENT) &&
|
||||
(rb->button_queue_count() || rb->button_status() || evt->id))
|
||||
ev_flag |= event_flag(i); /* any buttons ready? */
|
||||
else if(evt->ticks > 0 && TIME_AFTER(curr_tick, evt->next_tick))
|
||||
ev_flag |= event_flag(i);
|
||||
|
@ -315,23 +316,15 @@ static void event_thread(void)
|
|||
{
|
||||
/* only send ACTION_NONE once */
|
||||
if (evt->id == ACTION_NONE || rb->button_status() != 0)
|
||||
{
|
||||
evt->ticks = 0;
|
||||
continue; /* check next event */
|
||||
}
|
||||
}
|
||||
evt->ticks = EV_TICKS; /* poll release event */
|
||||
evt->id = action;
|
||||
break;
|
||||
case BTNEVENT:
|
||||
evt->id = rb->button_get(false);
|
||||
/* only send BUTTON_NONE once */
|
||||
if (evt->id == BUTTON_NONE)
|
||||
{
|
||||
evt->ticks = 0;
|
||||
continue; /* check next event */
|
||||
}
|
||||
evt->ticks = EV_TICKS; /* poll release event */
|
||||
break;
|
||||
case CUSTOMEVENT:
|
||||
case PLAYBKEVENT:
|
||||
|
@ -592,7 +585,7 @@ static int rockev_register(lua_State *L)
|
|||
case ACTEVENT:
|
||||
/* fall through */
|
||||
case BTNEVENT:
|
||||
event_ticks = 0; /* button events not triggered by timeout but release is*/
|
||||
event_ticks = 0; /* button events not triggered by timeout */
|
||||
break;
|
||||
case CUSTOMEVENT:
|
||||
event_ticks = luaL_optinteger(L, 3, EV_TICKS);
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
#include "rocklibc.h"
|
||||
|
||||
#undef strpbrk
|
||||
char *strpbrk(const char *s, const char *accept) {
|
||||
register int i,l=strlen(accept);
|
||||
for (; *s; s++)
|
||||
for (i=0; i<l; i++)
|
||||
if (*s == accept[i])
|
||||
return (char*)s;
|
||||
return 0;
|
||||
/* custom strbbrk allowing you to define search len of s*/
|
||||
const char *strpbrk_n(const char *s, int smax, const char *accept) {
|
||||
register int i;
|
||||
register const char *a = accept;
|
||||
for (i=0; __likely(s[i] && i < smax); i++, a=accept)
|
||||
while(__likely(a++[0]))
|
||||
if ((s[i] == a[0]))
|
||||
return &s[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
inline char *strpbrk(const char *s, const char *accept) {
|
||||
return (char*)strpbrk_n(s, INT_MAX, accept);
|
||||
}
|
||||
|
|
|
@ -9,12 +9,12 @@ long int strtol(const char *nptr, char **endptr, int base)
|
|||
unsigned long int v;
|
||||
const char*orig=nptr;
|
||||
|
||||
while(isspace(*nptr)) nptr++;
|
||||
while(__unlikely(isspace(*nptr))) nptr++;
|
||||
|
||||
if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; }
|
||||
v=strtoul(nptr,endptr,base);
|
||||
if (endptr && *endptr==nptr) *endptr=(char *)orig;
|
||||
if (v>=ABS_LONG_MIN) {
|
||||
if (__unlikely(v>=ABS_LONG_MIN)) {
|
||||
if (v==ABS_LONG_MIN && neg) {
|
||||
errno=0;
|
||||
return v;
|
||||
|
|
|
@ -7,7 +7,7 @@ unsigned long int strtoul(const char *ptr, char **endptr, int base)
|
|||
const char* orig;
|
||||
const char* nptr=ptr;
|
||||
|
||||
while(isspace(*nptr)) ++nptr;
|
||||
while(__unlikely(isspace(*nptr))) ++nptr;
|
||||
|
||||
if (*nptr == '-') { neg=1; nptr++; }
|
||||
else if (*nptr == '+') ++nptr;
|
||||
|
|
|
@ -1 +1 @@
|
|||
rb.splash_scroller(rb.HZ * 5, "This is a rb.splash_scroller test, it is meant to reflow text into a format easily digestable on small screen devices.\n\n it is not particularly adept at this as we strive for the bare minimum in order to leave room for YOUR code. :) \n\nHowever, it does recognize \t\\t \r\\r\n\\n\n\\b (bell)\b")
|
||||
rb.splash_scroller(rb.HZ * 5, "This is a rb.splash_scroller test, it is meant to reflow text into a format easily digestable on small screen devices.\n\n it is not particularly adept at this as we strive for the bare minimum in order to leave room for YOUR code. :) \n\nHowever, it does recognize \n\t\\t \r\\r\n\\n\n\\b (bell)\b")
|
||||
|
|
Loading…
Reference in a new issue