diff --git a/.astylerc b/.astylerc deleted file mode 100644 index 0ef438ca..00000000 --- a/.astylerc +++ /dev/null @@ -1,11 +0,0 @@ -style=allman -indent=spaces=4 -pad-comma -pad-oper -add-braces -keep-one-line-blocks -keep-one-line-statements -add-one-line-braces -align-pointer=name -align-reference=name -verbose diff --git a/platform/targets/linux/emulator/emulator.c b/platform/targets/linux/emulator/emulator.c index 55a76f14..93b52bf9 100644 --- a/platform/targets/linux/emulator/emulator.c +++ b/platform/targets/linux/emulator/emulator.c @@ -72,20 +72,20 @@ void _dump_skq() } void shellkeyq_put(keyboard_t keys) { - //note - we must allow keys == 0 to be inserted because otherwise a queue full of - // [1,1,1,1,1] is simulating HOLDING 1, and we sometimes (well, often) want - // [1,0,1,0,1,0] to simulate separate keypresses - // this, of course, relies on the kbd_thread getting just one element off the queue - // for every kbd_getKeys(). + // note - we must allow keys == 0 to be inserted because otherwise a queue + // full of [1,1,1,1,1] is simulating HOLDING 1, and we sometimes + // (well, often) want [1,0,1,0,1,0] to simulate separate keypresses + // this, of course, relies on the kbd_thread getting just one element off + // the queue for every kbd_getKeys(). if(_skq_in > _skq_out + _skq_cap) { printf("too many keys!\n"); return; } + _shellkeyq[ _skq_tail ] = keys; _skq_in++; _skq_tail = (_skq_tail + 1) % _skq_cap; - /*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/ } keyboard_t shellkeyq_get() { @@ -96,8 +96,6 @@ keyboard_t shellkeyq_get() _shellkeyq[ _skq_head ] = 0; _skq_out++; _skq_head = (_skq_head + 1) % _skq_cap; - /*printf("head: %d tail: %d in %d out %d\n", _skq_head, _skq_tail, _skq_in, _skq_out);*/ - /*_dump_skq();*/ return out; } else @@ -132,41 +130,50 @@ int shell_ready(void *_self, int _argc, char **_argv) keyboard_t keyname2keyboard(char *name) { - /* The line noise at the end of this comment is a vim macro for taking the keyboard.h - interface and putting it into the format further below - You can load it into vim register k with "kyy - and run the macro with @k (and then you can repeat a macro register application with @@ ) - (substitute k with any register you like) - Once you've got all the names quoted, you can J them all together into a nice block. - - _i"ElC", - - */ + /* The line noise at the end of this comment is a vim macro for taking the + * keyboard.h interface and putting it into the format further below. + * You can load it into vim register k with "kyy and run the macro with @k + * (and then you can repeat a macro register application with @@ ) + * (substitute k with any register you like) + * Once you've got all the names quoted, you can J them all together into + * a nice block. + * + * _i"ElC", + * + */ char *names[] = { "KEY_0", "KEY_1", "KEY_2", "KEY_3", "KEY_4", "KEY_5", "KEY_6", "KEY_7", - "KEY_8", "KEY_9", "KEY_STAR", "KEY_HASH", "KEY_ENTER", "KEY_ESC", "KEY_UP", - "KEY_DOWN", "KEY_LEFT", "KEY_RIGHT", "KEY_MONI", "KEY_F1", "KEY_F2", "KEY_F3", - "KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KNOB_LEFT", "KNOB_RIGHT", + "KEY_8", "KEY_9", "KEY_STAR", "KEY_HASH", "KEY_ENTER", "KEY_ESC", + "KEY_UP","KEY_DOWN", "KEY_LEFT", "KEY_RIGHT", "KEY_MONI", "KEY_F1", + "KEY_F2", "KEY_F3", "KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", + "KNOB_LEFT", "KNOB_RIGHT", }; + int numnames = sizeof(names) / sizeof(char *); + for(int i = 0; i < numnames; i++) { - if(strcasecmp(name, names[i] + 4) == 0 || strcasecmp(name, names[i]) == 0) //notice case insensitive - { - /*printf("MATCH with %s\n", names[i]);*/ - //+4 to skip the KEY_ on all the names, non +4 to allow for KNOB_LEFT. - //This also means you can write KEY_LEFT as "KEY_LEFT", or "LEFT" and KNOB_LEFT as "KNOB_LEFT" or "_LEFT" + /* + * +4 to skip the KEY_ on all the names, non +4 to allow for KNOB_LEFT. + * This also means you can write KEY_LEFT as "KEY_LEFT", or "LEFT" and + * KNOB_LEFT as "KNOB_LEFT" or "_LEFT" + * + * so if name == "2", this whole function will return equivalent to KEY_2 cpp define + * and if name=="LEFT", then you get equivalent to KEY_LEFT cpp define + * and if name=="_LEFT", then you get equivalent to KNOB_LEFT cpp define + * and if name=="KNOB_LEFT", then you get equivalent to KNOB_LEFT cpp define + * and if name=="KEY_2", then you get equivalent to KEY_2 cpp define. + * + * Of course order matters a great deal in names array, has to match the + * bit field generated in interface/keyboard.h so double check that with + * every update + */ - //so if name == "2", this whole function will return equivalent to KEY_2 cpp define - //and if name=="LEFT", then you get equivalent to KEY_LEFT cpp define - //and if name=="_LEFT", then you get equivalent to KNOB_LEFT cpp define - //and if name=="KNOB_LEFT", then you get equivalent to KNOB_LEFT cpp define - //and if name=="KEY_2", then you get equivalent to KEY_2 cpp define of course + if((strcasecmp(name, names[i] + 4) == 0) || + (strcasecmp(name, names[i]) == 0)) //notice case insensitive + { return (1 << i); - //order matters a great deal in names array, has to match - //the bit field generated in interface/keyboard.h - //so double check that with every update } } return 0; @@ -175,10 +182,10 @@ keyboard_t keyname2keyboard(char *name) int pressKey(void *_self, int _argc, char **_argv) { (void) _self; - //press a couple keys in sequence - /*_climenu_option * self = (_climenu_option*) _self;*/ + printf("Press Keys: [\n"); keyboard_t last = 0; + for(int i = 0; i < _argc; i++) { if(_argv[i] != NULL) @@ -187,13 +194,14 @@ int pressKey(void *_self, int _argc, char **_argv) keyboard_t press = keyname2keyboard(_argv[i]); if(press == last) { - //otherwise if you send key ENTER DOWN DOWN DOWN DOWN DOWN - //it will just hold DOWN for (5/(kbd_task_hz)) seconds - //so we need to give it a 0 value to get a 'release' - //so the next input is recognized as separate - //we only need to do this if we have two identical keys back to back, - //because keyboard_t will have a zero for this key's - //flag on other keys, which gives us the release we need + /* otherwise if you send key ENTER DOWN DOWN DOWN DOWN DOWN + * it will just hold DOWN for (5/(kbd_task_hz)) seconds + * so we need to give it a 0 value to get a 'release' + * so the next input is recognized as separate + * we only need to do this if we have two identical keys back + * to back, because keyboard_t will have a zero for this key's + * flag on other keys, which gives us the release we need + */ shellkeyq_put(0); } shellkeyq_put(press); @@ -204,13 +212,15 @@ int pressKey(void *_self, int _argc, char **_argv) shell_ready(NULL, 0, NULL); return SH_CONTINUE; // continue } + +// pressMultiKeys allows for key combos by sending all the keys specified in +// one keyboard_t int pressMultiKeys(void *_self, int _argc, char **_argv) { -//pressMultiKeys allows for key combos by sending all the keys specified in one keyboard_t - /*_climenu_option * self = (_climenu_option*) _self;*/ (void) _self; printf("Press Keys: [\n"); keyboard_t combo = 0; + for(int i = 0; i < _argc; i++) { if(_argv[i] != NULL) @@ -219,15 +229,12 @@ int pressMultiKeys(void *_self, int _argc, char **_argv) combo |= keyname2keyboard(_argv[i]); } } + shellkeyq_put(combo); printf("\t]\n"); shell_ready(NULL, 0, NULL); return SH_CONTINUE; // continue } -//need another function to press them in sequence by loading up a queue for keypress_from_shell to pull from - - - int template(void *_self, int _argc, char **_argv) { @@ -241,6 +248,7 @@ int template(void *_self, int _argc, char **_argv) printf("\tArgs:\t%s\n", _argv[i]); } } + return SH_CONTINUE; // continue } @@ -248,6 +256,7 @@ int screenshot(void *_self, int _argc, char **_argv) { (void) _self; char *filename = "screenshot.bmp"; + if(_argc && _argv[0] != NULL) { filename = _argv[0]; @@ -261,24 +270,7 @@ int screenshot(void *_self, int _argc, char **_argv) return SDL_PushEvent(&e) == 1 ? SH_CONTINUE : SH_ERR; } -/* - int record_start(void * _self, int _argc, char ** _argv ){ - char * filename = "screen.mkv"; - if( _argc && _argv[0] != NULL ){ - filename = _argv[0]; - } - //id="xwininfo -name 'OpenRTX' | grep id: |cut -d ' ' -f 4"; - //system("ffmpeg -f x11grab -show_region 1 -region_border 10 -window_id 0x2600016 -i :0.0 out.mkv"); - //https://stackoverflow.com/questions/14764873/how-do-i-detect-when-the-contents-of-an-x11-window-have-changed - return SH_ERR; - } - int record_stop( - void * _self, - int _argc, - char ** _argv ){ - return SH_ERR; - } -*/ + int setFloat(void *_self, int _argc, char **_argv) { _climenu_option *self = (_climenu_option *) _self; @@ -292,39 +284,47 @@ int setFloat(void *_self, int _argc, char **_argv) sscanf(_argv[0], "%f", (float *)self->var); printf("%s is %f\n", self->name, *(float *)(self->var)); } + return SH_CONTINUE; // continue } + int toggleVariable(void *_self, int _argc, char **_argv) { (void) _argc; (void) _argv; _climenu_option *self = (_climenu_option *) _self; *(int *)self->var = ! *(int *)self->var; //yeah, maybe this got a little out of hand - return SH_CONTINUE; // continue + return SH_CONTINUE; // continue } + int shell_sleep(void *_self, int _argc, char **_argv) { (void) _self; + if(! _argc || _argv[0] == NULL) { printf("Provide a number in milliseconds to sleep as an argument\n"); return SH_ERR; } + useconds_t sleepus = atoi(_argv[0]) * 1000; usleep(sleepus); return SH_CONTINUE; } + int shell_quit( void *_self, int _argc, char **_argv) { (void) _self; (void) _argc; (void) _argv; printf("QUIT: 73!\n"); + //could remove history entries here, if we wanted return SH_EXIT_OK; //normal quit } + int printState( void *_self, int _argc, char **_argv) { (void) _self; @@ -339,6 +339,7 @@ int printState( void *_self, int _argc, char **_argv) printf("PTT : %s\n\n", Radio_State.PttStatus ? "true" : "false"); return SH_CONTINUE; } + int shell_nop( void *_self, int _argc, char **_argv) { (void) _self; @@ -348,64 +349,50 @@ int shell_nop( void *_self, int _argc, char **_argv) return SH_CONTINUE; } -int shell_help(void *_self, int _argc, char **_argv); +// Forward declaration needed to include function pointer in the table below +int shell_help( void *_self, int _argc, char **_argv); _climenu_option _options[] = { /* name/shortcut description var reference, if available method to call */ - {"rssi", "Set rssi", (void *) &Radio_State.RSSI, setFloat }, - {"vbat", "Set vbat", (void *) &Radio_State.Vbat, setFloat }, - {"mic", "Set miclevel", (void *) &Radio_State.micLevel, setFloat }, - {"volume", "Set volume", (void *) &Radio_State.volumeLevel, setFloat }, - {"channel", "Set channel", (void *) &Radio_State.chSelector, setFloat }, - {"ptt", "Toggle PTT", (void *) &Radio_State.PttStatus, toggleVariable }, - { - "key", "Press keys in sequence (e.g. 'key ENTER DOWN ENTER' will descend through two menus)", - NULL, pressKey + {"rssi", "Set rssi", (void *) &Radio_State.RSSI, setFloat }, + {"vbat", "Set vbat", (void *) &Radio_State.Vbat, setFloat }, + {"mic", "Set miclevel", (void *) &Radio_State.micLevel, setFloat }, + {"volume", "Set volume", (void *) &Radio_State.volumeLevel, setFloat }, + {"channel", "Set channel", (void *) &Radio_State.chSelector, setFloat }, + {"ptt", "Toggle PTT", (void *) &Radio_State.PttStatus, toggleVariable }, + {"key", "Press keys in sequence (e.g. 'key ENTER DOWN ENTER' will descend through two menus)", + NULL, pressKey }, - { - "keycombo", "Press a bunch of keys simultaneously ", - NULL, pressMultiKeys - }, - { - "show", "Show current radio state (ptt, rssi, etc)", - NULL, printState - }, - - { - "screenshot", "[screenshot.bmp] Save screenshot to first arg or screenshot.bmp if none given", - NULL, screenshot - }, - /*{"record_start", "[screen.mkv] Automatically save a video of the remaining session (or until record_stop is called)",*/ - /*NULL, record_start },*/ - /*{"record_stop", "Stop the running recording, or no-op if none started",*/ - /*NULL, record_stop },*/ - {"sleep", "Wait some number of ms", NULL, shell_sleep }, - {"help", "Print this help", NULL, shell_help }, - { - "nop", "Do nothing (useful for comments)", - NULL, shell_nop + {"keycombo", "Press a bunch of keys simultaneously", NULL, pressMultiKeys }, + {"show", "Show current radio state (ptt, rssi, etc)", NULL, printState}, + {"screenshot", "[screenshot.bmp] Save screenshot to first arg or screenshot.bmp if none given", + NULL, screenshot }, + {"sleep", "Wait some number of ms", NULL, shell_sleep }, + {"help", "Print this help", NULL, shell_help }, + {"nop", "Do nothing (useful for comments)", NULL, shell_nop}, + {"quit", "Quit, close the emulator", NULL, shell_quit }, /*{"ready", */ /*"Wait until ready. Currently supports keyboard, so will wait until all keyboard events are processed,"*/ /*"but is already implied by key and keycombo so there's not much direct use for it right now",*/ /*NULL, shell_ready },*/ - {"quit", "Quit, close the emulator", NULL, shell_quit }, }; int num_options = (sizeof(_options) / sizeof(_climenu_option)); - int shell_help( void *_self, int _argc, char **_argv) { (void) _self; (void) _argc; (void) _argv; printf("OpenRTX emulator shell\n\n"); + for(int i = 0; i < num_options; i++) { _climenu_option *o = &_options[i]; printf("%10s -> %s\n", o->name, o->description); } + return SH_CONTINUE; } @@ -415,15 +402,19 @@ _climenu_option *findMenuOption(char *tok) for(int i = 0; i < num_options; i++) { _climenu_option *o = &_options[i]; + + /* + * strncmp like this allows for typing shortcuts like just "r" instead + * of the full "rssi". Priority for conflicts (like if there's "s" + * which could mean either "show" or "screenshot" ) is set by ordering + * in the _options array + */ if(strncmp(tok, o->name, strlen(tok)) == 0) { - //strncmp like this allows for typing shortcuts like just "r" instead of the full "rssi" - //priority for conflicts (like if there's "s" which could mean - // either "show" or "screenshot" ) - //is set by ordering in the _options array return o; } } + return NULL; } @@ -437,17 +428,21 @@ void striptoken(char *token) } } } + int process_line(char *line) { char *token = strtok(line, " "); + if(token == NULL) { return SH_ERR; } + striptoken(token); _climenu_option *o = findMenuOption(token); char *args[12] = {NULL}; int i = 0; + for(i = 0; i < 12; i++) { //immediately strtok again since first is a command rest are args @@ -459,10 +454,12 @@ int process_line(char *line) striptoken(token); args[i] = token; } + if(token != NULL) { printf("\nGot too many arguments, args truncated \n"); } + if(o != NULL) { if(o->fn != NULL) @@ -480,18 +477,18 @@ int process_line(char *line) return SH_WHAT; //not understood } } + void *startCLIMenu() { printf("\n\n"); char *histfile = ".emulatorsh_history"; shell_help(NULL, 0, NULL); - /*printf("\n> ");*/ int ret = SH_CONTINUE; using_history(); read_history(histfile); + do { - /*char * r = fgets(shellbuf, 255, stdin);*/ char *r = readline(">"); if(r == NULL) { @@ -506,31 +503,37 @@ void *startCLIMenu() { ret = SH_CONTINUE; } + switch(ret) { - default: - fflush(stdout); - break; - case SH_WHAT: - printf("?\n(type h or help for help)\n"); - ret = SH_CONTINUE; //i'd rather just fall through, but the compiler warns. blech. - /*printf("\n>");*/ - break; - case SH_CONTINUE: - /*printf("\n>");*/ - break; - case SH_EXIT_OK: - //normal quit - break; - case SH_ERR: - //error - printf("Error running that command\n"); - ret = SH_CONTINUE; - break; + default: + fflush(stdout); + break; + + case SH_WHAT: + printf("?\n(type h or help for help)\n"); + ret = SH_CONTINUE; + /*printf("\n>");*/ + break; + + case SH_CONTINUE: + /*printf("\n>");*/ + break; + + case SH_EXIT_OK: + //normal quit + break; + + case SH_ERR: + //error + printf("Error running that command\n"); + ret = SH_CONTINUE; + break; } free(r); //free the string allocated by readline } while(ret == SH_CONTINUE); + fflush(stdout); write_history(histfile); Radio_State.PowerOff = true; diff --git a/platform/targets/linux/emulator/sdl_engine.c b/platform/targets/linux/emulator/sdl_engine.c index 5c37ef81..69847d1a 100644 --- a/platform/targets/linux/emulator/sdl_engine.c +++ b/platform/targets/linux/emulator/sdl_engine.c @@ -39,91 +39,115 @@ pthread_mutex_t mu; bool ready = false; /* Signal if the main loop is ready */ keyboard_t sdl_keys; /* Store the keyboard status */ -bool sdk_key_code_to_key(SDL_KeyCode sym, keyboard_t *key) +bool sdk_key_code_to_key(SDL_Keycode sym, keyboard_t *key) { switch (sym) { - case SDLK_0: - *key = KEY_0; - return true; - case SDLK_1: - *key = KEY_1; - return true; - case SDLK_2: - *key = KEY_2; - return true; - case SDLK_3: - *key = KEY_3; - return true; - case SDLK_4: - *key = KEY_4; - return true; - case SDLK_5: - *key = KEY_5; - return true; - case SDLK_6: - *key = KEY_6; - return true; - case SDLK_7: - *key = KEY_7; - return true; - case SDLK_8: - *key = KEY_8; - return true; - case SDLK_9: - *key = KEY_9; - return true; - case SDLK_ASTERISK: - *key = KEY_STAR; - return true; - case SDLK_ESCAPE: - *key = KEY_ESC; - return true; - case SDLK_LEFT: - *key = KEY_LEFT; - return true; - case SDLK_RIGHT: - *key = KEY_RIGHT; - return true; - case SDLK_RETURN: - *key = KEY_ENTER; - return true; - case SDLK_HASH: - *key = KEY_HASH; - return true; - case SDLK_n: - *key = KEY_F1; - return true; - case SDLK_m: - *key = KEY_MONI; - return true; - case SDLK_PAGEUP: - *key = KNOB_LEFT; - return true; - case SDLK_PAGEDOWN: - *key = KNOB_RIGHT; - return true; - case SDLK_UP: - *key = KEY_UP; - return true; - case SDLK_DOWN: - *key = KEY_DOWN; - return true; - default: - return false; + case SDLK_0: + *key = KEY_0; + return true; + + case SDLK_1: + *key = KEY_1; + return true; + + case SDLK_2: + *key = KEY_2; + return true; + + case SDLK_3: + *key = KEY_3; + return true; + + case SDLK_4: + *key = KEY_4; + return true; + + case SDLK_5: + *key = KEY_5; + return true; + + case SDLK_6: + *key = KEY_6; + return true; + + case SDLK_7: + *key = KEY_7; + return true; + + case SDLK_8: + *key = KEY_8; + return true; + + case SDLK_9: + *key = KEY_9; + return true; + + case SDLK_ASTERISK: + *key = KEY_STAR; + return true; + + case SDLK_ESCAPE: + *key = KEY_ESC; + return true; + + case SDLK_LEFT: + *key = KEY_LEFT; + return true; + + case SDLK_RIGHT: + *key = KEY_RIGHT; + return true; + + case SDLK_RETURN: + *key = KEY_ENTER; + return true; + + case SDLK_HASH: + *key = KEY_HASH; + return true; + + case SDLK_n: + *key = KEY_F1; + return true; + + case SDLK_m: + *key = KEY_MONI; + return true; + + case SDLK_PAGEUP: + *key = KNOB_LEFT; + return true; + + case SDLK_PAGEDOWN: + *key = KNOB_RIGHT; + return true; + + case SDLK_UP: + *key = KEY_UP; + return true; + + case SDLK_DOWN: + *key = KEY_DOWN; + return true; + + default: + return false; } } int screenshot_display(const char *filename) { - //https://stackoverflow.com/a/48176678 - //user1902824 - //modified to keep renderer and display texture references in the body rather than as a parameter - SDL_Renderer * ren = renderer; - SDL_Texture * tex = displayTexture; + /* + * https://stackoverflow.com/a/48176678 + * user1902824 + * modified to keep renderer and display texture references in the body + * rather than as a parameter + */ + SDL_Renderer *ren = renderer; + SDL_Texture *tex = displayTexture; int err = 0; - SDL_Texture *ren_tex; SDL_Surface *surf; int st; @@ -139,6 +163,7 @@ int screenshot_display(const char *filename) /* Get information about texture we want to save */ st = SDL_QueryTexture(tex, NULL, NULL, &w, &h); + if (st != 0) { SDL_Log("Failed querying texture: %s\n", SDL_GetError()); @@ -147,6 +172,7 @@ int screenshot_display(const char *filename) } ren_tex = SDL_CreateTexture(ren, format, SDL_TEXTUREACCESS_TARGET, w, h); + if (!ren_tex) { SDL_Log("Failed creating render texture: %s\n", SDL_GetError()); @@ -159,52 +185,66 @@ int screenshot_display(const char *filename) * can access */ st = SDL_SetRenderTarget(ren, ren_tex); + if (st != 0) { SDL_Log("Failed setting render target: %s\n", SDL_GetError()); err++; goto cleanup; } + SDL_SetRenderDrawColor(ren, 0x00, 0x00, 0x00, 0x00); SDL_RenderClear(ren); st = SDL_RenderCopy(ren, tex, NULL, NULL); + if (st != 0) { SDL_Log("Failed copying texture data: %s\n", SDL_GetError()); err++; goto cleanup; } + /* Create buffer to hold texture data and load it */ pixels = malloc(w * h * SDL_BYTESPERPIXEL(format)); + if (!pixels) { SDL_Log("Failed allocating memory\n"); err++; goto cleanup; } - st = SDL_RenderReadPixels(ren, NULL, format, pixels, w * SDL_BYTESPERPIXEL(format)); + + st = SDL_RenderReadPixels(ren, NULL, format, pixels, + w * SDL_BYTESPERPIXEL(format)); if (st != 0) { SDL_Log("Failed reading pixel data: %s\n", SDL_GetError()); err++; goto cleanup; } + /* Copy pixel data over to surface */ - surf = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, SDL_BITSPERPIXEL(format), w * SDL_BYTESPERPIXEL(format), format); + surf = SDL_CreateRGBSurfaceWithFormatFrom(pixels, w, h, + SDL_BITSPERPIXEL(format), + w * SDL_BYTESPERPIXEL(format), + format); if (!surf) { SDL_Log("Failed creating new surface: %s\n", SDL_GetError()); err++; goto cleanup; } + /* Save result to an image */ st = SDL_SaveBMP(surf, filename); + if (st != 0) { SDL_Log("Failed saving image: %s\n", SDL_GetError()); err++; goto cleanup; } + SDL_Log("Saved texture as BMP to \"%s\"\n", filename); cleanup: @@ -242,6 +282,7 @@ void sdl_task() pthread_mutex_unlock(&mu); SDL_Event ev = { 0 }; + while (!Radio_State.PowerOff) { keyboard_t key = 0; @@ -249,25 +290,27 @@ void sdl_task() { switch (ev.type) { - case SDL_QUIT: - Radio_State.PowerOff = true; - break; - case SDL_KEYDOWN: - if (sdk_key_code_to_key(ev.key.keysym.sym, &key)) - { - pthread_mutex_lock(&mu); - sdl_keys |= key; - pthread_mutex_unlock(&mu); - } - break; - case SDL_KEYUP: - if (sdk_key_code_to_key(ev.key.keysym.sym, &key)) - { - pthread_mutex_lock(&mu); - sdl_keys ^= key; - pthread_mutex_unlock(&mu); - } - break; + case SDL_QUIT: + Radio_State.PowerOff = true; + break; + + case SDL_KEYDOWN: + if (sdk_key_code_to_key(ev.key.keysym.sym, &key)) + { + pthread_mutex_lock(&mu); + sdl_keys |= key; + pthread_mutex_unlock(&mu); + } + break; + + case SDL_KEYUP: + if (sdk_key_code_to_key(ev.key.keysym.sym, &key)) + { + pthread_mutex_lock(&mu); + sdl_keys ^= key; + pthread_mutex_unlock(&mu); + } + break; } if (ev.type == SDL_Screenshot_Event) { @@ -282,6 +325,7 @@ void sdl_task() { PIXEL_SIZE *pixels; int pitch = 0; + if (SDL_LockTexture(displayTexture, NULL, (void **) &pixels, &pitch) < 0) { @@ -295,7 +339,7 @@ void sdl_task() SDL_RenderCopy(renderer, displayTexture, NULL, NULL); SDL_RenderPresent(renderer); } - } /* while(!Radio_State.PowerOff) */ + } SDL_DestroyWindow(window); SDL_Quit(); diff --git a/platform/targets/linux/platform.c b/platform/targets/linux/platform.c index 22e8dbc9..a9a9a759 100644 --- a/platform/targets/linux/platform.c +++ b/platform/targets/linux/platform.c @@ -26,10 +26,10 @@ hwInfo_t hwInfo; void platform_init() { - //printf("Platform init\n"); // Fill hwinfo struct memset(&hwInfo, 0x00, sizeof(hwInfo)); snprintf(hwInfo.name, 10, "Linux"); + // Frequencies are in MHz hwInfo.vhf_maxFreq = 174; hwInfo.vhf_minFreq = 136; @@ -49,9 +49,9 @@ void platform_terminate() exit(0); } -void platform_setBacklightLevel(__attribute__((unused)) uint8_t level) +void platform_setBacklightLevel(uint8_t level) { - //printf("platform_setBacklightLevel(%u)\n", level); + (void) level; } // Simulate a fully charged lithium battery @@ -63,7 +63,6 @@ uint16_t platform_getVbat() return ((uint16_t) voltage); } - uint8_t platform_getMicLevel() { float level = Radio_State.micLevel; @@ -73,7 +72,6 @@ uint8_t platform_getMicLevel() return ((uint8_t) level); } - uint8_t platform_getVolumeLevel() { float level = Radio_State.volumeLevel; @@ -83,17 +81,16 @@ uint8_t platform_getVolumeLevel() return ((uint8_t) level); } - int8_t platform_getChSelector() { return Radio_State.chSelector; } - bool platform_getPttStatus() { // Read P key status from SDL const uint8_t *state = SDL_GetKeyboardState(NULL); + if (state[SDL_SCANCODE_P]) return true; else @@ -106,42 +103,21 @@ bool platform_pwrButtonStatus() return !Radio_State.PowerOff; } -void platform_ledOn(__attribute__((unused)) led_t led) +void platform_ledOn(led_t led) { - // Commented to reduce verbosity on Linux - //char* str; - //switch(led) - //{ - // case 0: - // str = "GREEN"; - // break; - // case 1: - // str = "RED"; - // break; - // case 2: - // str = "YELLOW"; - // break; - // case 3: - // str = "WHITE"; - // break; - //} - //printf("platform_ledOn(%s)\n", str); + (void) led; } - -void platform_ledOff(__attribute__((unused)) led_t led) +void platform_ledOff(led_t led) { - // Commented to reduce verbosity on Linux - //printf("platform_ledOff()\n"); + (void) led; } - void platform_beepStart(uint16_t freq) { printf("platform_beepStart(%u)\n", freq); } - void platform_beepStop() { printf("platform_beepStop()\n");