8 changed files with 117 additions and 18 deletions
-
4.settings/language.settings.xml
-
2app_protocols
-
2stm32basic
-
10ucomponents/zcan/zcan.cpp
-
5ucomponents/zcan/zcan.hpp
-
13usrc/service/app_core.cpp
-
62usrc/service/valve_state_ctrl_service.cpp
-
37usrc/service/valve_state_ctrl_service.hpp
@ -1 +1 @@ |
|||
Subproject commit 94d89e0e6d4a76e4eb434557974187e73dced518 |
|||
Subproject commit 38674eceb0655cfa98679886e95bd1e4f9dfc89d |
@ -1 +1 @@ |
|||
Subproject commit a3f7743a964044334b57b0ca786b69f76f6e4af6 |
|||
Subproject commit b2fbccdc9ddd701095912425f8f6f3eaaa47166a |
@ -0,0 +1,62 @@ |
|||
#include "valve_state_ctrl_service.hpp"
|
|||
|
|||
#include "app_protocols\app_protocols.h"
|
|||
|
|||
using namespace iflytop; |
|||
#define TAG "ValveStateSyncService"
|
|||
void ValveStateSyncService::initialize(ZCAN1* can) { |
|||
m_thread.init("ValveStateSyncService-Thread"); |
|||
this->can = can; |
|||
ZCAN1::ins()->init(); |
|||
lock.init(); |
|||
} |
|||
|
|||
void ValveStateSyncService::startSync() { |
|||
m_thread.start([this]() { |
|||
while (true) { |
|||
m_thread.sleep(300); |
|||
{ |
|||
zlock_guard l(lock); |
|||
|
|||
valve_ctrl_msg_t msg = {0}; |
|||
msg.output0 = output0state; |
|||
msg.output1 = output1state; |
|||
msg.rgbw = rgbwstate; |
|||
ZCAN1::ins()->txMsg(kvalve_ctrl_msg, (uint8_t*)&msg, sizeof(msg), 30); |
|||
} |
|||
} |
|||
}); |
|||
} |
|||
|
|||
void ValveStateSyncService::setValveState(int valveIndex, bool state) { |
|||
zlock_guard l(lock); |
|||
|
|||
if (valveIndex >= 4) { |
|||
ZLOGW(TAG, "valveIndex %d out of range", valveIndex); |
|||
return; |
|||
} |
|||
output0state = (output0state & ~(1 << valveIndex)) | (state << valveIndex); |
|||
forceupdate = true; |
|||
m_thread.wake(); |
|||
} |
|||
|
|||
#define SETBIT(byte, off, valve) (byte = (byte & ~(1 << off)) | (valve << off))
|
|||
|
|||
void ValveStateSyncService::setRGBState(bool r, bool g, bool b) { |
|||
zlock_guard l(lock); |
|||
// bit0:r
|
|||
// bit1:g
|
|||
// bit2:b
|
|||
SETBIT(rgbwstate, 0, r); |
|||
SETBIT(rgbwstate, 1, g); |
|||
SETBIT(rgbwstate, 2, b); |
|||
forceupdate = true; |
|||
m_thread.wake(); |
|||
} |
|||
void ValveStateSyncService::setWarningState(bool warning) { |
|||
zlock_guard l(lock); |
|||
|
|||
SETBIT(rgbwstate, 3, warning); |
|||
forceupdate = true; |
|||
m_thread.wake(); |
|||
} |
@ -0,0 +1,37 @@ |
|||
#pragma once
|
|||
|
|||
#include "apphardware/apphardware.hpp"
|
|||
#include "uappbase/base.hpp"
|
|||
#include "ucomponents/zcan/zcan.hpp"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class ValveStateSyncService { |
|||
private: |
|||
/* data */ |
|||
ZThread m_thread; |
|||
ZCAN1* can; |
|||
|
|||
uint8_t output0state = 0; |
|||
uint8_t output1state = 0; |
|||
uint8_t rgbwstate = 0; |
|||
|
|||
bool forceupdate = false; |
|||
zmutex lock = {"ValveStateSyncServiceLock"}; |
|||
|
|||
public: |
|||
static ValveStateSyncService* ins() { |
|||
static ValveStateSyncService instance; |
|||
return &instance; |
|||
} |
|||
|
|||
void initialize(ZCAN1* can); |
|||
void startSync(); |
|||
|
|||
void setValveState(int valveIndex, bool state); |
|||
void setRGBState(bool r, bool g, bool b); |
|||
void setWarningState(bool warning); |
|||
|
|||
public: |
|||
}; |
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue