diff --git a/include/settings.h b/include/settings.h index fc3fd31..ebf05cb 100644 --- a/include/settings.h +++ b/include/settings.h @@ -12,10 +12,10 @@ esp_power_level_t settings_load_esp_tx_power(void); bool settings_load_gps(void); void settings_menu_gps(void); -void settings_load_interval(interval_t *interval); -void settings_save_interval(interval_t *interval); +void settings_load_interval(interval_t &interval); +void settings_save_interval(const interval_t &interval); -void settings_add_interval_items(ezMenu *submenu, interval_t *interval); +void settings_add_interval_items(ezMenu *submenu, interval_t &interval); void settings_menu_interval(void); bool settings_load_multiconnect(void); diff --git a/include/spinner.h b/include/spinner.h index 8683d43..3c7c67e 100644 --- a/include/spinner.h +++ b/include/spinner.h @@ -14,10 +14,10 @@ struct __attribute__((packed)) SpinValue { spin_unit_t unit; }; -void spinner_modify_value(const char *title, bool preset, SpinValue *sv); +void spinner_modify_value(const char *title, bool preset, SpinValue &sv); -std::string sv2str(const SpinValue *sv); -unsigned long sv2ms(const SpinValue *sv); +std::string sv2str(const SpinValue &sv); +unsigned long sv2ms(const SpinValue &sv); void ms2hms(unsigned long ms, unsigned int *h, unsigned int *m, unsigned int *s); #endif diff --git a/lib/furble/Camera.cpp b/lib/furble/Camera.cpp index a377363..dd0cbbe 100644 --- a/lib/furble/Camera.cpp +++ b/lib/furble/Camera.cpp @@ -24,7 +24,7 @@ bool Camera::connect(esp_power_level_t power, progressFunc pFunc, void *pCtx) { return connected; } -bool Camera::isActive(void) { +bool Camera::isActive(void) const { return m_Active; } @@ -32,15 +32,15 @@ void Camera::setActive(bool active) { m_Active = active; } -const Camera::Type &Camera::getType(void) { +const Camera::Type &Camera::getType(void) const { return m_Type; } -const std::string &Camera::getName(void) { +const std::string &Camera::getName(void) const { return m_Name; } -const NimBLEAddress &Camera::getAddress(void) { +const NimBLEAddress &Camera::getAddress(void) const { return m_Address; } @@ -50,7 +50,7 @@ void Camera::updateProgress(progressFunc pFunc, void *ctx, float value) { } } -bool Camera::isConnected(void) { +bool Camera::isConnected(void) const { return m_Client->isConnected(); } diff --git a/lib/furble/Camera.h b/lib/furble/Camera.h index 55513eb..6006c31 100644 --- a/lib/furble/Camera.h +++ b/lib/furble/Camera.h @@ -87,29 +87,29 @@ class Camera { */ virtual void updateGeoData(const gps_t &gps, const timesync_t ×ync) = 0; - virtual size_t getSerialisedBytes(void) = 0; - virtual bool serialise(void *buffer, size_t bytes) = 0; + virtual size_t getSerialisedBytes(void) const = 0; + virtual bool serialise(void *buffer, size_t bytes) const = 0; /** * Checks if the client is still connected. */ - virtual bool isConnected(void); + virtual bool isConnected(void) const; /** * Camera is active (ie. connect() has succeeded previously). */ - bool isActive(void); + bool isActive(void) const; /** * Set camera activity state. */ void setActive(bool active); - const Type &getType(void); + const Type &getType(void) const; - const std::string &getName(void); + const std::string &getName(void) const; - const NimBLEAddress &getAddress(void); + const NimBLEAddress &getAddress(void) const; protected: Camera(Type type); diff --git a/lib/furble/CameraList.cpp b/lib/furble/CameraList.cpp index a6cfaf6..29c6afd 100644 --- a/lib/furble/CameraList.cpp +++ b/lib/furble/CameraList.cpp @@ -26,7 +26,7 @@ typedef struct { Camera::Type type; } index_entry_t; -void CameraList::fillSaveEntry(CameraList::index_entry_t &entry, Camera *camera) { +void CameraList::fillSaveEntry(index_entry_t &entry, const Camera *camera) { snprintf(entry.name, 16, "%08llX", (uint64_t)camera->getAddress()); entry.type = camera->getType(); } @@ -61,11 +61,11 @@ std::vector CameraList::load_index(void) { void CameraList::add_index(std::vector &index, index_entry_t &entry) { bool exists = false; - for (size_t i = 0; i < index.size(); i++) { - ESP_LOGI(LOG_TAG, "[%d] %s : %s", i, index[i].name, entry.name); - if (strcmp(index[i].name, entry.name) == 0) { + for (auto &i : index) { + ESP_LOGI(LOG_TAG, "%s : %s", i.name, entry.name); + if (strcmp(i.name, entry.name) == 0) { ESP_LOGI(LOG_TAG, "Overwriting existing entry: %s", entry.name); - index[i] = entry; + i = entry; exists = true; break; } @@ -77,7 +77,7 @@ void CameraList::add_index(std::vector &index, index_ } } -void CameraList::save(Furble::Camera *camera) { +void CameraList::save(const Furble::Camera *camera) { m_Prefs.begin(FURBLE_STR, false); std::vector index = load_index(); @@ -110,12 +110,11 @@ void CameraList::remove(Furble::Camera *camera) { for (i = 0; i < index.size(); i++) { if (strcmp(index[i].name, entry.name) == 0) { ESP_LOGI(LOG_TAG, "Deleting: %s", entry.name); + index.erase(index.begin() + i); break; } } - index.erase(index.begin() + i); - m_Prefs.remove(entry.name); save_index(index); @@ -138,15 +137,15 @@ void CameraList::load(void) { m_Prefs.begin(FURBLE_STR, true); m_ConnectList.clear(); std::vector index = load_index(); - for (size_t i = 0; i < index.size(); i++) { - size_t dbytes = m_Prefs.getBytesLength(index[i].name); + for (const auto &i : index) { + size_t dbytes = m_Prefs.getBytesLength(i.name); if (dbytes == 0) { continue; } uint8_t dbuffer[dbytes] = {0}; - m_Prefs.getBytes(index[i].name, dbuffer, dbytes); + m_Prefs.getBytes(i.name, dbuffer, dbytes); - switch (index[i].type) { + switch (i.type) { case Camera::Type::FUJIFILM: m_ConnectList.push_back(std::unique_ptr(new Fujifilm(dbuffer, dbytes))); break; @@ -184,7 +183,7 @@ Furble::Camera *CameraList::get(size_t n) { return m_ConnectList[n].get(); } -bool CameraList::match(NimBLEAdvertisedDevice *pDevice) { +bool CameraList::match(const NimBLEAdvertisedDevice *pDevice) { if (Fujifilm::matches(pDevice)) { m_ConnectList.push_back(std::unique_ptr(new Furble::Fujifilm(pDevice))); return true; diff --git a/lib/furble/CameraList.h b/lib/furble/CameraList.h index 39a31bc..c806c05 100644 --- a/lib/furble/CameraList.h +++ b/lib/furble/CameraList.h @@ -15,7 +15,7 @@ class CameraList { /** * Save camera to connection list. */ - static void save(Furble::Camera *camera); + static void save(const Furble::Camera *camera); /** * Remove camera from connection list. @@ -37,7 +37,7 @@ class CameraList { * * @return true if device matches */ - static bool match(NimBLEAdvertisedDevice *pDevice); + static bool match(const NimBLEAdvertisedDevice *pDevice); /** * Add mobile device to the list. @@ -65,7 +65,7 @@ class CameraList { Camera::Type type; } index_entry_t; - static void fillSaveEntry(index_entry_t &entry, Camera *camera); + static void fillSaveEntry(index_entry_t &entry, const Camera *camera); static std::vector load_index(void); static void save_index(std::vector &index); static void add_index(std::vector &index, index_entry_t &entry); diff --git a/lib/furble/CanonEOS.cpp b/lib/furble/CanonEOS.cpp index 00eb749..fb651f7 100644 --- a/lib/furble/CanonEOS.cpp +++ b/lib/furble/CanonEOS.cpp @@ -11,7 +11,7 @@ namespace Furble { CanonEOS::CanonEOS(Type type, const void *data, size_t len) : Camera(type) { if (len != sizeof(eos_t)) - throw; + abort(); const eos_t *eos = static_cast(data); m_Name = std::string(eos->name); @@ -19,7 +19,7 @@ CanonEOS::CanonEOS(Type type, const void *data, size_t len) : Camera(type) { memcpy(&m_Uuid, &eos->uuid, sizeof(Device::uuid128_t)); } -CanonEOS::CanonEOS(Type type, NimBLEAdvertisedDevice *pDevice) : Camera(type) { +CanonEOS::CanonEOS(Type type, const NimBLEAdvertisedDevice *pDevice) : Camera(type) { m_Name = pDevice->getName(); m_Address = pDevice->getAddress(); ESP_LOGI(LOG_TAG, "Name = %s", m_Name.c_str()); @@ -76,8 +76,6 @@ bool CanonEOS::write_prefix(NimBLEClient *pClient, * handled by the underlying NimBLE and ESP32 libraries. */ bool CanonEOS::connect(progressFunc pFunc, void *pCtx) { - using namespace std::placeholders; - if (NimBLEDevice::isBonded(m_Address)) { // Already bonded? Assume pair acceptance! m_PairResult = CANON_EOS_PAIR_ACCEPT; @@ -215,11 +213,11 @@ void CanonEOS::disconnect(void) { m_Client->disconnect(); } -size_t CanonEOS::getSerialisedBytes(void) { +size_t CanonEOS::getSerialisedBytes(void) const { return sizeof(eos_t); } -bool CanonEOS::serialise(void *buffer, size_t bytes) { +bool CanonEOS::serialise(void *buffer, size_t bytes) const { if (bytes != sizeof(eos_t)) { return false; } diff --git a/lib/furble/CanonEOS.h b/lib/furble/CanonEOS.h index cae2a4e..0f898a5 100644 --- a/lib/furble/CanonEOS.h +++ b/lib/furble/CanonEOS.h @@ -19,7 +19,7 @@ class CanonEOS: public Camera { } eos_t; CanonEOS(Type type, const void *data, size_t len); - CanonEOS(Type type, NimBLEAdvertisedDevice *pDevice); + CanonEOS(Type type, const NimBLEAdvertisedDevice *pDevice); ~CanonEOS(void); const char *CANON_EOS_SVC_IDEN_UUID = "00010000-0000-1000-0000-d8492fffa821"; @@ -63,8 +63,8 @@ class CanonEOS: public Camera { void focusRelease(void) override; void updateGeoData(const gps_t &gps, const timesync_t ×ync) override; void disconnect(void) override; - size_t getSerialisedBytes(void) override; - bool serialise(void *buffer, size_t bytes) override; + size_t getSerialisedBytes(void) const override; + bool serialise(void *buffer, size_t bytes) const override; Device::uuid128_t m_Uuid; diff --git a/lib/furble/CanonEOSM6.cpp b/lib/furble/CanonEOSM6.cpp index 6b77a88..70a7f5f 100644 --- a/lib/furble/CanonEOSM6.cpp +++ b/lib/furble/CanonEOSM6.cpp @@ -15,7 +15,7 @@ const uint8_t CANON_EOS_M6_XX_2 = 0x01; const uint8_t CANON_EOS_M6_XX_3 = 0xc5; const uint8_t CANON_EOS_M6_XX_4 = 0x32; -bool CanonEOSM6::matches(NimBLEAdvertisedDevice *pDevice) { +bool CanonEOSM6::matches(const NimBLEAdvertisedDevice *pDevice) { if (pDevice->haveManufacturerData() && pDevice->getManufacturerData().length() == CANON_EOS_M6_ADV_DATA_LEN) { const char *data = pDevice->getManufacturerData().data(); diff --git a/lib/furble/CanonEOSM6.h b/lib/furble/CanonEOSM6.h index 18d9920..a4e9a9e 100644 --- a/lib/furble/CanonEOSM6.h +++ b/lib/furble/CanonEOSM6.h @@ -10,12 +10,12 @@ namespace Furble { class CanonEOSM6: public CanonEOS { public: CanonEOSM6(const void *data, size_t len) : CanonEOS(Type::CANON_EOS_M6, data, len){}; - CanonEOSM6(NimBLEAdvertisedDevice *pDevice) : CanonEOS(Type::CANON_EOS_M6, pDevice){}; + CanonEOSM6(const NimBLEAdvertisedDevice *pDevice) : CanonEOS(Type::CANON_EOS_M6, pDevice){}; /** * Determine if the advertised BLE device is a Canon EOS M6. */ - static bool matches(NimBLEAdvertisedDevice *pDevice); + static bool matches(const NimBLEAdvertisedDevice *pDevice); private: }; diff --git a/lib/furble/CanonEOSRP.cpp b/lib/furble/CanonEOSRP.cpp index 3bbedb4..20878ec 100644 --- a/lib/furble/CanonEOSRP.cpp +++ b/lib/furble/CanonEOSRP.cpp @@ -18,7 +18,7 @@ const uint8_t CANON_EOS_RP_XX_5 = 0x00; const uint8_t CANON_EOS_RP_XX_6 = 0x00; const uint8_t CANON_EOS_RP_XX_7 = 0x02; -bool CanonEOSRP::matches(NimBLEAdvertisedDevice *pDevice) { +bool CanonEOSRP::matches(const NimBLEAdvertisedDevice *pDevice) { if (pDevice->haveManufacturerData() && pDevice->getManufacturerData().length() == CANON_EOS_RP_ADV_DATA_LEN) { const char *data = pDevice->getManufacturerData().data(); diff --git a/lib/furble/CanonEOSRP.h b/lib/furble/CanonEOSRP.h index 4b7b853..a657b60 100644 --- a/lib/furble/CanonEOSRP.h +++ b/lib/furble/CanonEOSRP.h @@ -10,12 +10,12 @@ namespace Furble { class CanonEOSRP: public CanonEOS { public: CanonEOSRP(const void *data, size_t len) : CanonEOS(Type::CANON_EOS_RP, data, len){}; - CanonEOSRP(NimBLEAdvertisedDevice *pDevice) : CanonEOS(Type::CANON_EOS_RP, pDevice){}; + CanonEOSRP(const NimBLEAdvertisedDevice *pDevice) : CanonEOS(Type::CANON_EOS_RP, pDevice){}; /** * Determine if the advertised BLE device is a Canon EOS RP. */ - static bool matches(NimBLEAdvertisedDevice *pDevice); + static bool matches(const NimBLEAdvertisedDevice *pDevice); private: }; diff --git a/lib/furble/Fujifilm.cpp b/lib/furble/Fujifilm.cpp index 46b87e1..336bae5 100644 --- a/lib/furble/Fujifilm.cpp +++ b/lib/furble/Fujifilm.cpp @@ -84,7 +84,7 @@ void Fujifilm::notify(BLERemoteCharacteristic *pChr, uint8_t *pData, size_t leng Fujifilm::Fujifilm(const void *data, size_t len) : Camera(Type::FUJIFILM) { if (len != sizeof(fujifilm_t)) - throw; + abort(); const fujifilm_t *fujifilm = static_cast(data); m_Name = std::string(fujifilm->name); @@ -92,7 +92,7 @@ Fujifilm::Fujifilm(const void *data, size_t len) : Camera(Type::FUJIFILM) { memcpy(m_Token.data(), fujifilm->token, FUJIFILM_TOKEN_LEN); } -Fujifilm::Fujifilm(NimBLEAdvertisedDevice *pDevice) : Camera(Type::FUJIFILM) { +Fujifilm::Fujifilm(const NimBLEAdvertisedDevice *pDevice) : Camera(Type::FUJIFILM) { const char *data = pDevice->getManufacturerData().data(); m_Name = pDevice->getName(); m_Address = pDevice->getAddress(); @@ -115,7 +115,7 @@ constexpr uint8_t FUJIFILM_TYPE_TOKEN = 0x02; /** * Determine if the advertised BLE device is a Fujifilm. */ -bool Fujifilm::matches(NimBLEAdvertisedDevice *pDevice) { +bool Fujifilm::matches(const NimBLEAdvertisedDevice *pDevice) { if (pDevice->haveManufacturerData() && pDevice->getManufacturerData().length() == FUJIFILM_ADV_TOKEN_LEN) { const char *data = pDevice->getManufacturerData().data(); @@ -315,11 +315,11 @@ void Fujifilm::disconnect(void) { m_Client->disconnect(); } -size_t Fujifilm::getSerialisedBytes(void) { +size_t Fujifilm::getSerialisedBytes(void) const { return sizeof(fujifilm_t); } -bool Fujifilm::serialise(void *buffer, size_t bytes) { +bool Fujifilm::serialise(void *buffer, size_t bytes) const { if (bytes != sizeof(fujifilm_t)) { return false; } diff --git a/lib/furble/Fujifilm.h b/lib/furble/Fujifilm.h index 7e4262f..3aaa577 100644 --- a/lib/furble/Fujifilm.h +++ b/lib/furble/Fujifilm.h @@ -14,13 +14,13 @@ namespace Furble { class Fujifilm: public Camera { public: Fujifilm(const void *data, size_t len); - Fujifilm(NimBLEAdvertisedDevice *pDevice); + Fujifilm(const NimBLEAdvertisedDevice *pDevice); ~Fujifilm(void); /** * Determine if the advertised BLE device is a Fujifilm X-T30. */ - static bool matches(NimBLEAdvertisedDevice *pDevice); + static bool matches(const NimBLEAdvertisedDevice *pDevice); bool connect(progressFunc pFunc = nullptr, void *pCtx = nullptr) override; void shutterPress(void) override; @@ -29,8 +29,8 @@ class Fujifilm: public Camera { void focusRelease(void) override; void updateGeoData(const gps_t &gps, const timesync_t ×ync) override; void disconnect(void) override; - size_t getSerialisedBytes(void) override; - bool serialise(void *buffer, size_t bytes) override; + size_t getSerialisedBytes(void) const override; + bool serialise(void *buffer, size_t bytes) const override; private: /** diff --git a/lib/furble/HIDServer.cpp b/lib/furble/HIDServer.cpp index 4611a33..8bd9339 100644 --- a/lib/furble/HIDServer.cpp +++ b/lib/furble/HIDServer.cpp @@ -113,7 +113,7 @@ void HIDServer::disconnect(NimBLEAddress &address) { m_Server->disconnect(info.getConnHandle()); } -bool HIDServer::isConnected(NimBLEAddress &address) { +bool HIDServer::isConnected(const NimBLEAddress &address) { NimBLEConnInfo info = m_Server->getPeerInfo(address); return (!info.getIdAddress().isNull()); diff --git a/lib/furble/HIDServer.h b/lib/furble/HIDServer.h index c75f1cb..3cb9051 100644 --- a/lib/furble/HIDServer.h +++ b/lib/furble/HIDServer.h @@ -35,7 +35,7 @@ class HIDServer: public NimBLEServerCallbacks { NimBLECharacteristic *getInput(void); NimBLEConnInfo getConnInfo(NimBLEAddress &address); void disconnect(NimBLEAddress &address); - bool isConnected(NimBLEAddress &address); + bool isConnected(const NimBLEAddress &address); private: HIDServer(); diff --git a/lib/furble/MobileDevice.cpp b/lib/furble/MobileDevice.cpp index 2b3a043..b6fd246 100644 --- a/lib/furble/MobileDevice.cpp +++ b/lib/furble/MobileDevice.cpp @@ -11,7 +11,7 @@ namespace Furble { MobileDevice::MobileDevice(const void *data, size_t len) : Camera(Type::MOBILE_DEVICE) { if (len != sizeof(mobile_device_t)) - throw; + abort(); const mobile_device_t *mobile_device = static_cast(data); m_Name = std::string(mobile_device->name); @@ -98,15 +98,15 @@ void MobileDevice::disconnect(void) { m_HIDServer->disconnect(m_Address); } -bool MobileDevice::isConnected(void) { +bool MobileDevice::isConnected(void) const { return m_HIDServer->isConnected(m_Address); } -size_t MobileDevice::getSerialisedBytes(void) { +size_t MobileDevice::getSerialisedBytes(void) const { return sizeof(mobile_device_t); } -bool MobileDevice::serialise(void *buffer, size_t bytes) { +bool MobileDevice::serialise(void *buffer, size_t bytes) const { if (bytes != sizeof(mobile_device_t)) { return false; } diff --git a/lib/furble/MobileDevice.h b/lib/furble/MobileDevice.h index 2378a6f..17d9c44 100644 --- a/lib/furble/MobileDevice.h +++ b/lib/furble/MobileDevice.h @@ -26,7 +26,7 @@ class MobileDevice: public Camera { void updateGeoData(const gps_t &gps, const timesync_t ×ync) override; void disconnect(void) override; - bool isConnected(void) override; + bool isConnected(void) const override; private: typedef struct _mobile_device_t { @@ -35,8 +35,8 @@ class MobileDevice: public Camera { uint8_t type; /** Address type. */ } mobile_device_t; - size_t getSerialisedBytes(void); - bool serialise(void *buffer, size_t bytes); + size_t getSerialisedBytes(void) const override; + bool serialise(void *buffer, size_t bytes) const override; void sendKeyReport(const uint8_t key); HIDServer *m_HIDServer; diff --git a/platformio.ini b/platformio.ini index 2c31298..8596840 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,6 @@ [furble] build_flags = -Wall + -fno-exceptions -DFURBLE_VERSION=\"${sysenv.FURBLE_VERSION}\" -DCORE_DEBUG_LEVEL=3 -DCONFIG_BT_NIMBLE_LOG_LEVEL=3 diff --git a/src/furble.cpp b/src/furble.cpp index c829763..43a566b 100644 --- a/src/furble.cpp +++ b/src/furble.cpp @@ -80,7 +80,7 @@ static void show_shutter_control(bool shutter_locked, unsigned long lock_start_m } static void remote_control(FurbleCtx *fctx) { - auto control = fctx->control; + auto *control = fctx->control; static unsigned long shutter_lock_start_ms = 0; static bool shutter_lock = false; @@ -153,7 +153,7 @@ static void remote_control(FurbleCtx *fctx) { */ static uint16_t statusRefresh(void *context) { FurbleCtx *fctx = static_cast(context); - auto control = fctx->control; + auto *control = fctx->control; if (control->isConnected()) { furble_gps_update(control); @@ -216,13 +216,13 @@ static void menu_remote(FurbleCtx *fctx) { } static bool do_connect(ezMenu *menu, void *context) { - auto ctx = static_cast(context); + auto *ctx = static_cast(context); FurbleCtx fctx = {ctx->control, false}; if (!ctx->scan && ctx->multiconnect) { for (int n = 0; n < Furble::CameraList::size(); n++) { - auto camera = Furble::CameraList::get(n); + auto *camera = Furble::CameraList::get(n); if (camera->isActive()) { ezProgressBar progress_bar(FURBLE_STR, {std::string("Connecting to ") + camera->getName()}, {""}); @@ -235,7 +235,7 @@ static bool do_connect(ezMenu *menu, void *context) { } } } else { - auto camera = Furble::CameraList::get(menu->pick() - 1); + auto *camera = Furble::CameraList::get(menu->pick() - 1); ezProgressBar progress_bar(FURBLE_STR, {std::string("Connecting to ") + camera->getName()}, {""}); @@ -254,7 +254,7 @@ static bool do_connect(ezMenu *menu, void *context) { } static bool toggleCameraSelect(ezMenu *menu, void *context) { - auto camera = static_cast(context); + auto *camera = static_cast(context); camera->setActive(!camera->isActive()); menu->setCaption(camera->getAddress().toString(), camera->getName() + "\t" + (camera->isActive() ? "*" : "")); @@ -266,15 +266,15 @@ static bool toggleCameraSelect(ezMenu *menu, void *context) { * Scan callback to update connection menu with new devices. */ static void updateConnectItems(void *context) { - auto ctx = static_cast(context); - auto menu = ctx->menu; + auto *ctx = static_cast(context); + auto *menu = ctx->menu; if (!ctx->scan && ctx->multiconnect) { menu->deleteItem(CONNECT_STAR); } menu->deleteItem("Back"); for (int i = menu->countItems(); i < Furble::CameraList::size(); i++) { - auto camera = Furble::CameraList::get(i); + auto *camera = Furble::CameraList::get(i); if (!ctx->scan && ctx->multiconnect) { menu->addItem(camera->getAddress().toString(), @@ -331,7 +331,7 @@ static void menu_connect(Furble::Control *control, bool scan) { * Scan for devices, then present connection menu. */ static bool do_scan(ezMenu *menu, void *context) { - auto control = static_cast(context); + auto *control = static_cast(context); Furble::CameraList::clear(); Furble::Scan::clear(); @@ -344,7 +344,7 @@ static bool do_scan(ezMenu *menu, void *context) { * Retrieve saved devices, then present connection menu. */ static bool do_saved(ezMenu *menu, void *context) { - auto control = static_cast(context); + auto *control = static_cast(context); Furble::CameraList::load(); menu_connect(control, false); @@ -408,7 +408,7 @@ static void mainmenu_poweroff(void) { } void vUITask(void *param) { - auto control = static_cast(param); + auto *control = static_cast(param); #include #include diff --git a/src/interval.cpp b/src/interval.cpp index 82508da..04af6c7 100644 --- a/src/interval.cpp +++ b/src/interval.cpp @@ -17,7 +17,7 @@ enum interval_state_t { static void display_interval_msg(interval_state_t state, unsigned int count, - SpinValue *sv_count, + const SpinValue &sv_count, unsigned long now, unsigned long next) { unsigned int rem_h = 0; @@ -51,11 +51,11 @@ static void display_interval_msg(interval_state_t state, int len = 0; int clen = 0; - if (sv_count->unit == SPIN_UNIT_INF) { + if (sv_count.unit == SPIN_UNIT_INF) { clen = snprintf(ccount, 16, "%09u", count); len = snprintf(hms, 32, "%02u:%02u:%02u", rem_h, rem_m, rem_s); } else { - clen = snprintf(ccount, 16, "%03u/%03u", count, sv_count->value); + clen = snprintf(ccount, 16, "%03u/%03u", count, sv_count.value); len = snprintf(hms, 32, "%02u:%02u:%02u", rem_h, rem_m, rem_s); } // ESP_LOGI(LOG_TAG, hms); @@ -68,10 +68,10 @@ static void display_interval_msg(interval_state_t state, } } -static void do_interval(FurbleCtx *fctx, interval_t *interval) { +static void do_interval(FurbleCtx *fctx, const interval_t &interval) { auto control = fctx->control; - const unsigned long config_delay = sv2ms(&interval->delay); - const unsigned long config_shutter = sv2ms(&interval->shutter); + const unsigned long config_delay = sv2ms(interval.delay); + const unsigned long config_shutter = sv2ms(interval.shutter); unsigned int icount = 0; @@ -94,7 +94,7 @@ static void do_interval(FurbleCtx *fctx, interval_t *interval) { switch (state) { case INTERVAL_SHUTTER_OPEN: - if ((icount < interval->count.value) || (interval->count.unit == SPIN_UNIT_INF)) { + if ((icount < interval.count.value) || (interval.count.unit == SPIN_UNIT_INF)) { control->sendCommand(CONTROL_CMD_SHUTTER_PRESS); next = now + config_shutter; state = INTERVAL_SHUTTER_WAIT; @@ -111,7 +111,7 @@ static void do_interval(FurbleCtx *fctx, interval_t *interval) { icount++; control->sendCommand(CONTROL_CMD_SHUTTER_RELEASE); next = now + config_delay; - if ((icount < interval->count.value) || (interval->count.unit == SPIN_UNIT_INF)) { + if ((icount < interval.count.value) || (interval.count.unit == SPIN_UNIT_INF)) { state = INTERVAL_DELAY; } else { state = INTERVAL_EXIT; @@ -134,7 +134,7 @@ static void do_interval(FurbleCtx *fctx, interval_t *interval) { active = false; } - display_interval_msg(state, icount, &interval->count, now, next); + display_interval_msg(state, icount, interval.count, now, next); } while (active && control->isConnected()); ez.backlight.inactivity(USER_SET); } @@ -142,12 +142,12 @@ static void do_interval(FurbleCtx *fctx, interval_t *interval) { void remote_interval(FurbleCtx *fctx) { interval_t interval; - settings_load_interval(&interval); + settings_load_interval(interval); ezMenu submenu(FURBLE_STR " - Interval"); submenu.buttons({"OK", "down"}); submenu.addItem("Start"); - settings_add_interval_items(&submenu, &interval); + settings_add_interval_items(&submenu, interval); submenu.addItem("Back"); submenu.downOnLast("first"); @@ -158,7 +158,7 @@ void remote_interval(FurbleCtx *fctx) { } if (submenu.pickName() == "Start") { - do_interval(fctx, &interval); + do_interval(fctx, interval); } } while (submenu.pickName() != "Back"); diff --git a/src/settings.cpp b/src/settings.cpp index f9e3a74..ecb0a00 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -171,34 +171,34 @@ void settings_menu_gps(void) { submenu.run(); } -void settings_load_interval(interval_t *interval) { +void settings_load_interval(interval_t &interval) { Preferences prefs; prefs.begin(FURBLE_STR, true); - size_t len = prefs.getBytes(PREFS_INTERVAL, interval, sizeof(interval_t)); + size_t len = prefs.getBytes(PREFS_INTERVAL, &interval, sizeof(interval_t)); if (len != sizeof(interval_t)) { // default values - interval->count.value = INTERVAL_DEFAULT_COUNT; - interval->count.unit = INTERVAL_DEFAULT_COUNT_UNIT; - interval->shutter.value = INTERVAL_DEFAULT_SHUTTER; - interval->shutter.unit = INTERVAL_DEFAULT_SHUTTER_UNIT; - interval->delay.value = INTERVAL_DEFAULT_DELAY; - interval->delay.unit = INTERVAL_DEFAULT_DELAY_UNIT; + interval.count.value = INTERVAL_DEFAULT_COUNT; + interval.count.unit = INTERVAL_DEFAULT_COUNT_UNIT; + interval.shutter.value = INTERVAL_DEFAULT_SHUTTER; + interval.shutter.unit = INTERVAL_DEFAULT_SHUTTER_UNIT; + interval.delay.value = INTERVAL_DEFAULT_DELAY; + interval.delay.unit = INTERVAL_DEFAULT_DELAY_UNIT; } prefs.end(); } -void settings_save_interval(interval_t *interval) { +void settings_save_interval(const interval_t &interval) { Preferences prefs; prefs.begin(FURBLE_STR, false); - prefs.putBytes(PREFS_INTERVAL, interval, sizeof(interval_t)); + prefs.putBytes(PREFS_INTERVAL, &interval, sizeof(interval_t)); prefs.end(); } static bool configure_count(ezMenu *menu, void *context) { - interval_t *interval = (interval_t *)context; + interval_t *interval = static_cast(context); ezMenu submenu("Count"); submenu.buttons({"OK", "down"}); @@ -209,26 +209,26 @@ static bool configure_count(ezMenu *menu, void *context) { submenu.runOnce(); if (submenu.pickName() == "Custom") { interval->count.unit = SPIN_UNIT_NIL; - spinner_modify_value("Count", false, &interval->count); + spinner_modify_value("Count", false, interval->count); } if (submenu.pickName() == "Infinite") { interval->count.unit = SPIN_UNIT_INF; } - std::string countstr = sv2str(&interval->count); + std::string countstr = sv2str(interval->count); if (interval->count.unit == SPIN_UNIT_INF) { countstr = "INF"; } menu->setCaption("interval_count", std::string("Count\t") + countstr); - settings_save_interval(interval); + settings_save_interval(*interval); return true; } static bool configure_delay(ezMenu *menu, void *context) { - interval_t *interval = (interval_t *)context; + interval_t *interval = static_cast(context); ezMenu submenu("Delay"); submenu.buttons({"OK", "down"}); @@ -246,15 +246,15 @@ static bool configure_delay(ezMenu *menu, void *context) { preset = true; } - spinner_modify_value("Delay", preset, &interval->delay); - menu->setCaption("interval_delay", "Delay\t" + sv2str(&interval->delay)); - settings_save_interval(interval); + spinner_modify_value("Delay", preset, interval->delay); + menu->setCaption("interval_delay", "Delay\t" + sv2str(interval->delay)); + settings_save_interval(*interval); return true; } static bool configure_shutter(ezMenu *menu, void *context) { - interval_t *interval = (interval_t *)context; + interval_t *interval = static_cast(context); ezMenu submenu("Shutter"); submenu.buttons({"OK", "down"}); @@ -272,30 +272,30 @@ static bool configure_shutter(ezMenu *menu, void *context) { preset = true; } - spinner_modify_value("Shutter", preset, &interval->shutter); - menu->setCaption("interval_shutter", "Shutter\t" + sv2str(&interval->shutter)); - settings_save_interval(interval); + spinner_modify_value("Shutter", preset, interval->shutter); + menu->setCaption("interval_shutter", "Shutter\t" + sv2str(interval->shutter)); + settings_save_interval(*interval); return true; } -void settings_add_interval_items(ezMenu *submenu, interval_t *interval) { - submenu->addItem("interval_count", std::string("Count\t") + sv2str(&interval->count), NULL, - interval, configure_count); - submenu->addItem("interval_delay", std::string("Delay\t") + sv2str(&interval->delay), NULL, - interval, configure_delay); - submenu->addItem("interval_shutter", std::string("Shutter\t") + sv2str(&interval->shutter), NULL, - interval, configure_shutter); +void settings_add_interval_items(ezMenu *submenu, interval_t &interval) { + submenu->addItem("interval_count", std::string("Count\t") + sv2str(interval.count), NULL, + &interval, configure_count); + submenu->addItem("interval_delay", std::string("Delay\t") + sv2str(interval.delay), NULL, + &interval, configure_delay); + submenu->addItem("interval_shutter", std::string("Shutter\t") + sv2str(interval.shutter), NULL, + &interval, configure_shutter); } void settings_menu_interval(void) { interval_t interval; - settings_load_interval(&interval); + settings_load_interval(interval); ezMenu submenu(FURBLE_STR " - Intervalometer settings"); submenu.buttons({"OK", "down"}); - settings_add_interval_items(&submenu, &interval); + settings_add_interval_items(&submenu, interval); submenu.addItem("Back"); submenu.downOnLast("first"); submenu.run(); diff --git a/src/spinner.cpp b/src/spinner.cpp index 6971515..43cd921 100644 --- a/src/spinner.cpp +++ b/src/spinner.cpp @@ -81,14 +81,14 @@ static void display_spinner(const char *title, ez.msgBox(title, {spin_row}, buttons, false); } -static void spinner_preset(const char *title, SpinValue *sv) { +static void spinner_preset(const char *title, SpinValue &sv) { const unsigned int imax = - sv->unit == SPIN_UNIT_NIL ? fmt_preset_none.size() : fmt_preset_unit.size(); + sv.unit == SPIN_UNIT_NIL ? fmt_preset_none.size() : fmt_preset_unit.size(); unsigned int i = 0; unsigned int n = 0; bool ok = false; - uint16_t value = sv->value; + uint16_t value = sv.value; unsigned int h; unsigned int t; unsigned int u; @@ -101,7 +101,7 @@ static void spinner_preset(const char *title, SpinValue *sv) { } value2htu(value, &h, &t, &u); - display_spinner(title, true, i, h, t, u, sv->unit); + display_spinner(title, true, i, h, t, u, sv.unit); M5.update(); do { @@ -118,23 +118,23 @@ static void spinner_preset(const char *title, SpinValue *sv) { value = spin_preset[n]; break; case 2: - switch (sv->unit) { + switch (sv.unit) { case SPIN_UNIT_MS: - sv->unit = SPIN_UNIT_SEC; + sv.unit = SPIN_UNIT_SEC; break; case SPIN_UNIT_SEC: - sv->unit = SPIN_UNIT_MIN; + sv.unit = SPIN_UNIT_MIN; break; case SPIN_UNIT_MIN: - sv->unit = SPIN_UNIT_MS; + sv.unit = SPIN_UNIT_MS; break; default: - sv->unit = SPIN_UNIT_NIL; + sv.unit = SPIN_UNIT_NIL; } break; } value2htu(value, &h, &t, &u); - display_spinner(title, true, i, h, t, u, sv->unit); + display_spinner(title, true, i, h, t, u, sv.unit); } if (M5.BtnB.wasClicked()) { @@ -142,18 +142,18 @@ static void spinner_preset(const char *title, SpinValue *sv) { if (i >= imax) { i = 0; } - display_spinner(title, true, i, h, t, u, sv->unit); + display_spinner(title, true, i, h, t, u, sv.unit); } ez.yield(); } while (!ok); // reconstruct the value - sv->value = htu2value(h, t, u); + sv.value = htu2value(h, t, u); } -static void spinner_custom(const char *title, SpinValue *sv) { - const unsigned int imax = sv->unit == SPIN_UNIT_NIL ? fmt_none.size() : fmt_unit.size(); +static void spinner_custom(const char *title, SpinValue &sv) { + const unsigned int imax = sv.unit == SPIN_UNIT_NIL ? fmt_none.size() : fmt_unit.size(); unsigned int i = 0; bool ok = false; @@ -161,8 +161,8 @@ static void spinner_custom(const char *title, SpinValue *sv) { unsigned int t = 0; unsigned int u = 0; - value2htu(sv->value, &h, &t, &u); - display_spinner(title, false, i, h, t, u, sv->unit); + value2htu(sv.value, &h, &t, &u); + display_spinner(title, false, i, h, t, u, sv.unit); M5.update(); do { @@ -190,22 +190,22 @@ static void spinner_custom(const char *title, SpinValue *sv) { } break; case 4: - switch (sv->unit) { + switch (sv.unit) { case SPIN_UNIT_MS: - sv->unit = SPIN_UNIT_SEC; + sv.unit = SPIN_UNIT_SEC; break; case SPIN_UNIT_SEC: - sv->unit = SPIN_UNIT_MIN; + sv.unit = SPIN_UNIT_MIN; break; case SPIN_UNIT_MIN: - sv->unit = SPIN_UNIT_MS; + sv.unit = SPIN_UNIT_MS; break; default: - sv->unit = SPIN_UNIT_NIL; + sv.unit = SPIN_UNIT_NIL; } break; } - display_spinner(title, false, i, h, t, u, sv->unit); + display_spinner(title, false, i, h, t, u, sv.unit); } if (M5.BtnB.wasClicked()) { @@ -213,7 +213,7 @@ static void spinner_custom(const char *title, SpinValue *sv) { if (i >= imax) { i = 0; } - display_spinner(title, false, i, h, t, u, sv->unit); + display_spinner(title, false, i, h, t, u, sv.unit); } ez.yield(); @@ -221,10 +221,10 @@ static void spinner_custom(const char *title, SpinValue *sv) { } while (!ok); // reconstruct the value - sv->value = htu2value(h, t, u); + sv.value = htu2value(h, t, u); } -void spinner_modify_value(const char *title, bool preset, SpinValue *sv) { +void spinner_modify_value(const char *title, bool preset, SpinValue &sv) { if (preset) { spinner_preset(title, sv); } else { @@ -232,18 +232,18 @@ void spinner_modify_value(const char *title, bool preset, SpinValue *sv) { } } -std::string sv2str(const SpinValue *sv) { - return std::to_string(sv->value) + unit2str[sv->unit]; +std::string sv2str(const SpinValue &sv) { + return std::to_string(sv.value) + unit2str[sv.unit]; } -unsigned long sv2ms(const SpinValue *sv) { - switch (sv->unit) { +unsigned long sv2ms(const SpinValue &sv) { + switch (sv.unit) { case SPIN_UNIT_MIN: - return (sv->value * 60 * 1000); + return (sv.value * 60 * 1000); case SPIN_UNIT_SEC: - return (sv->value * 1000); + return (sv.value * 1000); case SPIN_UNIT_MS: - return (sv->value); + return (sv.value); default: return 0; }