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

Minor changes to be able to wrap everything into a simulation tool inside companion9x

This commit is contained in:
bsongis 2011-12-07 20:36:13 +00:00
parent 87dddbb773
commit 53d9ddfacd
10 changed files with 72 additions and 39 deletions

View file

@ -730,9 +730,6 @@ endif
simu: $(CPPSRC) Makefile simu.cpp $(CPPSRC) simpgmspace.cpp *.h *.lbm eeprom.bin
g++ simu.cpp $(CPPFLAGS) $(CPPSRC) simpgmspace.cpp $(ARCH) -MD -DSIMU -o simu $(FOXINC) $(FOXLIB)
gruvin9x.so: $(CPPSRC) Makefile export.cpp $(CPPSRC) simpgmspace.cpp *.h *.lbm
g++ export.cpp $(CPPFLAGS) $(CPPSRC) simpgmspace.cpp $(ARCH) -g -MD -DSIMU -shared -fPIC -Wl,-soname,$@ -o $@
eeprom.bin:
dd if=/dev/zero of=$@ bs=1 count=2048

View file

@ -185,8 +185,8 @@ bool EeFsOpen()
eeprom_read_block(&eeFs,0,sizeof(eeFs));
#ifdef SIMU
if(eeFs.version != EEFS_VERS) printf("bad eeFs.version\n");
if(eeFs.mySize != sizeof(eeFs)) printf("bad eeFs.mySize\n");
if(eeFs.version != EEFS_VERS) perror("bad eeFs.version\n");
if(eeFs.mySize != sizeof(eeFs)) perror("bad eeFs.mySize\n");
#endif
return eeFs.version == EEFS_VERS && eeFs.mySize == sizeof(eeFs);
@ -429,7 +429,7 @@ bool RlcFile::copy(uint8_t i_fileDst, uint8_t i_fileSrc)
while ((len=theFile2.read(buf, 15)))
{
write(buf, len);
if (errno() != 0) {
if (write_errno() != 0) {
s_sync_write = false;
return false;
}

View file

@ -87,7 +87,7 @@ extern uint8_t s_write_err; // error reasons
extern uint8_t s_sync_write;
///deliver current errno, this is reset in open
inline uint8_t errno() { return s_write_err; }
inline uint8_t write_errno() { return s_write_err; }
class RlcFile: public EFile
{

View file

@ -59,6 +59,7 @@ MenuFuncP_PROGMEM APM menuTabDiag[] = {
void menuProcSetup(uint8_t event)
{
#define COUNT_ITEMS 19
#undef PARAM_OFS
#define PARAM_OFS 17*FW
SIMPLE_MENU("RADIO SETUP", menuTabDiag, e_Setup, COUNT_ITEMS+1);

View file

@ -21,6 +21,7 @@
#include "menus.h"
#undef ALTERNATE
#define ALTERNATE 0x10
enum MainViews {

View file

@ -382,6 +382,7 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo
}
}
#undef PARAM_OFS
#define PARAM_OFS (9*FW+2)
void menuProcModel(uint8_t event)
{

View file

@ -284,7 +284,6 @@ void eeLoadModel(uint8_t id)
#ifdef SIMU
if (sz > 0 && sz != sizeof(g_model)) {
printf("Model data read=%d bytes vs %d bytes\n", sz, sizeof(ModelData));
fflush(stdout);
}
#endif

View file

@ -29,18 +29,21 @@
volatile unsigned char pinb=0, pinc=0xff, pind, pine=0xff, ping=0xff, pinj=0xff, pinl=0;
unsigned char portb, dummyport;
const char *eepromFile = "eeprom.bin";
const char *eepromFile;
extern uint16_t eeprom_pointer;
extern const char* eeprom_buffer_data;
uint8_t eeprom[EESIZE];
sem_t eeprom_write_sem;
pthread_t eeprom_thread_pid = 0;
bool eeprom_thread_running = true;
void *eeprom_write_function(void *)
{
while (!sem_wait(&eeprom_write_sem)) {
if (!eeprom_thread_running)
return NULL;
FILE *fp = NULL;
if (eepromFile) {
@ -72,19 +75,64 @@ void *eeprom_write_function(void *)
return 0;
}
void InitEepromThread()
bool main_thread_running = true;
void *main_thread(void *)
{
g_menuStack[0] = menuMainView;
g_menuStack[1] = menuProcModelSelect;
eeReadAll(); //load general setup and selected model
doSplash();
checkLowEEPROM();
checkTHR();
checkSwitches();
checkAlarm();
while (main_thread_running) {
perMain();
usleep(1000);
}
return NULL;
}
pthread_t main_thread_pid;
void StartMainThread()
{
main_thread_running = true;
pthread_create(&main_thread_pid, NULL, &main_thread, NULL);
}
void StopMainThread()
{
main_thread_running = false;
pthread_join(main_thread_pid, NULL);
}
pthread_t eeprom_thread_pid;
void StartEepromThread(const char *filename)
{
eepromFile = filename;
sem_init(&eeprom_write_sem, 0, 0);
eeprom_thread_running = true;
assert(!pthread_create(&eeprom_thread_pid, NULL, &eeprom_write_function, NULL));
}
void StopEepromThread()
{
eeprom_thread_running = false;
sem_post(&eeprom_write_sem);
pthread_join(eeprom_thread_pid, NULL);
}
void eeprom_read_block (void *pointer_ram,
const void *pointer_eeprom,
size_t size)
{
if (eepromFile) {
FILE *fp=fopen(eepromFile, "r");
if(fseek(fp, (long) pointer_eeprom, SEEK_SET)==-1) perror("error in seek");
if (!fp) { perror("error in fopen"); return; }
if (fseek(fp, (long) pointer_eeprom, SEEK_SET)==-1) perror("error in seek");
if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in read");
fclose(fp);
}

View file

@ -28,6 +28,9 @@
#include <pthread.h>
#include <semaphore.h>
#undef min
#undef max
#define APM
typedef unsigned char prog_uchar;
@ -91,6 +94,12 @@ extern sem_t eeprom_write_sem;
#define SPIF dummyport
#define SPCR dummyport
#define TIMSK dummyport
#define TIMSK1 dummyport
#define UDR0 dummyport
#define OCIE1A dummyport
#define OUT_B_LIGHT 7
#define INP_E_ElevDR 2
#define INP_E_Trainer 5
@ -118,7 +127,8 @@ extern sem_t eeprom_write_sem;
extern volatile unsigned char pinb,pinc,pind,pine,ping,pinj,pinl;
extern unsigned char portb,dummyport;
void InitEepromThread();
void StartMainThread();
void StartEepromThread(const char *filename="eeprom.bin");
extern const char *eepromFile;
void eeprom_read_block (void *pointer_ram,

View file

@ -143,7 +143,6 @@ Gruvin9xSim::Gruvin9xSim(FXApp* a)
bmf = new FXBitmapFrame(this,bmp,0,0,0,0,0,0,0,0,0);
bmf->setOnColor(FXRGB(0,0,0));
//getApp()->addChore(this,1);
getApp()->addTimeout(this,2,100);
}
@ -187,7 +186,6 @@ void Gruvin9xSim::makeSnapshot(const FXDrawable* drawable)
}
void Gruvin9xSim::doEvents()
{
//getApp()->addChore(this,1);
getApp()->runOneEvent(false);
}
@ -355,25 +353,6 @@ void Gruvin9xSim::refreshDiplay()
}
}
void *main_thread(void *)
{
g_menuStack[0] = menuMainView;
g_menuStack[1] = menuProcModelSelect;
eeReadAll(); //load general setup and selected model
doSplash();
checkLowEEPROM();
checkTHR();
checkSwitches();
checkAlarm();
while(1) {
perMain();
usleep(1000);
}
return 0;
}
Gruvin9xSim *th9xSim;
void doFxEvents()
{
@ -387,7 +366,6 @@ int main(int argc,char **argv)
if(argc>=2){
eepromFile = argv[1];
}
printf("eeprom = %s\n", eepromFile);
// Each FOX GUI program needs one, and only one, application object.
// The application objects coordinates some common stuff shared between
@ -421,10 +399,8 @@ int main(int argc,char **argv)
th9xSim->show(); // Otherwise the main window gets centred across my two monitors, split down the middle.
#endif
InitEepromThread();
pthread_t pid;
pthread_create(&pid, NULL, &main_thread, NULL);
StartEepromThread();
StartMainThread();
return application.run();
}