TactilityC additions (#287)
New TactilityC implementations for: - WiFi - GPS - Preferences - Timezone Also includes: - Some fixes to enums/naming - Cleanup elsewhere
This commit is contained in:
committed by
GitHub
parent
869a56125f
commit
1593eb80ce
@@ -10,9 +10,9 @@ BundleHandle _Nullable tt_app_get_parameters(AppHandle handle) {
|
||||
return (BundleHandle)HANDLE_AS_APP_CONTEXT(handle)->getParameters().get();
|
||||
}
|
||||
|
||||
void tt_app_set_result(AppHandle handle, Result result, BundleHandle _Nullable bundle) {
|
||||
auto shared_bundle = std::unique_ptr<tt::Bundle>((tt::Bundle*)bundle);
|
||||
HANDLE_AS_APP_CONTEXT(handle)->getApp()->setResult((tt::app::Result)result, std::move(shared_bundle));
|
||||
void tt_app_set_result(AppHandle handle, AppResult result, BundleHandle _Nullable bundle) {
|
||||
auto shared_bundle = std::unique_ptr<tt::Bundle>(static_cast<tt::Bundle*>(bundle));
|
||||
HANDLE_AS_APP_CONTEXT(handle)->getApp()->setResult(static_cast<tt::app::Result>(result), std::move(shared_bundle));
|
||||
}
|
||||
|
||||
bool tt_app_has_result(AppHandle handle) {
|
||||
@@ -24,7 +24,7 @@ void tt_app_start(const char* appId) {
|
||||
}
|
||||
|
||||
void tt_app_start_with_bundle(const char* appId, BundleHandle parameters) {
|
||||
tt::app::start(appId, std::shared_ptr<tt::Bundle>((tt::Bundle*)parameters));
|
||||
tt::app::start(appId, std::shared_ptr<tt::Bundle>(static_cast<tt::Bundle*>(parameters)));
|
||||
}
|
||||
|
||||
void tt_app_stop() {
|
||||
|
||||
@@ -23,17 +23,19 @@ bool tt_bundle_opt_int32(BundleHandle handle, const char* key, int32_t* out) {
|
||||
}
|
||||
bool tt_bundle_opt_string(BundleHandle handle, const char* key, char* out, uint32_t outSize) {
|
||||
std::string out_string;
|
||||
if (HANDLE_AS_BUNDLE(handle)->optString(key, out_string)) {
|
||||
if (out_string.length() < outSize) { // Need 1 byte to add 0 at the end
|
||||
memcpy(out, out_string.c_str(), out_string.length());
|
||||
out[out_string.length()] = 0x00;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (!HANDLE_AS_BUNDLE(handle)->optString(key, out_string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (out_string.length() >= outSize) {
|
||||
// Need 1 byte to add 0 at the end
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(out, out_string.c_str(), out_string.length());
|
||||
out[out_string.length()] = 0x00;
|
||||
return true;
|
||||
}
|
||||
|
||||
void tt_bundle_put_bool(BundleHandle handle, const char* key, bool value) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "tt_gps.h"
|
||||
#include <Tactility/service/gps/GpsService.h>
|
||||
|
||||
using namespace tt::service;
|
||||
|
||||
extern "C" {
|
||||
|
||||
bool tt_gps_has_coordinates() {
|
||||
auto service = gps::findGpsService();
|
||||
return service != nullptr && service->hasCoordinates();
|
||||
}
|
||||
|
||||
bool tt_gps_get_coordinates(
|
||||
float* longitude,
|
||||
float* latitude,
|
||||
float* speed,
|
||||
float* course,
|
||||
int* day,
|
||||
int* month,
|
||||
int* year
|
||||
) {
|
||||
auto service = gps::findGpsService();
|
||||
|
||||
if (service == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
minmea_sentence_rmc rmc;
|
||||
|
||||
if (!service->getCoordinates(rmc)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
*longitude = minmea_tocoord(&rmc.longitude);
|
||||
*latitude = minmea_tocoord(&rmc.latitude);
|
||||
*speed = minmea_tocoord(&rmc.speed);
|
||||
*course = minmea_tocoord(&rmc.course);
|
||||
*day = rmc.date.day;
|
||||
*month = rmc.date.month;
|
||||
*year = rmc.date.year;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,15 +5,19 @@
|
||||
#include "tt_app_manifest.h"
|
||||
#include "tt_app_selectiondialog.h"
|
||||
#include "tt_bundle.h"
|
||||
#include "tt_gps.h"
|
||||
#include "tt_hal_i2c.h"
|
||||
#include "tt_lvgl_keyboard.h"
|
||||
#include "tt_lvgl_spinner.h"
|
||||
#include "tt_lvgl_toolbar.h"
|
||||
#include "tt_message_queue.h"
|
||||
#include "tt_mutex.h"
|
||||
#include "tt_preferences.h"
|
||||
#include "tt_semaphore.h"
|
||||
#include "tt_thread.h"
|
||||
#include "tt_time.h"
|
||||
#include "tt_timer.h"
|
||||
#include "tt_wifi.h"
|
||||
|
||||
#include <private/elf_symbol.h>
|
||||
|
||||
@@ -39,6 +43,8 @@ const struct esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_put_bool),
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_put_int32),
|
||||
ESP_ELFSYM_EXPORT(tt_bundle_put_string),
|
||||
ESP_ELFSYM_EXPORT(tt_gps_has_coordinates),
|
||||
ESP_ELFSYM_EXPORT(tt_gps_get_coordinates),
|
||||
ESP_ELFSYM_EXPORT(tt_hal_i2c_start),
|
||||
ESP_ELFSYM_EXPORT(tt_hal_i2c_stop),
|
||||
ESP_ELFSYM_EXPORT(tt_hal_i2c_is_started),
|
||||
@@ -72,6 +78,14 @@ const struct esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(tt_mutex_free),
|
||||
ESP_ELFSYM_EXPORT(tt_mutex_lock),
|
||||
ESP_ELFSYM_EXPORT(tt_mutex_unlock),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_alloc),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_free),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_opt_bool),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_opt_int32),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_opt_string),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_put_bool),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_put_int32),
|
||||
ESP_ELFSYM_EXPORT(tt_preferences_put_string),
|
||||
ESP_ELFSYM_EXPORT(tt_semaphore_alloc),
|
||||
ESP_ELFSYM_EXPORT(tt_semaphore_free),
|
||||
ESP_ELFSYM_EXPORT(tt_semaphore_acquire),
|
||||
@@ -99,6 +113,21 @@ const struct esp_elfsym elf_symbols[] {
|
||||
ESP_ELFSYM_EXPORT(tt_timer_get_expire_time),
|
||||
ESP_ELFSYM_EXPORT(tt_timer_set_pending_callback),
|
||||
ESP_ELFSYM_EXPORT(tt_timer_set_thread_priority),
|
||||
ESP_ELFSYM_EXPORT(tt_timezone_set),
|
||||
ESP_ELFSYM_EXPORT(tt_timezone_get_name),
|
||||
ESP_ELFSYM_EXPORT(tt_timezone_get_code),
|
||||
ESP_ELFSYM_EXPORT(tt_timezone_is_format_24_hour),
|
||||
ESP_ELFSYM_EXPORT(tt_timezone_set_format_24_hour),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_get_radio_state),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_radio_state_to_string),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_scan),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_is_scanning),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_get_connection_target),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_set_enabled),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_connect),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_disconnect),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_is_connnection_secure),
|
||||
ESP_ELFSYM_EXPORT(tt_wifi_get_rssi),
|
||||
// tt::lvgl
|
||||
ESP_ELFSYM_EXPORT(tt_lvgl_spinner_create),
|
||||
// lv_event
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "tt_preferences.h"
|
||||
#include <Tactility/Preferences.h>
|
||||
#include <cstring>
|
||||
|
||||
#define HANDLE_AS_PREFERENCES(handle) ((tt::Preferences*)(handle))
|
||||
|
||||
extern "C" {
|
||||
|
||||
PreferencesHandle tt_preferences_alloc(const char* identifier) {
|
||||
return new tt::Preferences(identifier);
|
||||
}
|
||||
|
||||
void tt_preferences_free(PreferencesHandle handle) {
|
||||
delete HANDLE_AS_PREFERENCES(handle);
|
||||
}
|
||||
|
||||
bool tt_preferences_opt_bool(PreferencesHandle handle, const char* key, bool* out) {
|
||||
return HANDLE_AS_PREFERENCES(handle)->optBool(key, *out);
|
||||
}
|
||||
|
||||
bool tt_preferences_opt_int32(PreferencesHandle handle, const char* key, int32_t* out) {
|
||||
return HANDLE_AS_PREFERENCES(handle)->optInt32(key, *out);
|
||||
}
|
||||
bool tt_preferences_opt_string(PreferencesHandle handle, const char* key, char* out, uint32_t outSize) {
|
||||
std::string out_string;
|
||||
|
||||
if (!HANDLE_AS_PREFERENCES(handle)->optString(key, out_string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (out_string.length() >= outSize) {
|
||||
// Need 1 byte to add 0 at the end
|
||||
return false;
|
||||
}
|
||||
|
||||
memcpy(out, out_string.c_str(), out_string.length());
|
||||
out[out_string.length()] = 0x00;
|
||||
return true;
|
||||
}
|
||||
|
||||
void tt_preferences_put_bool(PreferencesHandle handle, const char* key, bool value) {
|
||||
HANDLE_AS_PREFERENCES(handle)->putBool(key, value);
|
||||
}
|
||||
|
||||
void tt_preferences_put_int32(PreferencesHandle handle, const char* key, int32_t value) {
|
||||
HANDLE_AS_PREFERENCES(handle)->putInt32(key, value);
|
||||
}
|
||||
|
||||
void tt_preferences_put_string(PreferencesHandle handle, const char* key, const char* value) {
|
||||
HANDLE_AS_PREFERENCES(handle)->putString(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "tt_time.h"
|
||||
|
||||
#include <Tactility/time/Time.h>
|
||||
#include <cstring>
|
||||
|
||||
using namespace tt;
|
||||
|
||||
extern "C" {
|
||||
|
||||
void tt_timezone_set(const char* name, const char* code) {
|
||||
time::setTimeZone(name, code);
|
||||
}
|
||||
|
||||
bool tt_timezone_get_name(char* buffer, size_t bufferSize) {
|
||||
auto name = time::getTimeZoneName();
|
||||
if (bufferSize < (name.length() + 1)) {
|
||||
return false;
|
||||
} else {
|
||||
strcpy(buffer, name.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool tt_timezone_get_code(char* buffer, size_t bufferSize) {
|
||||
auto code = time::getTimeZoneCode();
|
||||
if (bufferSize < (code.length() + 1)) {
|
||||
return false;
|
||||
} else {
|
||||
strcpy(buffer, code.c_str());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool tt_timezone_is_format_24_hour() {
|
||||
return time::isTimeFormat24Hour();
|
||||
}
|
||||
|
||||
void tt_timezone_set_format_24_hour(bool show24Hour) {
|
||||
return time::setTimeFormat24Hour(show24Hour);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,7 +7,6 @@ struct TimerWrapper {
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
TimerHandle tt_timer_alloc(TimerType type, TimerCallback callback, void* callbackContext) {
|
||||
auto wrapper = std::make_shared<TimerWrapper>();
|
||||
wrapper->timer = std::make_unique<tt::Timer>((tt::Timer::Type)type, [callback, callbackContext](){ callback(callbackContext); });
|
||||
@@ -54,4 +53,3 @@ void tt_timer_set_thread_priority(TimerHandle handle, ThreadPriority priority) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#include "tt_wifi.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <Tactility/service/wifi/Wifi.h>
|
||||
#include <Tactility/service/wifi/WifiSettings.h>
|
||||
|
||||
using namespace tt::service;
|
||||
|
||||
extern "C" {
|
||||
|
||||
WifiRadioState tt_wifi_get_radio_state() {
|
||||
return static_cast<WifiRadioState>(wifi::getRadioState());
|
||||
}
|
||||
const char* tt_wifi_radio_state_to_string(WifiRadioState state) {
|
||||
return wifi::radioStateToString(static_cast<wifi::RadioState>(state));
|
||||
}
|
||||
|
||||
void tt_wifi_scan() {
|
||||
wifi::scan();
|
||||
}
|
||||
|
||||
bool tt_wifi_is_scanning() {
|
||||
return wifi::isScanning();
|
||||
}
|
||||
|
||||
void tt_wifi_get_connection_target(char* buffer) {
|
||||
auto target = wifi::getConnectionTarget();
|
||||
strcpy(buffer, target.c_str());
|
||||
}
|
||||
|
||||
void tt_wifi_set_enabled(bool enabled) {
|
||||
wifi::setEnabled(enabled);
|
||||
}
|
||||
|
||||
void tt_wifi_connect(const char* ssid, const char* password, int32_t channel, bool autoConnect, bool remember) {
|
||||
wifi::settings::WifiApSettings settings;
|
||||
strcpy(settings.ssid, ssid);
|
||||
strcpy(settings.password, password);
|
||||
settings.channel = channel;
|
||||
settings.auto_connect = autoConnect;
|
||||
}
|
||||
|
||||
void tt_wifi_disconnect() {
|
||||
wifi::disconnect();
|
||||
}
|
||||
|
||||
bool tt_wifi_is_connnection_secure() {
|
||||
return wifi::isConnectionSecure();
|
||||
}
|
||||
|
||||
int tt_wifi_get_rssi() {
|
||||
return wifi::getRssi();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user