Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 0 additions & 4 deletions Apps/Calculator/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
file(GLOB_RECURSE SOURCE_FILES
Source/*.c*
# Library source files must be included directly,
# because all regular dependencies get stripped by elf_loader's cmake script
../../../Libraries/Str/Source/*.c**
)

idf_component_register(
SRCS ${SOURCE_FILES}
# Library headers must be included directly,
# because all regular dependencies get stripped by elf_loader's cmake script
INCLUDE_DIRS ../../../Libraries/Str/Include
INCLUDE_DIRS ../../../Libraries/TactilityCpp/Include
REQUIRES TactilitySDK
)
21 changes: 11 additions & 10 deletions Apps/Calculator/main/Source/Calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <ctype.h>
#include <tt_lvgl_toolbar.h>
#include <stack>
#include <cstring>

constexpr auto* TAG = "Calculator";

Expand Down Expand Up @@ -45,31 +46,31 @@ void Calculator::handleInput(const char* txt) {
}
}

std::deque<Str> Calculator::infixToRPN(const Str& infix) {
std::deque<std::string> Calculator::infixToRPN(const std::string& infix) {
std::stack<char> opStack;
std::deque<Str> output;
Str token;
std::deque<std::string> output;
std::string token;
size_t i = 0;

while (i < infix.length()) {
char ch = infix[i];

if (isdigit(ch)) {
token.clear();
while (i < infix.length() && (isdigit(infix[i]) || infix[i] == '.')) { token.append(infix[i++]); }
while (i < infix.length() && (isdigit(infix[i]) || infix[i] == '.')) { token += infix[i++]; }
output.push_back(token);
continue;
}

if (ch == '(') { opStack.push(ch); } else if (ch == ')') {
while (!opStack.empty() && opStack.top() != '(') {
output.push_back(Str(1, opStack.top()));
output.push_back(std::string(1, opStack.top()));
opStack.pop();
}
opStack.pop();
} else if (strchr("+-*/", ch)) {
while (!opStack.empty() && precedence(opStack.top()) >= precedence(ch)) {
output.push_back(Str(1, opStack.top()));
output.push_back(std::string(1, opStack.top()));
opStack.pop();
}
opStack.push(ch);
Expand All @@ -79,18 +80,18 @@ std::deque<Str> Calculator::infixToRPN(const Str& infix) {
}

while (!opStack.empty()) {
output.push_back(Str(1, opStack.top()));
output.push_back(std::string(1, opStack.top()));
opStack.pop();
}

return output;
}

double Calculator::evaluateRPN(std::deque<Str> rpnQueue) {
double Calculator::evaluateRPN(std::deque<std::string> rpnQueue) {
std::stack<double> values;

while (!rpnQueue.empty()) {
Str token = rpnQueue.front();
std::string token = rpnQueue.front();
rpnQueue.pop_front();

if (isdigit(token[0])) {
Expand Down Expand Up @@ -132,7 +133,7 @@ void Calculator::evaluateExpression() {
}

double Calculator::computeFormula() {
return evaluateRPN(infixToRPN(Str(formulaBuffer)));
return evaluateRPN(infixToRPN(std::string(formulaBuffer)));
}

void Calculator::resetCalculator() {
Expand Down
6 changes: 3 additions & 3 deletions Apps/Calculator/main/Source/Calculator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include <lvgl.h>
#include <deque>
#include <Str.h>
#include <string>
#include <TactilityCpp/App.h>

class Calculator final : public App {
Expand All @@ -18,8 +18,8 @@ class Calculator final : public App {
void handleInput(const char* txt);
void evaluateExpression();
double computeFormula();
static std::deque<Str> infixToRPN(const Str& infix);
static double evaluateRPN(std::deque<Str> rpnQueue);
static std::deque<std::string> infixToRPN(const std::string& infix);
static double evaluateRPN(std::deque<std::string> rpnQueue);
void resetCalculator();

public:
Expand Down
8 changes: 4 additions & 4 deletions Apps/Calculator/manifest.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[manifest]
version=0.1
[target]
sdk=0.6.0
platforms=esp32,esp32s3
sdk=0.7.0-dev
platforms=esp32,esp32s3,esp32c6,esp32p4
[app]
id=one.tactility.calculator
versionName=0.2.0
versionCode=2
versionName=0.3.0
versionCode=3
name=Calculator
105 changes: 54 additions & 51 deletions Apps/Calculator/tactility.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,20 @@
import tarfile

ttbuild_path = ".tactility"
ttbuild_version = "2.5.0"
ttbuild_version = "3.1.0"
ttbuild_cdn = "https://cdn.tactility.one"
ttbuild_sdk_json_validity = 3600 # seconds
ttport = 6666
verbose = False
use_local_sdk = False
local_base_path = None

if sys.platform == "win32":
shell_color_red = "\033[91m"
shell_color_orange = "\033[93m"
shell_color_green = "\033[32m"
shell_color_purple = "\033[35m"
shell_color_cyan = "\033[36m"
shell_color_reset = "\033[m"
else:
shell_color_red = "\033[91m"
shell_color_orange = "\033[93m"
shell_color_green = "\033[32m"
shell_color_purple = "\033[35m"
shell_color_cyan = "\033[36m"
shell_color_reset = "\033[m"
shell_color_red = "\033[91m"
shell_color_orange = "\033[93m"
shell_color_green = "\033[32m"
shell_color_purple = "\033[35m"
shell_color_cyan = "\033[36m"
shell_color_reset = "\033[m"

def print_help():
print("Usage: python tactility.py [action] [options]")
Expand Down Expand Up @@ -115,9 +107,9 @@ def read_properties_file(path):
#region SDK helpers

def read_sdk_json():
json_file_path = os.path.join(ttbuild_path, "sdk.json")
json_file = open(json_file_path)
return json.load(json_file)
json_file_path = os.path.join(ttbuild_path, "tool.json")
with open(json_file_path) as json_file:
return json.load(json_file)

def get_sdk_dir(version, platform):
global use_local_sdk, local_base_path
Expand Down Expand Up @@ -148,17 +140,17 @@ def get_sdk_root_dir(version, platform):
global ttbuild_cdn
return os.path.join(ttbuild_path, f"{version}-{platform}")

def get_sdk_url(version, platform):
def get_sdk_url(version, file):
global ttbuild_cdn
return f"{ttbuild_cdn}/TactilitySDK-{version}-{platform}.zip"
return f"{ttbuild_cdn}/sdk/{version}/{file}"

def sdk_exists(version, platform):
sdk_dir = get_sdk_dir(version, platform)
return os.path.isdir(sdk_dir)

def should_update_sdk_json():
def should_update_tool_json():
global ttbuild_cdn
json_filepath = os.path.join(ttbuild_path, "sdk.json")
json_filepath = os.path.join(ttbuild_path, "tool.json")
if os.path.exists(json_filepath):
json_modification_time = os.path.getmtime(json_filepath)
now = time.time()
Expand All @@ -168,10 +160,10 @@ def should_update_sdk_json():
else:
return True

def update_sdk_json():
def update_tool_json():
global ttbuild_cdn, ttbuild_path
json_url = f"{ttbuild_cdn}/sdk.json"
json_filepath = os.path.join(ttbuild_path, "sdk.json")
json_url = f"{ttbuild_cdn}/sdk/tool.json"
json_filepath = os.path.join(ttbuild_path, "tool.json")
return download_file(json_url, json_filepath)

def should_fetch_sdkconfig_files(platform_targets):
Expand Down Expand Up @@ -206,16 +198,6 @@ def validate_environment():
elif use_local_sdk == True and os.environ.get("TACTILITY_SDK_PATH") is None:
exit_with_error("local build was requested, but TACTILITY_SDK_PATH environment variable is not set.")

def validate_version_and_platforms(sdk_json, sdk_version, platforms_to_build):
version_map = sdk_json["versions"]
if not sdk_version in version_map:
exit_with_error(f"Version not found: {sdk_version}")
version_data = version_map[sdk_version]
available_platforms = version_data["platforms"]
for desired_platform in platforms_to_build:
if not desired_platform in available_platforms:
exit_with_error(f"Platform {desired_platform} is not available. Available ones: {available_platforms}")

def validate_self(sdk_json):
if not "toolVersion" in sdk_json:
exit_with_error("Server returned invalid SDK data format (toolVersion not found)")
Expand Down Expand Up @@ -287,15 +269,32 @@ def get_manifest_target_platforms(manifest, requested_platform):
def sdk_download(version, platform):
sdk_root_dir = get_sdk_root_dir(version, platform)
os.makedirs(sdk_root_dir, exist_ok=True)
sdk_url = get_sdk_url(version, platform)
filepath = os.path.join(sdk_root_dir, f"{version}-{platform}.zip")
sdk_index_url = get_sdk_url(version, "index.json")
print(f"Downloading SDK version {version} for {platform}")
if download_file(sdk_url, filepath):
with zipfile.ZipFile(filepath, "r") as zip_ref:
zip_ref.extractall(os.path.join(sdk_root_dir, "TactilitySDK"))
return True
else:
sdk_index_filepath = os.path.join(sdk_root_dir, "index.json")
if verbose:
print(f"Downloading {sdk_index_url} to {sdk_index_filepath}")
if not download_file(sdk_index_url, sdk_index_filepath):
# TODO: 404 check, print a more accurate error
print_error(f"Failed to download SDK version {version}. Check your internet connection and make sure this release exists.")
return False
with open(sdk_index_filepath) as sdk_index_json_file:
sdk_index_json = json.load(sdk_index_json_file)
sdk_platforms = sdk_index_json["platforms"]
if platform not in sdk_platforms:
print_error(f"Platform {platform} not found in {sdk_platforms} for version {version}")
return False
sdk_platform_file = sdk_platforms[platform]
sdk_zip_source_url = get_sdk_url(version, sdk_platform_file)
sdk_zip_target_filepath = os.path.join(sdk_root_dir, f"{version}-{platform}.zip")
if verbose:
print(f"Downloading {sdk_zip_source_url} to {sdk_zip_target_filepath}")
if not download_file(sdk_zip_source_url, sdk_zip_target_filepath):
print_error(f"Failed to download {sdk_zip_source_url} to {sdk_zip_target_filepath}")
return False
with zipfile.ZipFile(sdk_zip_target_filepath, "r") as zip_ref:
zip_ref.extractall(os.path.join(sdk_root_dir, "TactilitySDK"))
return True

def sdk_download_all(version, platforms):
for platform in platforms:
Expand Down Expand Up @@ -378,7 +377,10 @@ def build_first(version, platform, skip_build):
cmake_path = get_cmake_path(platform)
print_status_busy(f"Building {platform} ELF")
shell_needed = sys.platform == "win32"
with subprocess.Popen(["idf.py", "-B", cmake_path, "build"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
build_command = ["idf.py", "-B", cmake_path, "build"]
if verbose:
print(f"Running command: {" ".join(build_command)}")
with subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
build_output = wait_for_process(process)
# The return code is never expected to be 0 due to a bug in the elf cmake script, but we keep it just in case
if process.returncode == 0:
Expand Down Expand Up @@ -406,7 +408,10 @@ def build_consecutively(version, platform, skip_build):
cmake_path = get_cmake_path(platform)
print_status_busy(f"Building {platform} ELF")
shell_needed = sys.platform == "win32"
with subprocess.Popen(["idf.py", "-B", cmake_path, "elf"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
build_command = ["idf.py", "-B", cmake_path, "elf"]
if verbose:
print(f"Running command: {" ".join(build_command)}")
with subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
build_output = wait_for_process(process)
if process.returncode == 0:
print_status_success(f"Building {platform} ELF")
Expand Down Expand Up @@ -494,12 +499,9 @@ def build_action(manifest, platform_arg):
if not use_local_sdk:
sdk_json = read_sdk_json()
validate_self(sdk_json)
if not "versions" in sdk_json:
exit_with_error("Version data not found in sdk.json")
# Build
sdk_version = manifest["target"]["sdk"]
if not use_local_sdk:
validate_version_and_platforms(sdk_json, sdk_version, platforms_to_build)
if not sdk_download_all(sdk_version, platforms_to_build):
exit_with_error("Failed to download one or more SDKs")
if not build_all(sdk_version, platforms_to_build, skip_build): # Environment validation
Expand Down Expand Up @@ -613,7 +615,7 @@ def uninstall_action(manifest, ip):
# Argument validation
if len(sys.argv) == 1:
print_help()
sys.exit()
sys.exit(1)
if "--verbose" in sys.argv:
verbose = True
sys.argv.remove("--verbose")
Expand All @@ -633,8 +635,8 @@ def uninstall_action(manifest, ip):
manifest = read_manifest()
validate_manifest(manifest)
all_platform_targets = manifest["target"]["platforms"].split(",")
# Update SDK cache (sdk.json)
if should_update_sdk_json() and not update_sdk_json():
# Update SDK cache (tool.json)
if should_update_tool_json() and not update_tool_json():
exit_with_error("Failed to retrieve SDK info")
# Actions
if action_arg == "build":
Expand All @@ -644,7 +646,8 @@ def uninstall_action(manifest, ip):
platform = None
if len(sys.argv) > 2:
platform = sys.argv[2]
build_action(manifest, platform)
if not build_action(manifest, platform):
sys.exit(1)
elif action_arg == "clean":
clean_action()
elif action_arg == "clearcache":
Expand Down
1 change: 0 additions & 1 deletion Apps/Diceware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ set(EXTRA_COMPONENT_DIRS ${TACTILITY_SDK_PATH})

project(Diceware)
tactility_project(Diceware)

4 changes: 0 additions & 4 deletions Apps/Diceware/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
file(GLOB_RECURSE SOURCE_FILES
Source/*.c*
# Library source files must be included directly,
# because all regular dependencies get stripped by elf_loader's cmake script
../../../Libraries/Str/Source/*.c**
)

idf_component_register(
SRCS ${SOURCE_FILES}
# Library headers must be included directly,
# because all regular dependencies get stripped by elf_loader's cmake script
INCLUDE_DIRS ../../../Libraries/Str/Include
INCLUDE_DIRS ../../../Libraries/TactilityCpp/Include
REQUIRES TactilitySDK
)
Expand Down
Loading