Skip to content

Commit

Permalink
Explicitly initialize everything on ZrFunctionConstructor
Browse files Browse the repository at this point in the history
Plus gate some functions on network/XR being available.
  • Loading branch information
zorzella committed Nov 29, 2019
1 parent 53f402c commit fa72b16
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/ZrComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ IPAddress &xrIp() { return m_xrIp; };
* Return true if a message was there to be received, false otherwise.
*/
void receiveOscIfAny(OSCMessage &msg) {
if (!ZrComm::instance().isConnectedToNetwork()) {
return;
}
int size = wifiUdp.parsePacket();

if (size == 0) {
Expand Down
18 changes: 13 additions & 5 deletions src/ZrFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
ZrFunction::ZrFunction()
: m_hPos{-1},
m_vPos{-1},
m_typeDesc{},
m_oscAddr{UNKNOWN_OSC_ADDR},
m_humanChannelName{"??"},
m_humanCustomName{""} {}
m_humanCustomName{""},
m_lastUpdated{0},
m_lastSentUpdateRequest{0},
m_cachedValue{} {}

void plus(OSCMessage& outParam, OSCMessage& source) { outParam = source; }

Expand Down Expand Up @@ -47,12 +51,16 @@ const bool ZrFunction::lastCacheUpdateRequestIsOld() const {

bool ZrFunction::triggerCacheUpdate() { return send1(m_oscAddr); }

bool ZrFunction::triggerCacheUpdateIfNeeded() {
void ZrFunction::triggerCacheUpdateIfNeeded() {
if (!ZrComm::instance().isConnectedToNetwork()) {
return;
}
if (cacheIsStale() && lastCacheUpdateRequestIsOld()) {
m_lastSentUpdateRequest = millis();
return send1(m_oscAddr);
TRACE();
if (send1(m_oscAddr)) {
m_lastSentUpdateRequest = millis();
}
}
return true;
}

void ZrFunction::clickChange(const double humanNotch) {
Expand Down
2 changes: 1 addition & 1 deletion src/ZrFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ZrFunction {
void clickMinus();
void updateCachedValue(OSCMessage& msg);
bool triggerCacheUpdate();
bool triggerCacheUpdateIfNeeded();
void triggerCacheUpdateIfNeeded();

private:
friend class ZrNavigation;
Expand Down
18 changes: 13 additions & 5 deletions src/ZrNavigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ std::map<std::string, ZrFunction*> m_oscAddrToFunctionMap;

int m_currentPageIndex;

const int index() {
return m_currentPage.index();
}
const int index() { return m_currentPage.index(); }

/*
Expand Down Expand Up @@ -103,9 +101,19 @@ void ZrNavigation::goDown() { m_currentPage.goDown(); }

void ZrNavigation::goUp() { m_currentPage.goUp(); }

void ZrNavigation::clickPlus() { currentFunction().clickPlus(); }
void ZrNavigation::clickPlus() {
if (!ZrComm::instance().isConnectedToXr()) {
return;
}
currentFunction().clickPlus();
}

void ZrNavigation::clickMinus() { currentFunction().clickMinus(); }
void ZrNavigation::clickMinus() {
if (!ZrComm::instance().isConnectedToXr()) {
return;
}
currentFunction().clickMinus();
}

const int ZrNavigation::getCurrentPageIndex() const {
return m_currentPageIndex;
Expand Down

0 comments on commit fa72b16

Please sign in to comment.