From f70b02712ac333fea1a3ddd02339b4cc16672257 Mon Sep 17 00:00:00 2001 From: lcgamboa Date: Sat, 13 Jan 2024 15:40:55 -0300 Subject: [PATCH] chg: Code refactor - Moving menu stuff out library !minor --- VERSION | 2 +- src/boards/board_PICGenios.cc | 2 +- src/boards/bridge_gpsim.cc | 2 +- src/lib/picsimlab.cc | 70 ++++------------------------------- src/lib/picsimlab.h | 10 +---- src/picsimlab1.cc | 59 +++++++++++++++++++++++++++-- src/picsimlab1.h | 9 ++++- 7 files changed, 75 insertions(+), 79 deletions(-) diff --git a/VERSION b/VERSION index 867d6625..f6c77084 100644 --- a/VERSION +++ b/VERSION @@ -2,5 +2,5 @@ PACKAGE=picsimlab MAINVER=0 MINORVER=9 VERSION=0.9.1 -DATE=240111 +DATE=240113 VERSION_STABLE=0.9.1 diff --git a/src/boards/board_PICGenios.cc b/src/boards/board_PICGenios.cc index 1c5d342b..1b082754 100644 --- a/src/boards/board_PICGenios.cc +++ b/src/boards/board_PICGenios.cc @@ -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 diff --git a/src/boards/bridge_gpsim.cc b/src/boards/bridge_gpsim.cc index 66989fc7..93ae38c0 100644 --- a/src/boards/bridge_gpsim.cc +++ b/src/boards/bridge_gpsim.cc @@ -13,7 +13,7 @@ // #include #include -#include "../lib/picsimlab.h" +#include "../lib/util.h" void simulation_cleanup(void); diff --git a/src/lib/picsimlab.cc b/src/lib/picsimlab.cc index 08f48617..9a4f37ee 100644 --- a/src/lib/picsimlab.cc +++ b/src/lib/picsimlab.cc @@ -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(); } @@ -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); } } @@ -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) { @@ -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); diff --git a/src/lib/picsimlab.h b/src/lib/picsimlab.h index 0918e3ab..b2aed840 100644 --- a/src/lib/picsimlab.h +++ b/src/lib/picsimlab.h @@ -33,8 +33,6 @@ extern char SERIALDEVICE[100]; -#define MAX_MIC 140 - #include "board.h" #include "util.h" @@ -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); diff --git a/src/picsimlab1.cc b/src/picsimlab1.cc index 4c00ff71..af16da8b 100644 --- a/src/picsimlab1.cc +++ b/src/picsimlab1.cc @@ -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; @@ -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) { diff --git a/src/picsimlab1.h b/src/picsimlab1.h index 615ad021..862e2146 100644 --- a/src/picsimlab1.h +++ b/src/picsimlab1.h @@ -50,6 +50,9 @@ #define CPWINDOW1 #include +#include "lib/board.h" + +#define MAX_MIC 140 /** * @brief CPWindow1 class @@ -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; };