Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "src/libs/littlefs"]
path = src/libs/littlefs
url = https://github.com/littlefs-project/littlefs.git
[submodule "src/libs/QR-Code-generator"]
path = src/libs/QR-Code-generator
url = https://github.com/nayuki/QR-Code-generator
25 changes: 23 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ set(LVGL_SRC
libs/lvgl/src/lv_widgets/lv_win.c
)

set(QRCODE_SRC
libs/QR-Code-generator/c/qrcodegen.c
libs/QR-Code-generator/c/qrcodegen.h
)

list(APPEND IMAGE_FILES
displayapp/icons/battery/os_battery_error.c
displayapp/icons/battery/os_battery_100.c
Expand Down Expand Up @@ -414,6 +419,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/ApplicationList.cpp
displayapp/screens/Notifications.cpp
displayapp/screens/Twos.cpp
displayapp/screens/Qr.cpp
displayapp/screens/HeartRate.cpp
displayapp/screens/Motion.cpp
displayapp/screens/FlashLight.cpp
Expand Down Expand Up @@ -476,6 +482,7 @@ list(APPEND SOURCE_FILES
components/ble/BatteryInformationService.cpp
components/ble/ImmediateAlertService.cpp
components/ble/ServiceDiscovery.cpp
components/ble/QrService.cpp
components/ble/HeartRateService.cpp
components/ble/MotionService.cpp
components/firmwarevalidator/FirmwareValidator.cpp
Expand Down Expand Up @@ -548,6 +555,7 @@ list(APPEND RECOVERY_SOURCE_FILES
components/ble/NavigationService.cpp
components/ble/HeartRateService.cpp
components/ble/MotionService.cpp
components/ble/QrService.cpp
components/firmwarevalidator/FirmwareValidator.cpp
components/settings/Settings.cpp
components/timer/TimerController.cpp
Expand Down Expand Up @@ -660,6 +668,7 @@ set(INCLUDE_FILES
components/settings/Settings.h
components/timer/TimerController.h
components/alarm/AlarmController.h
components/ble/QrService.h
drivers/Cst816s.h
FreeRTOS/portmacro.h
FreeRTOS/portmacro_cmsis.h
Expand Down Expand Up @@ -847,13 +856,25 @@ target_compile_options(littlefs PRIVATE
$<$<COMPILE_LANGUAGE:ASM>: -MP -MD -x assembler-with-cpp>
)

# qrcode
add_library(qrcode STATIC ${QRCODE_SRC})
target_include_directories(qrcode SYSTEM PUBLIC . ../)
target_include_directories(qrcode SYSTEM PUBLIC ${INCLUDES_FROM_LIBS})
target_compile_options(qrcode PRIVATE
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -O0 -g3>
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -O3>
$<$<COMPILE_LANGUAGE:ASM>: -MP -MD -std=c99 -x assembler-with-cpp>
)

# Build autonomous binary (without support for bootloader)
set(EXECUTABLE_NAME "pinetime-app")
set(EXECUTABLE_FILE_NAME ${EXECUTABLE_NAME}-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH})
set(NRF5_LINKER_SCRIPT "${CMAKE_SOURCE_DIR}/gcc_nrf52.ld")
add_executable(${EXECUTABLE_NAME} ${SOURCE_FILES})
set_target_properties(${EXECUTABLE_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_FILE_NAME})
target_link_libraries(${EXECUTABLE_NAME} nimble nrf-sdk lvgl littlefs)
target_link_libraries(${EXECUTABLE_NAME} nimble nrf-sdk lvgl littlefs qrcode)
target_compile_options(${EXECUTABLE_NAME} PUBLIC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -Og -g3>
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:RELEASE>>: ${COMMON_FLAGS} -Os>
Expand Down Expand Up @@ -882,7 +903,7 @@ set(IMAGE_MCUBOOT_FILE_NAME ${EXECUTABLE_MCUBOOT_NAME}-image-${pinetime_VERSION_
set(DFU_MCUBOOT_FILE_NAME ${EXECUTABLE_MCUBOOT_NAME}-dfu-${pinetime_VERSION_MAJOR}.${pinetime_VERSION_MINOR}.${pinetime_VERSION_PATCH}.zip)
set(NRF5_LINKER_SCRIPT_MCUBOOT "${CMAKE_SOURCE_DIR}/gcc_nrf52-mcuboot.ld")
add_executable(${EXECUTABLE_MCUBOOT_NAME} ${SOURCE_FILES})
target_link_libraries(${EXECUTABLE_MCUBOOT_NAME} nimble nrf-sdk lvgl littlefs)
target_link_libraries(${EXECUTABLE_MCUBOOT_NAME} nimble nrf-sdk lvgl littlefs qrcode)
set_target_properties(${EXECUTABLE_MCUBOOT_NAME} PROPERTIES OUTPUT_NAME ${EXECUTABLE_MCUBOOT_FILE_NAME})
target_compile_options(${EXECUTABLE_MCUBOOT_NAME} PUBLIC
$<$<AND:$<COMPILE_LANGUAGE:C>,$<CONFIG:DEBUG>>: ${COMMON_FLAGS} -Og -g3>
Expand Down
4 changes: 3 additions & 1 deletion src/components/ble/NimbleController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ NimbleController::NimbleController(Pinetime::System::SystemTask& systemTask,
navService {systemTask},
batteryInformationService {batteryController},
immediateAlertService {systemTask, notificationManager},
qrService(systemTask),
heartRateService {systemTask, heartRateController},
motionService{systemTask, motionController},
motionService {systemTask, motionController},
serviceDiscovery({&currentTimeClient, &alertNotificationClient}) {
}

Expand Down Expand Up @@ -82,6 +83,7 @@ void NimbleController::Init() {
dfuService.Init();
batteryInformationService.Init();
immediateAlertService.Init();
qrService.Init();
heartRateService.Init();
motionService.Init();

Expand Down
5 changes: 5 additions & 0 deletions src/components/ble/NimbleController.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "DfuService.h"
#include "ImmediateAlertService.h"
#include "MusicService.h"
#include "QrService.h"
#include "NavigationService.h"
#include "ServiceDiscovery.h"
#include "HeartRateService.h"
Expand Down Expand Up @@ -70,6 +71,9 @@ namespace Pinetime {
Pinetime::Controllers::AlertNotificationService& alertService() {
return anService;
};
Pinetime::Controllers::QrService& qr() {
return qrService;
};

uint16_t connHandle();
void NotifyBatteryLevel(uint8_t level);
Expand All @@ -96,6 +100,7 @@ namespace Pinetime {
NavigationService navService;
BatteryInformationService batteryInformationService;
ImmediateAlertService immediateAlertService;
QrService qrService;
HeartRateService heartRateService;
MotionService motionService;

Expand Down
85 changes: 85 additions & 0 deletions src/components/ble/QrService.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "QrService.h"
#include "systemtask/SystemTask.h"

using namespace Pinetime::Controllers;

namespace {
// 0004yyxx-78fc-48fe-8e23-433b3a1942d0
constexpr ble_uuid128_t CharUuid(uint8_t x, uint8_t y) {
return ble_uuid128_t {.u = {.type = BLE_UUID_TYPE_128},
.value = {0xd0, 0x42, 0x19, 0x3a, 0x3b, 0x43, 0x23, 0x8e, 0xfe, 0x48, 0xfc, 0x78, x, y, 0x04, 0x00}};
}

// 00040000-78fc-48fe-8e23-433b3a1942d0
constexpr ble_uuid128_t BaseUuid() {
return CharUuid(0x00, 0x00);
}

constexpr ble_uuid128_t qrServiceUuid {BaseUuid()};
constexpr ble_uuid128_t qrCharUuid {CharUuid(0x01, 0x00)};

int QrCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
auto qrService = static_cast<QrService*>(arg);
return qrService->OnCommand(conn_handle, attr_handle, ctxt);
}
}

QrService::QrService(Pinetime::System::SystemTask& system)
: system {system},
characteristicDefinition {
{.uuid = &qrCharUuid.u, .access_cb = QrCallback, .arg = this, .flags = BLE_GATT_CHR_F_WRITE | BLE_GATT_CHR_F_READ}, {0}},
serviceDefinition {
{.type = BLE_GATT_SVC_TYPE_PRIMARY, .uuid = &qrServiceUuid.u, .characteristics = characteristicDefinition},
{0},
} {
qrList[0].name = "Github";
qrList[0].text = "https://github.com/InfiniTimeOrg/InfiniTime";
qrList[1].name = "Twitter";
qrList[1].text = "https://twitter.com/codingfield";
qrList[2].name = "Mastodon";
qrList[2].text = "https://mastodon.codingfield.com/@JF";
qrList[3].name = "Donate!";
qrList[3].text = "https://liberapay.com/JF002";
}

void QrService::Init() {
int res = 0;
res = ble_gatts_count_cfg(serviceDefinition);
ASSERT(res == 0);

res = ble_gatts_add_svcs(serviceDefinition);
ASSERT(res == 0);
}

int QrService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
uint8_t data[notifSize + 1];
data[notifSize] = '\0';
os_mbuf_copydata(ctxt->om, 0, notifSize, data);
char* s = (char*) &data[0];
NRF_LOG_INFO("DATA : %s", s);

const char* d = "|";
const char* qrId = strtok(s, d);
const char* qrName = strtok(NULL, d);
const char* qrText = strtok(NULL, d);

if (ble_uuid_cmp(ctxt->chr->uuid, (ble_uuid_t*) &qrCharUuid) == 0) {
if (qrId != NULL) {
if (atoi(qrId) == 0 || qrName == NULL || qrText == NULL) {
qrList[0].name = "Wrong format";
qrList[0].text = qrId;
} else if (atoi(qrId) > 0 && atoi(qrId) < MAXLISTITEMS + 1) {
qrList[atoi(qrId) - 1].name = qrName;
qrList[atoi(qrId) - 1].text = qrText;
}
}
}
}
return 0;
}

std::array<QrService::QrInfo, 4> QrService::getQrList() {
return qrList;
}
47 changes: 47 additions & 0 deletions src/components/ble/QrService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include <cstdint>
#include <string>
#include <array>
#define min // workaround: nimble's min/max macros conflict with libstdc++
#define max
#include <host/ble_gap.h>
#include <host/ble_uuid.h>
#undef max
#undef min

#define MAXLISTITEMS 4

namespace Pinetime {
namespace System {
class SystemTask;
}
namespace Controllers {
class QrService {
public:
struct QrInfo {
std::string name;
std::string text;
bool operator==(const QrInfo& rhs) const {
return (rhs.name == name && rhs.text == text);
}
};

explicit QrService(Pinetime::System::SystemTask& system);

void Init();

int OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt);

std::array<QrInfo, 4> getQrList();

private:
Pinetime::System::SystemTask& system;

struct ble_gatt_chr_def characteristicDefinition[2];
struct ble_gatt_svc_def serviceDefinition[2];

std::array<QrInfo, 4> qrList;
};
}
}
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Pinetime {
Metronome,
Motion,
Steps,
Qr,
QuickSettings,
Settings,
SettingWatchFace,
Expand Down
5 changes: 4 additions & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "displayapp/screens/BatteryInfo.h"
#include "displayapp/screens/Steps.h"
#include "displayapp/screens/Error.h"

#include "displayapp/screens/Qr.h"
#include "drivers/Cst816s.h"
#include "drivers/St7789.h"
#include "drivers/Watchdog.h"
Expand Down Expand Up @@ -448,6 +448,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Steps:
currentScreen = std::make_unique<Screens::Steps>(this, motionController, settingsController);
break;
case Apps::Qr:
currentScreen = std::make_unique<Screens::Qr>(this, lvgl, systemTask->nimble().qr());
break;
}
currentApp = app;
}
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/screens/ApplicationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
{Symbols::paddle, Apps::Paddle},
{"2", Apps::Twos},
{Symbols::chartLine, Apps::Motion},
{Symbols::drum, Apps::Metronome},
{Symbols::qrcode, Apps::Qr},
{Symbols::clock, Apps::Alarm},
}};

Expand Down
Loading