Skip to content

Commit

Permalink
chg: Code refactor - Moving menu stuff out library !minor
Browse files Browse the repository at this point in the history
  • Loading branch information
lcgamboa committed Jan 13, 2024
1 parent 9155434 commit f70b027
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 79 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PACKAGE=picsimlab
MAINVER=0
MINORVER=9
VERSION=0.9.1
DATE=240111
DATE=240113
VERSION_STABLE=0.9.1
2 changes: 1 addition & 1 deletion src/boards/board_PICGenios.cc
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ cboard_PICGenios::cboard_PICGenios(void) : font(10, lxFONTFAMILY_TELETYPE, lxFON
label5->SetHeight(24);
label5->SetEnable(1);
label5->SetVisible(1);
label5->SetText("Temp: 00.0°C");
label5->SetText("Temp: 27.50C");
label5->SetAlign(1);
PICSimLab.GetWindow()->CreateChild(label5);
// label6
Expand Down
2 changes: 1 addition & 1 deletion src/boards/bridge_gpsim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// #include <gpsim/stimuli.h>
#include <gpsim/sim_context.h>

#include "../lib/picsimlab.h"
#include "../lib/util.h"

void simulation_cleanup(void);

Expand Down
70 changes: 7 additions & 63 deletions src/lib/picsimlab.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,14 @@ CPICSimLab::CPICSimLab() {
cpu_cond = NULL;
#endif

updatestatus = NULL;
menu_EvBoard = NULL;
menu_EvMicrocontroller = NULL;
OnUpdateStatus = NULL;
OnConfigure = NULL;
board_Event = NULL;
board_ButtonEvent = NULL;
}

void CPICSimLab::Init(CWindow* w) {
Window = w;
if (Window) {
// board menu
for (int i = 0; i < BOARDS_LAST; i++) {
MBoard[i].SetFOwner(Window);
MBoard[i].SetName(std::to_string(i));
MBoard[i].SetText(boards_list[i].name);
MBoard[i].EvMenuActive = menu_EvBoard;
Window->GetChildByName("menu1")->GetChildByName("menu1_Board")->CreateChild(&MBoard[i]);
}
}
// check for other instances
StartRControl();
}
Expand Down Expand Up @@ -237,8 +226,8 @@ void CPICSimLab::SetDebugStatus(int dbs, int updatebtn) {
}

void CPICSimLab::UpdateStatus(const PICSimlabStatus field, const std::string msg) {
if ((updatestatus) && (field < PS_LAST)) {
(*updatestatus)(field, msg);
if ((OnUpdateStatus) && (field < PS_LAST)) {
(*OnUpdateStatus)(field, msg);
}
}

Expand Down Expand Up @@ -1064,38 +1053,10 @@ void CPICSimLab::Configure(const char* home, int use_default_board, int create,
#endif
}

if (Window) {
((CPMenu*)Window->GetChildByName("menu1")->GetChildByName("menu1_Microcontroller"))->DestroyChilds();
std::string sdev = pboard->GetSupportedDevices();
int f;
int dc = 0;
while (sdev.size() > 0) {
f = sdev.find(",");
if (f < 0)
break;
MMicro[dc].SetFOwner(Window);
MMicro[dc].SetName("Micro_" + std::to_string(dc + 1));
MMicro[dc].SetText(sdev.substr(0, f));
MMicro[dc].EvMenuActive = menu_EvMicrocontroller;
((CPMenu*)Window->GetChildByName("menu1")->GetChildByName("menu1_Microcontroller"))
->CreateChild(&MMicro[dc]);
MMicro[dc].SetVisible(true);
sdev = sdev.substr(f + 1, sdev.size() - f - 1);
dc++;

if (dc >= MAX_MIC) {
printf("PICSimLab: microcontroller menu only support %i entries!\n", MAX_MIC);
exit(-1);
}
}

((CFileDialog*)Window->GetChildByName("filedialog1"))->SetDir(GetPath());

((CDraw*)Window->GetChildByName("draw1"))->SetVisible(0);
((CDraw*)Window->GetChildByName("draw1"))
->SetImgFileName(lxGetLocalFile(GetSharePath() + "boards/" + pboard->GetPictureFileName()), GetScale(),
GetScale());
if ((OnConfigure)) {
(*OnConfigure)();
}

pboard->MSetSerial(SERIALDEVICE);

if (lfile) {
Expand Down Expand Up @@ -1216,23 +1177,6 @@ void CPICSimLab::Configure(const char* home, int use_default_board, int create,
}
#endif

#ifndef NO_TOOLS
if (Window) {
if ((!pboard->GetProcessorName().compare("atmega328p")) ||
(!pboard->GetProcessorName().compare("atmega2560"))) {
Window->GetChildByName("menu1")
->GetChildByName("menu1_Tools")
->GetChildByName("menu1_Tools_ArduinoBootloader")
->SetEnable(true);
} else {
Window->GetChildByName("menu1")
->GetChildByName("menu1_Tools")
->GetChildByName("menu1_Tools_ArduinoBootloader")
->SetEnable(false);
}
}
#endif

#ifndef __EMSCRIPTEN__
printf("PICSimLab: Remote Control Port %i\n", GetRemotecPort());
rcontrol_init(GetRemotecPort() + Instance);
Expand Down
10 changes: 2 additions & 8 deletions src/lib/picsimlab.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

extern char SERIALDEVICE[100];

#define MAX_MIC 140

#include "board.h"
#include "util.h"

Expand Down Expand Up @@ -270,12 +268,8 @@ class CPICSimLab {
int plHeight;
int use_dsr_reset;

CItemMenu MBoard[BOARDS_MAX];
CItemMenu MMicro[MAX_MIC];

void (*updatestatus)(const int field, const std::string msg);
void (CControl::*menu_EvBoard)(CControl* control);
void (CControl::*menu_EvMicrocontroller)(CControl* control);
void (*OnUpdateStatus)(const int field, const std::string msg);
void (*OnConfigure)(void);
void (CControl::*board_Event)(CControl* control);
void (CControl::*board_ButtonEvent)(CControl* control, const uint button, const uint x, const uint y,
const uint mask);
Expand Down
59 changes: 56 additions & 3 deletions src/picsimlab1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,21 @@ void CPWindow1::_EvOnCreate(CControl* control) {
PICSimLab.SetHomePath(home);
PICSimLab.SetPath((const char*)lxGetCwd().c_str());

PICSimLab.updatestatus = &CPWindow1::UpdateStatus;
PICSimLab.menu_EvBoard = EVMENUACTIVE & CPWindow1::menu1_EvBoard;
PICSimLab.menu_EvMicrocontroller = EVMENUACTIVE & CPWindow1::menu1_EvMicrocontroller;
PICSimLab.OnUpdateStatus = &CPWindow1::UpdateStatus;
PICSimLab.OnConfigure = &CPWindow1::OnConfigure;
PICSimLab.board_Event = EVONCOMBOCHANGE & CPWindow1::board_Event;
PICSimLab.board_ButtonEvent = EVMOUSEBUTTONRELEASE & CPWindow1::board_ButtonEvent;
PICSimLab.Init(this);

// board menu
for (int i = 0; i < BOARDS_LAST; i++) {
MBoard[i].SetFOwner(this);
MBoard[i].SetName(std::to_string(i));
MBoard[i].SetText(boards_list[i].name);
MBoard[i].EvMenuActive = EVMENUACTIVE & CPWindow1::menu1_EvBoard;
menu1_Board.CreateChild(&MBoard[i]);
}

Oscilloscope.Init(&Window4);

SpareParts.PropButtonRelease = EVMOUSEBUTTONRELEASE & CPWindow5::PropButtonRelease;
Expand Down Expand Up @@ -864,6 +872,51 @@ void CPWindow1::_EvOnCreate(CControl* control) {
label1.SetText(PICSimLab.GetBoard()->GetClkLabel());
}

void CPWindow1::OnConfigure(void) {
Window1.Configure();
}

void CPWindow1::Configure(void) {
menu1_Microcontroller.DestroyChilds();
std::string sdev = PICSimLab.GetBoard()->GetSupportedDevices();
int f;
int dc = 0;
while (sdev.size() > 0) {
f = sdev.find(",");
if (f < 0)
break;
MMicro[dc].SetFOwner(this);
MMicro[dc].SetName("Micro_" + std::to_string(dc + 1));
MMicro[dc].SetText(sdev.substr(0, f));
MMicro[dc].EvMenuActive = EVMENUACTIVE & CPWindow1::menu1_EvMicrocontroller;
menu1_Microcontroller.CreateChild(&MMicro[dc]);
MMicro[dc].SetVisible(true);
sdev = sdev.substr(f + 1, sdev.size() - f - 1);
dc++;

if (dc >= MAX_MIC) {
printf("PICSimLab: microcontroller menu only support %i entries!\n", MAX_MIC);
exit(-1);
}
}

filedialog1.SetDir(PICSimLab.GetPath());

draw1.SetVisible(0);
draw1.SetImgFileName(
lxGetLocalFile(PICSimLab.GetSharePath() + "boards/" + PICSimLab.GetBoard()->GetPictureFileName()),
PICSimLab.GetScale(), PICSimLab.GetScale());

#ifndef NO_TOOLS
if ((!PICSimLab.GetBoard()->GetProcessorName().compare("atmega328p")) ||
(!PICSimLab.GetBoard()->GetProcessorName().compare("atmega2560"))) {
menu1_Tools_ArduinoBootloader.SetEnable(true);
} else {
menu1_Tools_ArduinoBootloader.SetEnable(false);
}
#endif
}

// Change frequency

void CPWindow1::combo1_EvOnComboChange(CControl* control) {
Expand Down
9 changes: 7 additions & 2 deletions src/picsimlab1.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#define CPWINDOW1

#include <lxrad.h>
#include "lib/board.h"

#define MAX_MIC 140

/**
* @brief CPWindow1 class
Expand Down Expand Up @@ -155,12 +158,14 @@ class CPWindow1 : public CPWindow {
void menu1_EvMicrocontroller(CControl* control);
void DrawBoard(void);
static void UpdateStatus(const int field, const std::string msg);
static void OnConfigure(void);
void Configure(void);

private:
CItemMenu MBoard[BOARDS_MAX];
CItemMenu MMicro[MAX_MIC];
int pa;

float over;

int crt;
int zerocount;
};
Expand Down

0 comments on commit f70b027

Please sign in to comment.