1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-15 12:25:12 +03:00

Thread names and cosmetics

This commit is contained in:
Bertrand Songis 2019-06-18 12:13:11 +02:00
parent ad13301389
commit afa69cb0c5
No known key found for this signature in database
GPG key ID: F189F79290FEC50F
5 changed files with 92 additions and 82 deletions

View file

@ -114,9 +114,10 @@ extern "C++" {
#define TASK_FUNCTION(task) void * task(void * pdata) #define TASK_FUNCTION(task) void * task(void * pdata)
template<int SIZE> template<int SIZE>
inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char *, FakeTaskStack<SIZE> &, unsigned, unsigned) inline void RTOS_CREATE_TASK(pthread_t &taskId, void * task(void *), const char * name, FakeTaskStack<SIZE> &, unsigned, unsigned)
{ {
pthread_create(&taskId, nullptr, task, nullptr); pthread_create(&taskId, nullptr, task, nullptr);
pthread_setname_np(taskId, name);
} }
#define TASK_RETURN() return nullptr #define TASK_RETURN() return nullptr

View file

@ -42,14 +42,14 @@
#define W2 LCD_W*LCD_ZOOM #define W2 LCD_W*LCD_ZOOM
#define H2 LCD_H*LCD_ZOOM #define H2 LCD_H*LCD_ZOOM
class Open9xSim: public FXMainWindow class OpenTxSim: public FXMainWindow
{ {
FXDECLARE(Open9xSim) FXDECLARE(OpenTxSim)
public: public:
Open9xSim(){}; OpenTxSim(){};
Open9xSim(FXApp* a); OpenTxSim(FXApp* a);
~Open9xSim(); ~OpenTxSim();
void updateKeysAndSwitches(bool start=false); void updateKeysAndSwitches(bool start=false);
long onKeypress(FXObject*,FXSelector,void*); long onKeypress(FXObject*,FXSelector,void*);
long onTimeout(FXObject*,FXSelector,void*); long onTimeout(FXObject*,FXSelector,void*);
@ -60,28 +60,26 @@ class Open9xSim: public FXMainWindow
void setPixel(int x, int y, FXColor color); void setPixel(int x, int y, FXColor color);
private: private:
FXImage *bmp; FXImage * bmp;
FXImageFrame *bmf; FXImageFrame * bmf;
bool firstTime;
public: public:
FXSlider *sliders[NUM_STICKS]; FXSlider * sliders[NUM_STICKS];
FXKnob *knobs[NUM_POTS+NUM_SLIDERS]; FXKnob * knobs[NUM_POTS+NUM_SLIDERS];
}; };
// Message Map // Message Map
FXDEFMAP(Open9xSim) Open9xSimMap[] = { FXDEFMAP(OpenTxSim) OpenTxSimMap[] = {
//Message_Type _________ ID____Message_Handler_______ // Message_Type _______ID____Message_Handler_______
FXMAPFUNC(SEL_TIMEOUT, 2, Open9xSim::onTimeout), FXMAPFUNC(SEL_TIMEOUT, 2, OpenTxSim::onTimeout),
FXMAPFUNC(SEL_KEYPRESS, 0, Open9xSim::onKeypress), FXMAPFUNC(SEL_KEYPRESS, 0, OpenTxSim::onKeypress),
}; };
FXIMPLEMENT(Open9xSim,FXMainWindow,Open9xSimMap,ARRAYNUMBER(Open9xSimMap)) FXIMPLEMENT(OpenTxSim,FXMainWindow,OpenTxSimMap,ARRAYNUMBER(OpenTxSimMap))
Open9xSim::Open9xSim(FXApp* a): OpenTxSim::OpenTxSim(FXApp* a):
FXMainWindow(a, "OpenTX Simu", NULL, NULL, DECOR_ALL, 20, 90, 0, 0) FXMainWindow(a, "OpenTX Simu", NULL, NULL, DECOR_ALL, 20, 90, 0, 0)
{ {
firstTime = true;
memset(displayBuf, 0, DISPLAY_BUFFER_SIZE * sizeof(display_t)); memset(displayBuf, 0, DISPLAY_BUFFER_SIZE * sizeof(display_t));
bmp = new FXPPMImage(getApp(),NULL,IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2); bmp = new FXPPMImage(getApp(),NULL,IMAGE_OWNED|IMAGE_KEEP|IMAGE_SHMI|IMAGE_SHMP, W2, H2);
@ -89,8 +87,8 @@ Open9xSim::Open9xSim(FXApp* a):
SDL_Init(SDL_INIT_AUDIO); SDL_Init(SDL_INIT_AUDIO);
#endif #endif
FXHorizontalFrame *hf11=new FXHorizontalFrame(this,LAYOUT_CENTER_X); FXHorizontalFrame * hf11 = new FXHorizontalFrame(this,LAYOUT_CENTER_X);
FXHorizontalFrame *hf1=new FXHorizontalFrame(this,LAYOUT_FILL_X); FXHorizontalFrame * hf1 = new FXHorizontalFrame(this,LAYOUT_FILL_X);
//rh lv rv lh //rh lv rv lh
for (int i=0; i<4; i++) { for (int i=0; i<4; i++) {
@ -131,16 +129,19 @@ Open9xSim::Open9xSim(FXApp* a):
} }
bmf = new FXImageFrame(this,bmp); bmf = new FXImageFrame(this,bmp);
bmf->enable();
bmf->setTarget(this);
updateKeysAndSwitches(true); updateKeysAndSwitches(true);
getApp()->addTimeout(this, 2, 100); getApp()->addTimeout(this, 2, 100);
} }
Open9xSim::~Open9xSim() OpenTxSim::~OpenTxSim()
{ {
StopSimu(); StopSimu();
StopAudioThread(); StopAudioThread();
#if defined(EEPROM) #if defined(EEPROM)
StopEepromThread(); StopEepromThread();
#endif #endif
@ -162,7 +163,7 @@ Open9xSim::~Open9xSim()
#endif #endif
} }
void Open9xSim::createBitmap(int index, uint16_t *data, int x, int y, int w, int h) void OpenTxSim::createBitmap(int index, uint16_t *data, int x, int y, int w, int h)
{ {
FXPNGImage snapshot(getApp(), NULL, IMAGE_OWNED, w, h); FXPNGImage snapshot(getApp(), NULL, IMAGE_OWNED, w, h);
@ -187,59 +188,62 @@ void Open9xSim::createBitmap(int index, uint16_t *data, int x, int y, int w, int
} }
} }
void Open9xSim::makeSnapshot(const FXDrawable* drawable) void OpenTxSim::makeSnapshot(const FXDrawable* drawable)
{ {
// Construct and create an FXImage object // Construct and create an FXImage object
FXPNGImage snapshot(getApp(), NULL, 0, drawable->getWidth(), drawable->getHeight()); FXPNGImage snapshot(getApp(), NULL, 0, drawable->getWidth(), drawable->getHeight());
snapshot.create(); snapshot.create();
// Create a window device context and lock it onto the image // Create a window device context and lock it onto the image
FXDCWindow dc(&snapshot); FXDCWindow dc(&snapshot);
// Draw from the widget to this // Draw from the widget to this
dc.drawArea(drawable, 0, 0, drawable->getWidth(), drawable->getHeight(), 0, 0); dc.drawArea(drawable, 0, 0, drawable->getWidth(), drawable->getHeight(), 0, 0);
// Release lock // Release lock
dc.end(); dc.end();
// Grab pixels from server side back to client side // Grab pixels from server side back to client side
snapshot.restore(); snapshot.restore();
// Save recovered pixels to a file // Save recovered pixels to a file
FXFileStream stream; FXFileStream stream;
char buf[100]; char buf[100];
do { do {
stream.close(); stream.close();
sprintf(buf,"snapshot_%02d.png", ++g_snapshot_idx); sprintf(buf, "snapshot_%02d.png", ++g_snapshot_idx);
} while (stream.open(buf, FXStreamLoad)); } while (stream.open(buf, FXStreamLoad));
if (stream.open(buf, FXStreamSave)) { if (stream.open(buf, FXStreamSave)) {
snapshot.savePixels(stream); snapshot.savePixels(stream);
stream.close(); stream.close();
printf("Snapshot written: %s\n", buf); printf("Snapshot written: %s\n", buf);
} }
else { else {
printf("Cannot create snapshot %s\n", buf); printf("Cannot create snapshot %s\n", buf);
} }
} }
void Open9xSim::doEvents() void OpenTxSim::doEvents()
{ {
getApp()->runOneEvent(false); getApp()->runOneEvent(false);
} }
long Open9xSim::onKeypress(FXObject*,FXSelector,void*v) long OpenTxSim::onKeypress(FXObject *, FXSelector, void * v)
{ {
FXEvent *evt=(FXEvent*)v; FXEvent *evt = (FXEvent *)v;
// printf("keypress %x\n", evt->code);
if (evt->code=='s') { // TRACE("keypress %x", evt->code);
if (evt->code == 's') {
makeSnapshot(bmf); makeSnapshot(bmf);
} }
return 0; return 0;
} }
void Open9xSim::updateKeysAndSwitches(bool start) void OpenTxSim::updateKeysAndSwitches(bool start)
{ {
static int keys1[] = { static int keys1[] = {
#if defined(PCBHORUS) #if defined(PCBHORUS)
@ -352,7 +356,7 @@ void Open9xSim::updateKeysAndSwitches(bool start)
#endif #endif
} }
long Open9xSim::onTimeout(FXObject*, FXSelector, void*) long OpenTxSim::onTimeout(FXObject*, FXSelector, void*)
{ {
if (hasFocus()) { if (hasFocus()) {
#if defined(COPROCESSOR) #if defined(COPROCESSOR)
@ -442,7 +446,7 @@ long Open9xSim::onTimeout(FXObject*, FXSelector, void*)
#define BL_COLOR FXRGB(150, 200, 152) #define BL_COLOR FXRGB(150, 200, 152)
#endif #endif
void Open9xSim::setPixel(int x, int y, FXColor color) void OpenTxSim::setPixel(int x, int y, FXColor color)
{ {
#if LCD_ZOOM > 1 #if LCD_ZOOM > 1
for (int i=0; i<LCD_ZOOM; ++i) { for (int i=0; i<LCD_ZOOM; ++i) {
@ -455,17 +459,17 @@ void Open9xSim::setPixel(int x, int y, FXColor color)
#endif #endif
} }
void Open9xSim::refreshDisplay() void OpenTxSim::refreshDisplay()
{ {
if (simuLcdRefresh) { if (simuLcdRefresh) {
simuLcdRefresh = false; simuLcdRefresh = false;
FXColor offColor = isBacklightEnabled() ? BL_COLOR : FXRGB(200, 200, 200); FXColor offColor = isBacklightEnabled() ? BL_COLOR : FXRGB(200, 200, 200);
#if LCD_W == 128 #if LCD_DEPTH == 1
FXColor onColor = FXRGB(0, 0, 0); FXColor onColor = FXRGB(0, 0, 0);
#endif #endif
for (int x=0; x<LCD_W; x++) { for (int x=0; x<LCD_W; x++) {
for (int y=0; y<LCD_H; y++) { for (int y=0; y<LCD_H; y++) {
#if defined(PCBHORUS) #if defined(COLORLCD)
display_t z = simuLcdBuf[y * LCD_W + x]; display_t z = simuLcdBuf[y * LCD_W + x];
if (1) { if (1) {
if (z == 0) { if (z == 0) {
@ -479,7 +483,7 @@ void Open9xSim::refreshDisplay()
setPixel(x, y, color); setPixel(x, y, color);
} }
} }
#elif LCD_W >= 212 #elif LCD_DEPTH == 4
display_t * p = &simuLcdBuf[y / 2 * LCD_W + x]; display_t * p = &simuLcdBuf[y / 2 * LCD_W + x];
uint8_t z = (y & 1) ? (*p >> 4) : (*p & 0x0F); uint8_t z = (y & 1) ? (*p >> 4) : (*p & 0x0F);
if (z) { if (z) {
@ -506,15 +510,16 @@ void Open9xSim::refreshDisplay()
} }
} }
Open9xSim *th9xSim; OpenTxSim * opentxSim;
void doFxEvents() void doFxEvents()
{ {
//puts("doFxEvents"); //puts("doFxEvents");
th9xSim->getApp()->runOneEvent(false); opentxSim->getApp()->runOneEvent(false);
th9xSim->refreshDisplay(); opentxSim->refreshDisplay();
} }
int main(int argc,char **argv) int main(int argc, char ** argv)
{ {
// Each FOX GUI program needs one, and only one, application object. // Each FOX GUI program needs one, and only one, application object.
// The application objects coordinates some common stuff shared between // The application objects coordinates some common stuff shared between
@ -537,15 +542,15 @@ int main(int argc,char **argv)
// drag handles, and so on the Window Manager is supposed to give this // drag handles, and so on the Window Manager is supposed to give this
// window. // window.
//FXMainWindow *main=new FXMainWindow(&application,"Hello",NULL,NULL,DECOR_ALL); //FXMainWindow *main=new FXMainWindow(&application,"Hello",NULL,NULL,DECOR_ALL);
th9xSim = new Open9xSim(&application); opentxSim = new OpenTxSim(&application);
application.create(); application.create();
// Pretty self-explanatory:- this shows the window, and places it in the // Pretty self-explanatory:- this shows the window, and places it in the
// middle of the screen. // middle of the screen.
#ifndef __APPLE__ #ifndef __APPLE__
th9xSim->show(PLACEMENT_SCREEN); opentxSim->show(PLACEMENT_SCREEN);
#else #else
th9xSim->show(); // Otherwise the main window gets centred across my two monitors, split down the middle. opentxSim->show(); // Otherwise the main window gets centred across my two monitors, split down the middle.
#endif #endif
#if defined(TELEMETRY_FRSKY) && !defined(TELEMETRY_FRSKY_SPORT) #if defined(TELEMETRY_FRSKY) && !defined(TELEMETRY_FRSKY_SPORT)
@ -568,9 +573,9 @@ int main(int argc,char **argv)
uint16_t anaIn(uint8_t chan) uint16_t anaIn(uint8_t chan)
{ {
if (chan<NUM_STICKS) if (chan<NUM_STICKS)
return th9xSim->sliders[chan]->getValue(); return opentxSim->sliders[chan]->getValue();
else if (chan<NUM_STICKS+NUM_POTS+NUM_SLIDERS) else if (chan<NUM_STICKS+NUM_POTS+NUM_SLIDERS)
return th9xSim->knobs[chan-NUM_STICKS]->getValue(); return opentxSim->knobs[chan-NUM_STICKS]->getValue();
#if defined(PCBHORUS) #if defined(PCBHORUS)
else if (chan == TX_VOLTAGE) else if (chan == TX_VOLTAGE)
return 1737; //~10.6V return 1737; //~10.6V
@ -603,5 +608,5 @@ uint16_t getAnalogValue(uint8_t index)
void createBitmap(int index, uint16_t *data, int x, int y, int w, int h) void createBitmap(int index, uint16_t *data, int x, int y, int w, int h)
{ {
th9xSim->createBitmap(index, data, x, y, w, h); opentxSim->createBitmap(index, data, x, y, w, h);
} }

View file

@ -554,7 +554,8 @@ void StartAudioThread(int volumeGain)
struct sched_param sp; struct sched_param sp;
sp.sched_priority = SCHED_RR; sp.sched_priority = SCHED_RR;
pthread_attr_setschedparam(&attr, &sp); pthread_attr_setschedparam(&attr, &sp);
pthread_create(&simuAudio.threadPid, &attr, &audioThread, NULL); pthread_create(&simuAudio.threadPid, &attr, &audioThread, nullptr);
pthread_setname_np(simuAudio.threadPid, "audio");
return; return;
} }

View file

@ -20,8 +20,8 @@
#include "opentx.h" #include "opentx.h"
const char * eepromFile = NULL; const char * eepromFile = nullptr;
FILE * fp = NULL; FILE * fp = nullptr;
uint32_t eeprom_pointer; uint32_t eeprom_pointer;
uint8_t * eeprom_buffer_data; uint8_t * eeprom_buffer_data;
@ -33,7 +33,7 @@ bool eeprom_thread_running = false;
#if defined(EEPROM_SIZE) #if defined(EEPROM_SIZE)
uint8_t eeprom[EEPROM_SIZE]; uint8_t eeprom[EEPROM_SIZE];
#else #else
uint8_t * eeprom = NULL; uint8_t * eeprom = nullptr;
#endif #endif
sem_t * eeprom_write_sem; sem_t * eeprom_write_sem;
@ -75,7 +75,7 @@ void * eeprom_thread_function(void *)
{ {
while (!sem_wait(eeprom_write_sem)) { while (!sem_wait(eeprom_write_sem)) {
if (!eeprom_thread_running) if (!eeprom_thread_running)
return NULL; return nullptr;
assert(eeprom_buffer_size); assert(eeprom_buffer_size);
if (eeprom_read_operation) { if (eeprom_read_operation) {
eepromReadBlock(eeprom_buffer_data, eeprom_pointer, eeprom_buffer_size); eepromReadBlock(eeprom_buffer_data, eeprom_pointer, eeprom_buffer_size);
@ -162,17 +162,20 @@ void StartEepromThread(const char * filename)
sem_init(eeprom_write_sem, 0, 0); sem_init(eeprom_write_sem, 0, 0);
#endif #endif
if (!pthread_create(&eeprom_thread_pid, NULL, &eeprom_thread_function, NULL)) if (!pthread_create(&eeprom_thread_pid, nullptr, &eeprom_thread_function, nullptr)) {
pthread_setname_np(eeprom_thread_pid, "eeprom");
eeprom_thread_running = true; eeprom_thread_running = true;
else }
else {
perror("Could not create eeprom thread."); perror("Could not create eeprom thread.");
}
} }
void StopEepromThread() void StopEepromThread()
{ {
eeprom_thread_running = false; eeprom_thread_running = false;
sem_post(eeprom_write_sem); sem_post(eeprom_write_sem);
pthread_join(eeprom_thread_pid, NULL); pthread_join(eeprom_thread_pid, nullptr);
#ifdef __APPLE__ #ifdef __APPLE__
sem_close(eeprom_write_sem); sem_close(eeprom_write_sem);

View file

@ -285,11 +285,11 @@ void tasksStart()
cliStart(); cliStart();
#endif #endif
RTOS_CREATE_TASK(mixerTaskId, mixerTask, "Mixer", mixerStack, MIXER_STACK_SIZE, MIXER_TASK_PRIO); RTOS_CREATE_TASK(mixerTaskId, mixerTask, "mixer", mixerStack, MIXER_STACK_SIZE, MIXER_TASK_PRIO);
RTOS_CREATE_TASK(menusTaskId, menusTask, "Menus", menusStack, MENUS_STACK_SIZE, MENUS_TASK_PRIO); RTOS_CREATE_TASK(menusTaskId, menusTask, "menus", menusStack, MENUS_STACK_SIZE, MENUS_TASK_PRIO);
#if !defined(SIMU) #if !defined(SIMU)
RTOS_CREATE_TASK(audioTaskId, audioTask, "Audio", audioStack, AUDIO_STACK_SIZE, AUDIO_TASK_PRIO); RTOS_CREATE_TASK(audioTaskId, audioTask, "audio", audioStack, AUDIO_STACK_SIZE, AUDIO_TASK_PRIO);
#endif #endif
RTOS_CREATE_MUTEX(audioMutex); RTOS_CREATE_MUTEX(audioMutex);