diff --git a/gui/gui_device.cpp b/gui/gui_device.cpp index c7cce91..660a8c8 100644 --- a/gui/gui_device.cpp +++ b/gui/gui_device.cpp @@ -338,7 +338,7 @@ mLogFiles.clear(); - mPowermon.requestGetFileList([this](uint16_t status, const std::vector &list) + mPowermon.requestGetLogFileList([this](uint16_t status, const std::vector &list) { if (status == Powermon::RSP_SUCCESS) { @@ -424,7 +424,7 @@ { const uint32_t block_size = Powermon::hasWifi(mPowermon.getLastDeviceInfo().hardware_revision_bcd) ? 128 * 1024 : 4 * 1024; - mPowermon.requestReadFile(mLogFiles.front().id, mFileSize, block_size, + mPowermon.requestReadLogFile(mLogFiles.front().id, mFileSize, block_size, [this](uint16_t status, const uint8_t* data, size_t size) { if ((status == Powermon::RSP_SUCCESS) && size) @@ -752,6 +752,14 @@ { stopSync(); Model::getInstance().deleteLogData(); + + mPowermon.requestClearLog([this](uint16_t status) + { + wxQueueEvent(this, new GuiEvent([this, status](const GuiEvent &event) + { + checkDeviceError(this, status); + })); + }); } diff --git a/gui/gui_fg_stats.cpp b/gui/gui_fg_stats.cpp index 30c38fa..49292fc 100644 --- a/gui/gui_fg_stats.cpp +++ b/gui/gui_fg_stats.cpp @@ -26,8 +26,12 @@ //main window sizer wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); - SetSizer(main_sizer); + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + main_sizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 20); + + + wxString str; if (stats.time_since_last_full_charge != 0xFFFFFFFF) @@ -55,64 +59,66 @@ str.Printf(wxT("Time since last full charge: unknown")); } - - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Full charge capacity: %5.0f Ah"), stats.full_charge_capacity); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); if (fabs(stats.total_discharge) >= 1000000) str.Printf(wxT("Total discharged capacity: %.2f kAh"), stats.total_discharge / 1000000.0); else str.Printf(wxT("Total discharged capacity: %.1f Ah"), stats.total_discharge / 1000.0); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); if (fabs(stats.total_discharge_energy) >= 1000000) str.Printf(wxT("Total discharged energy: %.2f kWh"), stats.total_discharge_energy / 1000000.0); else str.Printf(wxT("Total discharged energy: %.0f Wh"), stats.total_discharge_energy / 1000.0); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); if (fabs(stats.total_charge) >= 1000000) str.Printf(wxT("Total charged capacity: %.2f kAh"), stats.total_charge / 1000000.0); else str.Printf(wxT("Total charged capacity: %.1f Ah"), stats.total_charge / 1000.0); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); if (fabs(stats.total_charge_energy) >= 1000000) str.Printf(wxT("Total charged energy: %.2f kWh"), stats.total_charge_energy / 1000000.0); else str.Printf(wxT("Total charged energy: %.0f Wh"), stats.total_charge_energy / 1000.0); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Minimum battery voltage: %.3f V"), stats.min_voltage); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Maximum battery voltage: %.3f V"), stats.max_voltage); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Maximum discharge current: %.2f A"), stats.max_discharge_current); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Maximum charge current: %.2f A"), stats.max_charge_current); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Last discharge depth: %.1f Ah"), stats.last_discharge); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Deepest discharge: %.1f Ah"), stats.deepest_discharge); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); str.Printf(wxT("Number of full discharge cycles: %u"), (uint32_t)round(stats.total_discharge / (1000.0 * stats.full_charge_capacity))); - main_sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(new wxStaticText(this, wxID_ANY, str), 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); - main_sizer->Add(mCloseButton, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); + main_sizer->Add(mCloseButton, 0, wxALL | wxALIGN_CENTER, 2 * BORDER_SIZE); + SetSizer(main_sizer); main_sizer->SetSizeHints(this); + Fit(); + Centre(); } diff --git a/gui/gui_stats.cpp b/gui/gui_stats.cpp index 48a56f9..a786d2d 100644 --- a/gui/gui_stats.cpp +++ b/gui/gui_stats.cpp @@ -37,61 +37,66 @@ //main window sizer wxBoxSizer* main_sizer = new wxBoxSizer(wxVERTICAL); - SetSizer(main_sizer); + + wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL); + main_sizer->Add(sizer, 0, wxALL | wxALIGN_CENTER, 20); wxBoxSizer* h_sizer; h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Time Since Powered On:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mSecondsSinceOnText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Minimum Voltage 1:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mVoltage1MinText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Maximum Voltage 1:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mVoltage1MaxText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Minimum Voltage 2:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mVoltage2MinText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Maximum Voltage 2:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mVoltage2MaxText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Peak Discharge Current:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mPeakDischargeCurrentText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Peak Charge Current:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mPeakChargeCurrentText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Minimum Temperature:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mTemperatureMinText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(new wxStaticText(this, wxID_ANY, wxT("Maximum Temperature:")), 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); h_sizer->Add(mTemperatureMaxText, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); - main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, BORDER_SIZE); + sizer->Add(h_sizer, 0, wxALL | wxALIGN_LEFT, 0); h_sizer = new wxBoxSizer(wxHORIZONTAL); h_sizer->Add(mResetButton, 0, wxALIGN_CENTER | wxALL, BORDER_SIZE); h_sizer->Add(mCloseButton, 0, wxALIGN_CENTER | wxALL, BORDER_SIZE); main_sizer->Add(h_sizer, 0, wxALL | wxALIGN_CENTER, BORDER_SIZE); + SetSizer(main_sizer); main_sizer->SetSizeHints(this); + Fit(); + Centre(); mStatsTimer = new wxTimer(this, ID_STATS_TIMER); @@ -214,6 +219,7 @@ mTemperatureMaxText->SetLabel(str); Refresh(); + Fit(); } })); }); diff --git a/lib/powermon/inc/powermon.h b/lib/powermon/inc/powermon.h index 9bca041..53ecf71 100644 --- a/lib/powermon/inc/powermon.h +++ b/lib/powermon/inc/powermon.h @@ -364,6 +364,12 @@ static Powermon* createInstance(void); virtual ~Powermon(); + /** + * \brief Returns the PowerMon access library version + * \return Version in BCD format + */ + static uint16_t getVersion(void); + /** * \brief Connects to a remote WiFi PowerMon @@ -687,7 +693,7 @@ * \brief Requests the list of log files * \param cb Lambda of type void(ResponseCode, const std::vector&) that will be called to signal the result of the request */ - virtual void requestGetFileList(const std::function&)> &cb) = 0; + virtual void requestGetLogFileList(const std::function&)> &cb) = 0; /** @@ -697,7 +703,14 @@ * \param read_size Read size in bytes * \param cb Lambda of type void(ResponseCode, const uint8_t*, size_t) that will be called to signal the result of the request */ - virtual void requestReadFile(uint32_t file_id, uint32_t offset, uint32_t read_size, const std::function &cb) = 0; + virtual void requestReadLogFile(uint32_t file_id, uint32_t offset, uint32_t read_size, const std::function &cb) = 0; + + + /** + * \brief Requests committing the schedules to non-volatile memory + * \param cb Lambda of type void(ResponseCode) that will be called to signal the result of the request + */ + virtual void requestClearLog(const std::function &cb) = 0; /** @@ -712,6 +725,12 @@ const std::function &done_cb) = 0; + + virtual void requestReadDebug(uint32_t offset, uint32_t read_size, const std::function &cb) = 0; + virtual void requestEraseDebug(const std::function &cb) = 0; + + + /** * \brief Returns the IP address as string */ @@ -741,6 +760,12 @@ */ static std::string getPowerStatusString(PowerStatus ps); + + /** + * \brief Returns true if the PowerMon described by the BCD hardware revision has data logging capabilities + */ + static bool hasDataLog(uint8_t bcd); + /** * \brief Returns true if the PowerMon described by the BCD hardware revision has V2 @@ -761,6 +786,12 @@ /** + * \brief Returns true if the PowerMon described by the BCD hardware revision has Bluetooth + */ + static bool hasBluetooth(uint8_t bcd); + + + /** * \brief Returns true if the parameter is a valid BCD number */ static inline bool checkBCD(uint16_t bcd) diff --git a/lib/powermon/inc/powermon_scanner.h b/lib/powermon/inc/powermon_scanner.h index 0b8e477..25025e6 100644 --- a/lib/powermon/inc/powermon_scanner.h +++ b/lib/powermon/inc/powermon_scanner.h @@ -23,6 +23,8 @@ #include #include +#include + /** * \brief PowermonScanner offers support for scanning for PowerMon advertisments. Both BLE and WiFi PowerMon devices are supported. diff --git a/lib/powermon/powermon_lib.a b/lib/powermon/powermon_lib.a index 22325a0..10effa8 100644 --- a/lib/powermon/powermon_lib.a +++ b/lib/powermon/powermon_lib.a Binary files differ diff --git a/lib/powermon/powermon_lib.lib b/lib/powermon/powermon_lib.lib deleted file mode 100644 index 810f373..0000000 --- a/lib/powermon/powermon_lib.lib +++ /dev/null Binary files differ diff --git a/lib/powermon/powermon_libd.lib b/lib/powermon/powermon_libd.lib deleted file mode 100644 index 08f303e..0000000 --- a/lib/powermon/powermon_libd.lib +++ /dev/null Binary files differ