bringup
This commit is contained in:
+1
-1
Submodule platform updated: 14f18793e5...38ed7f2767
+19
-18
@@ -9,36 +9,37 @@ enum ConMode_e {
|
||||
};
|
||||
|
||||
enum IncommingCommands_e : uint16_t {
|
||||
Qurey, // Qurey info
|
||||
SetMaintanance, // Set Maintanance mode
|
||||
SetPromoMode, // Enable PromoMode
|
||||
SetGamingMode, // Enable in Game mode
|
||||
Qurey = 0x00, // Qurey info
|
||||
SetMaintanance = 0x01, // Set Maintanance mode
|
||||
SetPromoMode = 0x02, // Enable PromoMode
|
||||
SetGamingMode = 0x03, // Enable in Game mode
|
||||
};
|
||||
|
||||
enum ServiceCommands_e {
|
||||
Open,
|
||||
Close,
|
||||
Play1,
|
||||
Play2,
|
||||
Play3,
|
||||
SerQuery = 0x10,
|
||||
Open = 0x11,
|
||||
Close = 0x12,
|
||||
Play1 = 0x13,
|
||||
Play2 = 0x14,
|
||||
Play3 = 0x15,
|
||||
};
|
||||
|
||||
enum GameModeCommands_e {
|
||||
GameNextTryLocked, // Lock sword on next try
|
||||
GameNextTryRelease // Release sword on next try
|
||||
GameNextTryLocked = 0x21, // Lock sword on next try
|
||||
GameNextTryRelease = 0x22 // Release sword on next try
|
||||
};
|
||||
|
||||
enum OutgoingCommands_e {
|
||||
Status, // Send Status
|
||||
Response, // Confirm last command
|
||||
Error, // Send error status
|
||||
PullHappend // Message if User tried to pull the sword
|
||||
Status = 0x00, // Send Status
|
||||
Response = 0x01, // Confirm last command
|
||||
Error = 0x02, // Send error status
|
||||
PullHappend = 0x03 // Message if User tried to pull the sword
|
||||
};
|
||||
|
||||
enum GameModeResponses_e {
|
||||
SwordPullHappend, // Message if User tried to pull the sword
|
||||
SwordReleased, // Message that User pulled the sword
|
||||
SwordReturned // Message that User returned the sword
|
||||
SwordPullHappend = 0x11, // Message if User tried to pull the sword
|
||||
SwordReleased = 0x12, // Message that User pulled the sword
|
||||
SwordReturned = 0x13 // Message that User returned the sword
|
||||
};
|
||||
|
||||
struct StatusFrame {
|
||||
|
||||
+88
-52
@@ -167,7 +167,7 @@ void LoRaServiceTask(Thread::Context& ctx, Queue<RxMsg>& rxQueue, Queue<TxMsg>&
|
||||
rxQueue.enqueue(std::move(e));
|
||||
return true;
|
||||
};
|
||||
auto spi = SpiPort({.mode = SpiPort::mode0,
|
||||
auto spi = SpiPort({.mode = SpiPort::Mode0,
|
||||
.cs = SpiPort::Cs0,
|
||||
.frequ = 1'000'000});
|
||||
|
||||
@@ -196,16 +196,30 @@ void LoRaServiceTask(Thread::Context& ctx, Queue<RxMsg>& rxQueue, Queue<TxMsg>&
|
||||
int main(int argc, char* argv[]) {
|
||||
fmt::println("Sword Firmware");
|
||||
|
||||
if (argc > 1) {
|
||||
fmt::println("Got Startup Argument");
|
||||
auto arg1 = string{argv[1]};
|
||||
if (arg1 == "promo") {
|
||||
fmt::println("starting with promo");
|
||||
Mode = OpMode::PromoMode;
|
||||
} else if (arg1 == "game") {
|
||||
fmt::println("starting with promo");
|
||||
Mode = OpMode::PromoMode;
|
||||
} else {
|
||||
fmt::println("unknown {}", arg1);
|
||||
}
|
||||
}
|
||||
|
||||
auto itrHandler = [&]() {
|
||||
TriggeredInput itr(26, "PItr");
|
||||
while (true) {
|
||||
std::cout << "Await next interrupt\n";
|
||||
cout << "Await next interrupt\n";
|
||||
if (itr.await()) {
|
||||
std::cout << "Interrupt Event\n";
|
||||
cout << "Interrupt Event\n";
|
||||
}
|
||||
}
|
||||
};
|
||||
std::thread interruptThread(itrHandler);
|
||||
thread interruptThread(itrHandler);
|
||||
|
||||
InputPort spPort(SwordPulledPin, "PInSPull");
|
||||
InputPort sbPort(SwordEntryPin, "PinSEntry");
|
||||
@@ -227,36 +241,32 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
static Queue<RxMsg> rxQueue;
|
||||
static Queue<TxMsg> txQueue;
|
||||
static auto conTask = (ConMode == ModeMqtt) ? Thread::createExplicit("MqttTask", MQttServiceTask, std::ref(rxQueue), std::ref(txQueue))
|
||||
: Thread::createExplicit("LoRaTask", LoRaServiceTask, std::ref(rxQueue), std::ref(txQueue));
|
||||
static auto conTask = (ConMode == ModeMqtt) ? Thread::createExplicit("MqttTask", MQttServiceTask, ref(rxQueue), ref(txQueue))
|
||||
: Thread::createExplicit("LoRaTask", LoRaServiceTask, ref(rxQueue), ref(txQueue));
|
||||
|
||||
SwordLatch.moveOut();
|
||||
|
||||
const static map<IncommingCommands_e, OpMode> opCodes = {
|
||||
{SetMaintanance, OpMode::Maintanance},
|
||||
{SetPromoMode, OpMode::PromoMode},
|
||||
{SetGamingMode, OpMode::GamingMode},
|
||||
};
|
||||
|
||||
fmt::println("Running App");
|
||||
while (true) {
|
||||
auto msg = rxQueue.dequeue();
|
||||
fmt::println("MAIN: Got message {}", msg->code);
|
||||
// auto msg = rxQueue.dequeue();
|
||||
// fmt::println("MAIN: Got message {}", msg->code);
|
||||
// auto code = static_cast<IncommingCommands_e>(msg->code);
|
||||
// if (opCodes.contains(code)) {
|
||||
// Mode == opCodes.at(code);
|
||||
// } else {
|
||||
// Mode = OpMode::Undefined;
|
||||
// }
|
||||
// fmt::println("running Maintanance");
|
||||
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
// txQueue.enqueue(move(e));
|
||||
|
||||
auto code = static_cast<IncommingCommands_e>(msg->code);
|
||||
if (opCodes.contains(code)) {
|
||||
Mode == opCodes.at(code);
|
||||
} else {
|
||||
Mode = OpMode::Undefined;
|
||||
}
|
||||
while (true) {
|
||||
/* code */
|
||||
|
||||
switch (Mode) {
|
||||
case OpMode::Maintanance: {
|
||||
fmt::println("Got Maintanance");
|
||||
auto e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
fmt::println("Running Maintanance");
|
||||
// txQueue.emplace<ResponseTxMsg>(msg->code, 0);
|
||||
|
||||
while (true) {
|
||||
auto serMsg = rxQueue.tryDequeueFor(1000ms);
|
||||
if (serMsg) {
|
||||
@@ -279,44 +289,70 @@ int main(int argc, char* argv[]) {
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
auto e = std::make_unique<StatusTxMsg>(
|
||||
tick();
|
||||
auto e = make_unique<StatusTxMsg>(
|
||||
(uint8_t)Mode,
|
||||
IoStat->SwordEnd.get(),
|
||||
IoStat->SwordEntry.get(),
|
||||
IoStat->SwordPulled.get(),
|
||||
IoStat->SwordLatch.isLocked());
|
||||
txQueue.enqueue(std::move(e));
|
||||
txQueue.enqueue(move(e));
|
||||
}
|
||||
e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
// auto e = make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
// txQueue.enqueue(move(e));
|
||||
} break;
|
||||
case OpMode::PromoMode: {
|
||||
fmt::println("Got SetPromoMode");
|
||||
auto e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
|
||||
fmt::println("Running PromoMode");
|
||||
auto tn = chrono::steady_clock::now();
|
||||
while (true) {
|
||||
SwordPulled.sample();
|
||||
auto rx = txQueue.tryDequeueFor(10ms);
|
||||
auto serMsg = rxQueue.tryDequeueFor(10ms);
|
||||
if (serMsg) {
|
||||
auto code = static_cast<ServiceCommands_e>(serMsg->code);
|
||||
switch (code) {
|
||||
case ServiceCommands_e::Open: {
|
||||
IoStat->SwordLatch.moveIn();
|
||||
} break;
|
||||
case ServiceCommands_e::Close: {
|
||||
IoStat->SwordLatch.moveOut();
|
||||
} break;
|
||||
case ServiceCommands_e::Play1: {
|
||||
playWavFile(soundPromo);
|
||||
} break;
|
||||
case ServiceCommands_e::Play2: {
|
||||
playWavFile(soundDeny);
|
||||
} break;
|
||||
case ServiceCommands_e::Play3: {
|
||||
playWavFile(soundAllow);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
tick();
|
||||
if (SwordPulled.isPosEdge()) {
|
||||
// say: Play our tours
|
||||
Thread::sleep(5s);
|
||||
playWavFile(soundPromo);
|
||||
Thread::sleep(15s);
|
||||
}
|
||||
|
||||
if (chrono::steady_clock::now() > (tn + 1s)) {
|
||||
tn = chrono::steady_clock::now();
|
||||
auto e = make_unique<StatusTxMsg>(
|
||||
(uint8_t)Mode,
|
||||
IoStat->SwordEnd.get(),
|
||||
IoStat->SwordEntry.get(),
|
||||
IoStat->SwordPulled.get(),
|
||||
IoStat->SwordLatch.isLocked());
|
||||
txQueue.enqueue(move(e));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case OpMode::GamingMode: {
|
||||
fmt::println("Got SetGamingMode");
|
||||
auto e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
|
||||
fmt::println("Running GamingMode");
|
||||
while (true) {
|
||||
auto gameMsg = txQueue.dequeue();
|
||||
auto code = static_cast<GameModeCommands_e>(msg->code);
|
||||
auto gameMsg = rxQueue.dequeue();
|
||||
auto code = static_cast<GameModeCommands_e>(gameMsg->code);
|
||||
switch (code) {
|
||||
case GameModeCommands_e::GameNextTryLocked: {
|
||||
auto e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
auto e = make_unique<ResponseTxMsg>(gameMsg->code, 0);
|
||||
txQueue.enqueue(move(e));
|
||||
|
||||
fmt::println("Got NextTryLock");
|
||||
while (true) {
|
||||
@@ -330,8 +366,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
} break;
|
||||
case GameModeCommands_e::GameNextTryRelease: {
|
||||
auto e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
auto e = make_unique<ResponseTxMsg>(gameMsg->code, 0);
|
||||
txQueue.enqueue(move(e));
|
||||
SwordLatch.moveIn();
|
||||
|
||||
fmt::println("Got NextTryRelease");
|
||||
@@ -351,8 +387,8 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// say: The prophecy is fulfilled
|
||||
e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
e = make_unique<ResponseTxMsg>(gameMsg->code, 0);
|
||||
txQueue.enqueue(move(e));
|
||||
|
||||
while (true) {
|
||||
SwordEnd.sample();
|
||||
@@ -369,19 +405,19 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
e = std::make_unique<ResponseTxMsg>(msg->code, 0);
|
||||
txQueue.enqueue(std::move(e));
|
||||
e = make_unique<ResponseTxMsg>(gameMsg->code, 0);
|
||||
txQueue.enqueue(move(e));
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
interruptThread.join();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user