Skip to content

Commit

Permalink
85 disable connect and delete saved if there are no connections (#87)
Browse files Browse the repository at this point in the history
* Disable 'Connect' and 'Delete Saved' if there are no connections.

Also, fix a bug with deleting down to zero connections by removing the
preference entry.

* Fix README
  • Loading branch information
gkoh authored Mar 14, 2024
1 parent 988d1b3 commit 89e2cf9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ More details are on the wiki: [PlatformIO](https://github.com/gkoh/furble/wiki/L
## Usage

The top level menu has the following entries:
- `Connect`
- `Connect` (if there are saved connections)
- `Scan`
- `Delete Saved`
- `Delete Saved` (if there are saved connections)
- `Settings`
- `Power Off`

Expand Down
14 changes: 13 additions & 1 deletion lib/furble/CameraList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ typedef struct {
} index_entry_t;

static void save_index(std::vector<index_entry_t> &index) {
m_Prefs.putBytes(FURBLE_PREF_INDEX, index.data(), sizeof(index[0]) * index.size());
if (index.size() > 0) {
m_Prefs.putBytes(FURBLE_PREF_INDEX, index.data(), sizeof(index[0]) * index.size());
} else {
m_Prefs.remove(FURBLE_PREF_INDEX);
}
}

static std::vector<index_entry_t> load_index(void) {
Expand Down Expand Up @@ -149,6 +153,14 @@ void CameraList::load(void) {
m_Prefs.end();
}

size_t CameraList::getSaveCount(void) {
m_Prefs.begin(FURBLE_STR, false);
auto index = load_index();
m_Prefs.end();

return index.size();
}

void CameraList::match(NimBLEAdvertisedDevice *pDevice) {
if (Fujifilm::matches(pDevice)) {
m_ConnectList.push_back(new Furble::Fujifilm(pDevice));
Expand Down
5 changes: 5 additions & 0 deletions lib/furble/CameraList.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class CameraList {
*/
static void load(void);

/**
* Get number of saved connections.
*/
static size_t getSaveCount(void);

/**
* Add matching devices to the list.
*/
Expand Down
15 changes: 12 additions & 3 deletions src/furble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,22 @@ void setup() {
}

void loop() {
size_t save_count = Furble::CameraList::getSaveCount();

ezMenu mainmenu(FURBLE_STR);
mainmenu.buttons("OK#down");
mainmenu.addItem("Connect", do_saved);
if (save_count > 0) {
mainmenu.addItem("Connect", do_saved);
}
mainmenu.addItem("Scan", do_scan);
mainmenu.addItem("Delete Saved", menu_delete);
if (save_count > 0) {
mainmenu.addItem("Delete Saved", menu_delete);
}
mainmenu.addItem("Settings", menu_settings);
mainmenu.addItem("Power Off", mainmenu_poweroff);
mainmenu.downOnLast("first");
mainmenu.run();

do {
mainmenu.runOnce();
} while (Furble::CameraList::getSaveCount() == save_count);
}

0 comments on commit 89e2cf9

Please sign in to comment.