starting from GPIO and OS Example

This commit is contained in:
2026-06-25 17:03:45 +02:00
parent 55b7909717
commit 26c12b7e80
7 changed files with 209 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
build/
.cache/
+3
View File
@@ -0,0 +1,3 @@
[submodule "platform"]
path = platform
url = git@github.com:Gustice/RPiLnxPlatform.git
+13
View File
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.10)
project(SwordProp C CXX)
include(platform/tools/project.cmake)
ProjectSetup()
PlatformRequirements()
add_subdirectory(platform/extern)
add_subdirectory(src)
addSubDirs_ofRoot("${CMAKE_CURRENT_LIST_DIR}/platform/modules")
core_addSubDirs_inAbsPath("${CMAKE_CURRENT_LIST_DIR}/platform/palCore/modules")
Submodule
+1
Submodule platform added at 92c57ba83f
+12
View File
@@ -0,0 +1,12 @@
add_executable(SwordMain swordMain.cpp)
target_link_libraries(SwordMain
PkgConfig::LIBGPIOD
base
palAdapt
loRa
os
Mqtt
fmt::fmt
utils
)
+149
View File
@@ -0,0 +1,149 @@
#include "swordMain.hpp"
using namespace pal;
using namespace std::literals::string_view_literals;
using namespace std::literals::chrono_literals;
// using namespace std::literals;
constexpr int OutPin = 23;
enum IncommingCommands_e {
Qurey, // Qurey info
Disable, // Disable Station
Maintanance, // Set Maintanance mode
SetPromoMode, // Enable PromoMode
SetGamingMode, // Enable in Game mode
NextTryLock, // Lock sword on next try
NextTryRelease // Release sword on next try
};
enum OutgoingCommands_e {
Version, // Send Version
Status, // Send Status
TryHappend, // Message if User tried to pull the sword
SwordReleased, // Message that User pulled the sword
SwordReturned // Message that User returned the sword
};
/// @brief incomming / outgoing message codes
struct TxMsg {
TxMsg(std::uint32_t m)
: message(m) {};
uint32_t message;
};
// struct RsrsCtx {
// std::string name;
// Mutex& mtx;
// decltype(std::chrono::steady_clock::duration()) duration;
// };
/// @brief MQTT-Service provider
// void LoRaServiceTask(Thread::Context& ctx, Queue<TxMsg>& queue) {
void MQttServiceTask(Thread::Context& ctx) {
printf("MQTT service: Starting\n");
// uint32_t cnt{};
while (!ctx.isCancelled()) {
Thread::sleep(2s);
// blinkSem.give();
// auto e = std::make_unique<TxMsg>(cnt++, "tick");
// queue.enqueue(std::move(e));
std::cout << "MQTT service: Running ...\n";
}
}
/// @brief LoRa-Service provider
// void LoRaServiceTask(Thread::Context& ctx, Queue<TxMsg>& queue) {
void LoRaServiceTask(Thread::Context& ctx) {
printf("LoRa service: Starting\n");
// uint32_t cnt{};
while (!ctx.isCancelled()) {
Thread::sleep(2s);
// blinkSem.give();
// auto e = std::make_unique<TxMsg>(cnt++, "tick");
// queue.enqueue(std::move(e));
std::cout << "LoRa service: Running ...\n";
}
// while (!ctx.isCancelled()) {
// auto msg = queue.dequeue(); // Wait with infinit timeout, guaranteed to succeed
// printf("Message: %s %lu\n", msg->message.c_str(), msg->cnt);
// }
// while (!ctx.isCancelled()) {
// blinkSem.take();
// led.write(true); // execute blink event
// Thread::sleep(100ms);
// led.write(false); // execute blink event
// printf("Blink tick\n");
// }
}
// void RessourceAccessor(Thread::Context& tCtx, RsrsCtx& ctx) {
// using namespace std::chrono;
// fmt::println("starting Ressource Accessor {}", ctx.name);
// while (!tCtx.isCancelled()) {
// {
// StopWatch sw;
// ctx.mtx.claim();
// auto e = duration_cast<milliseconds>(sw.getEleapsed());
// auto d = duration_cast<milliseconds>(ctx.duration);
// fmt::println("took {}ms to quire, now access ressource for {}ms",
// (int)e.count(), (int)d.count());
// Thread::sleep(ctx.duration);
// ctx.mtx.release();
// }
// Thread::sleep(100ms);
// }
// }
void itrHandler() {
TriggeredInput itr(26, "PItr");
while (true) {
std::cout << "Await next interrupt\n";
if (itr.await()) {
std::cout << "Interrupt Event\n";
}
}
}
int main(int argc, char* argv[]) {
printf("Sword Firmware\n");
OutputPort out(OutPin, "POut");
InputPort in(20, "PIn");
std::cout << "setting GPIO21 as Out and GPIO20 as input: ";
std::thread interruptThread(itrHandler);
// Semaphore blinkSem;
auto mqttTask = Thread::createExplicit("MqttTask", MQttServiceTask);
auto loraTask = Thread::createExplicit("LoRaTask", LoRaServiceTask);
// static Queue<TxMsg> txQueue;
// auto mqttTask = Thread::createExplicit("MqttTask", MQttServiceTask, std::ref(txQueue));
// auto loraTask = Thread::createExplicit("LoRaTask", LoRaServiceTask, std::ref(txQueue));
// Mutex rsrMtx;
// RsrsCtx rsCtx1{
// .name = "intense",
// .mtx = rsrMtx,
// .duration = 3000ms};
// RsrsCtx rsCtx2{
// .name = "light",
// .mtx = rsrMtx,
// .duration = 1000ms};
// auto ressourceAccess1 = Thread::createExplicit("IntenseAccess", RessourceAccessor, std::ref(rsCtx1));
// auto ressourceAccess2 = Thread::createExplicit("LightAccess", RessourceAccessor, std::ref(rsCtx2));
fmt::print("Running App\n");
while (true) {
std::cout << "in=" << in.read() << "\n";
out.write(0);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::cout << "in=" << in.read() << "\n";
out.write(1);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
// std::this_thread::sleep_for(1s);
}
interruptThread.join();
return EXIT_SUCCESS;
}
+29
View File
@@ -0,0 +1,29 @@
#pragma once
#include <fcntl.h>
#include <fmt/core.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
#include <unistd.h>
#include <chrono>
#include <cinttypes>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <vector>
#include "MqttClient.hpp"
#include "coreExcept.hpp"
#include "gpioPort.hpp"
#include "loRa.hpp"
#include "mutex.hpp"
#include "queue.hpp"
#include "semaphore.hpp"
#include "spiPort.hpp"
#include "textUtils.hpp"
#include "thread.hpp"