From 42698214bf8a900abe552f381b02ed41cfb92e7c Mon Sep 17 00:00:00 2001 From: Asami De Almeida Date: Tue, 3 Jun 2025 15:10:51 +1200 Subject: [PATCH 1/4] Started Adding a StenoByte Writer This is a separate executable for writing to a file --- CMakeLists.txt | 10 +++++-- includes/StenoByte_Core.c | 31 +++++++++++++++++++++ includes/StenoByte_Core.h | 5 ++++ includes/StenoByte_Helper_for_Linux.c | 3 +-- main.c => src/stenobyte_demo.c | 4 +-- src/stenobyte_writer.c | 39 +++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 6 deletions(-) rename main.c => src/stenobyte_demo.c (90%) create mode 100644 src/stenobyte_writer.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bb79bc..0c4be64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.30) project(StenoByte_Prototype C) +project(StenoByte_Writer C) set(CMAKE_C_STANDARD 23) @@ -38,6 +39,11 @@ else () endif () # Main App -add_executable(StenoByte_Prototype main.c) +add_executable(StenoByte_Prototype src/stenobyte_demo.c) target_include_directories(StenoByte_Prototype PRIVATE ${LIBEVDEV_INCLUDE_DIRS} StenoByte_Library) -target_link_libraries(StenoByte_Prototype PRIVATE ${LIBEVDEV_LIBRARIES} StenoByte_Library) \ No newline at end of file +target_link_libraries(StenoByte_Prototype PRIVATE ${LIBEVDEV_LIBRARIES} StenoByte_Library) + +# Writer App +add_executable(StenoByte_Writer src/stenobyte_writer.c) +target_include_directories(StenoByte_Writer PRIVATE ${LIBEVDEV_INCLUDE_DIRS} StenoByte_Library) +target_link_libraries(StenoByte_Writer PRIVATE ${LIBEVDEV_LIBRARIES} StenoByte_Library) \ No newline at end of file diff --git a/includes/StenoByte_Core.c b/includes/StenoByte_Core.c index dd60e6d..7bb2115 100644 --- a/includes/StenoByte_Core.c +++ b/includes/StenoByte_Core.c @@ -29,12 +29,35 @@ bool bit_arr[BITS_ARR_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0}; // ordered from b0 to b7 char keys_arr[BITS_ARR_SIZE] = {';', 'L', 'K', 'J', 'F', 'D', 'S', 'A'}; // ';' = b0, 'L' = b1, ... 'A' = b7 u_int8_t subvalues_arr[BITS_ARR_SIZE]; bool ready_to_compute_byte = false; // the state for whether to convert the bit array into a byte and process it +const char* output_file_path; // The path to the file write to +FILE *output_file_ptr; // The pointer of the file itself to write to u_int8_t current_byte = 0x00; // The byte last computed from the bit array // Methods & Functions +int setup_stenobyte_demo() { + printf("Starting StenoType...\n"); + return setup_stenobyte(); +} + +int setup_stenobyte_writer(int argc, const char* argv[]) { + if (argc < 2) { + // Default File Path if none is provided + output_file_path = "./output.txt"; + } else { + // File Path Provided by Command Line Arguments + output_file_path = argv[1]; + } + + printf("Welcome to StenoByte Writer.\nWriting to file: %s\n", output_file_path); + + output_file_ptr = fopen(output_file_path, "w"); + + return setup_stenobyte(); +} + /* * Generates the Byte based on the bits in the array */ @@ -115,4 +138,12 @@ void print_bit_arr_summary() { "Press ESC to exit\n"); // Prints 53 chars printf("%s", msg); +} + +/* + * Closes the File and frees up memory safely + */ +void end_stenobyte_writer() { + fclose(output_file_ptr); + end_stenobyte(); } \ No newline at end of file diff --git a/includes/StenoByte_Core.h b/includes/StenoByte_Core.h index 650faf2..c3abcf4 100644 --- a/includes/StenoByte_Core.h +++ b/includes/StenoByte_Core.h @@ -34,6 +34,8 @@ extern char keys_arr[BITS_ARR_SIZE]; // ';' = b0, 'L' = b1, ... 'A' = b7 extern u_int8_t subvalues_arr[BITS_ARR_SIZE]; extern bool ready_to_compute_byte; // the state for whether to convert the bit array into a byte and process it extern u_int8_t current_byte; // The byte last computed from the bit array +extern const char* output_file_path; // The path to the file write to +extern FILE *output_file_ptr; // The pointer of the file itself to write to // Externally Declared Methods & Functions (expected to be declared & defined StenoByte_Helper files) @@ -43,10 +45,13 @@ extern void run_stenobyte(); extern void end_stenobyte(); // Methods & Functions +int setup_stenobyte_demo(); +int setup_stenobyte_writer(int argc, const char* argv[]); void compute_byte(); void setup_subvalues_array(); void get_byte_summary(char* msg); void print_byte_summary(); void print_bit_arr_summary(); +void end_stenobyte_writer(); #endif //STENOBYTE_CORE_H diff --git a/includes/StenoByte_Helper_for_Linux.c b/includes/StenoByte_Helper_for_Linux.c index 281fe3a..e3bf41b 100644 --- a/includes/StenoByte_Helper_for_Linux.c +++ b/includes/StenoByte_Helper_for_Linux.c @@ -35,8 +35,6 @@ const int event_file_device; * Returns 0 if there were no errors, 1 if there were errors */ int setup_stenobyte() { - printf("Starting StenoType...\n"); - setup_subvalues_array(); const int event_file_device = open("/dev/input/event3", O_RDONLY | O_NONBLOCK); // Change to the correct device @@ -135,6 +133,7 @@ void run_stenobyte() { process_key_presses(¤t_event); print_bit_arr_summary(); + // TODO: Handle if in writer mode and to write to file if it is if (ready_to_compute_byte) { compute_byte(); diff --git a/main.c b/src/stenobyte_demo.c similarity index 90% rename from main.c rename to src/stenobyte_demo.c index 953185e..be276f3 100644 --- a/main.c +++ b/src/stenobyte_demo.c @@ -16,12 +16,12 @@ limitations under the License. */ -#include "includes/StenoByte_Core.h" +#include "../includes/StenoByte_Core.h" int main() { // Performs setup; exits app if there was an error while setting up - const int setup_result = setup_stenobyte(); + const int setup_result = setup_stenobyte_demo(); if (setup_result != 0) { return setup_result; } diff --git a/src/stenobyte_writer.c b/src/stenobyte_writer.c new file mode 100644 index 0000000..11db921 --- /dev/null +++ b/src/stenobyte_writer.c @@ -0,0 +1,39 @@ +/** +StenoByte: a stenotype inspired keyboard app for typing out bytes. + + Copyright 2025 Asami De Almeida + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include "../includes/StenoByte_Core.h" + + +int main(int argc, const char* argv[]) { + + // fprintf(output_file_ptr, "Some Text 123!\n"); + + // Performs setup; exits app if there was an error while setting up + const int setup_result = setup_stenobyte_writer(argc, argv); + if (setup_result != 0) { + return setup_result; + } + + // Runs the loop + run_stenobyte(); + + // Frees up Memory Safely & Closes the File + end_stenobyte_writer(); + + return 0; +} From 66f807af635a2221c0d3d851aeff87ba9657b57a Mon Sep 17 00:00:00 2001 From: Asami De Almeida Date: Mon, 9 Jun 2025 15:10:39 +1200 Subject: [PATCH 2/4] Added a handler for different modes --- includes/StenoByte_Core.c | 51 +++++++++++++++++++++++++-- includes/StenoByte_Core.h | 11 ++++++ includes/StenoByte_Helper.h | 2 ++ includes/StenoByte_Helper_for_Linux.c | 3 +- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/includes/StenoByte_Core.c b/includes/StenoByte_Core.c index 7bb2115..346f4d9 100644 --- a/includes/StenoByte_Core.c +++ b/includes/StenoByte_Core.c @@ -31,6 +31,7 @@ u_int8_t subvalues_arr[BITS_ARR_SIZE]; bool ready_to_compute_byte = false; // the state for whether to convert the bit array into a byte and process it const char* output_file_path; // The path to the file write to FILE *output_file_ptr; // The pointer of the file itself to write to +enum stenobyte_mode mode = NOT_SET; u_int8_t current_byte = 0x00; // The byte last computed from the bit array @@ -39,6 +40,7 @@ u_int8_t current_byte = 0x00; // The byte last computed from the bit array int setup_stenobyte_demo() { printf("Starting StenoType...\n"); + mode = DEMO; return setup_stenobyte(); } @@ -52,12 +54,27 @@ int setup_stenobyte_writer(int argc, const char* argv[]) { } printf("Welcome to StenoByte Writer.\nWriting to file: %s\n", output_file_path); - output_file_ptr = fopen(output_file_path, "w"); - + mode = WRITER; return setup_stenobyte(); } +void action() { + // TODO: this could probably be done once during setup by setting a pointer to the function to run as the action + switch (mode) { + case DEMO: + print_bit_arr_summary(); + break; + case WRITER: + print_bit_arr_summary(); + write_byte_to_file(); + break; + default: + perror("No StenoByte Mode Set"); + exit(EXIT_FAILURE); + } +} + /* * Generates the Byte based on the bits in the array */ @@ -97,13 +114,37 @@ void print_byte_summary() { printf("%s", msg); } +void print_current_mode(char* msg) { + // Min Chars Printed: 11 + // Max Chars Printed: 19 + sprintf(msg+strlen(msg), "Mode: "); // Prints 6 chars + + switch (mode) { + case DEMO: + sprintf(msg+strlen(msg), "DEMO"); // Prints 4 chars + break; + case WRITER: + sprintf(msg+strlen(msg), "WRITER"); // Prints 6 chars + break; + case NOT_SET: + sprintf(msg+strlen(msg), "NOT_SET"); // Prints 7 chars + break; + default: + sprintf(msg+strlen(msg), "UNKNOWN MODE"); // Prints 12 chars + break; + } + + sprintf(msg+strlen(msg), "\n"); // Prints 1 char +} + /* * Prints the current state of the Bit Array * TODO: The repeated for loops could probably be simplified into a dedicated method */ void print_bit_arr_summary() { - char msg[654] = ""; + char msg[673] = ""; + print_current_mode(msg); // Prints between 11 and 19 chars sprintf(msg + strlen(msg), "\nBits in Array:\n"); // Prints 16 chars sprintf(msg + strlen(msg), "\tBit Value:\t| "); // Prints 14 chars for (int i = 7; i >= 0; i--) { // Repeats 8 times @@ -140,6 +181,10 @@ void print_bit_arr_summary() { printf("%s", msg); } +void write_byte_to_file() { + printf("This is where the writing will happen...\n"); +} + /* * Closes the File and frees up memory safely */ diff --git a/includes/StenoByte_Core.h b/includes/StenoByte_Core.h index c3abcf4..0c3e5a0 100644 --- a/includes/StenoByte_Core.h +++ b/includes/StenoByte_Core.h @@ -24,6 +24,12 @@ #include "StenoByte_Helper.h" +enum stenobyte_mode { + NOT_SET = 0, + DEMO, + WRITER +}; + // Number of Bits in the Bit Array (should be 8) # define BITS_ARR_SIZE 8 @@ -36,6 +42,8 @@ extern bool ready_to_compute_byte; // the state for whether to convert the bit extern u_int8_t current_byte; // The byte last computed from the bit array extern const char* output_file_path; // The path to the file write to extern FILE *output_file_ptr; // The pointer of the file itself to write to +extern enum stenobyte_mode mode; // What mode is the program currently in + // Externally Declared Methods & Functions (expected to be declared & defined StenoByte_Helper files) @@ -47,11 +55,14 @@ extern void end_stenobyte(); // Methods & Functions int setup_stenobyte_demo(); int setup_stenobyte_writer(int argc, const char* argv[]); +void action(); void compute_byte(); void setup_subvalues_array(); void get_byte_summary(char* msg); void print_byte_summary(); +void print_current_mode(char* msg); void print_bit_arr_summary(); +void write_byte_to_file(); void end_stenobyte_writer(); #endif //STENOBYTE_CORE_H diff --git a/includes/StenoByte_Helper.h b/includes/StenoByte_Helper.h index aa3fa5d..c383eea 100644 --- a/includes/StenoByte_Helper.h +++ b/includes/StenoByte_Helper.h @@ -32,6 +32,7 @@ #include #include #include +#include // Key Press States #define EV_KEY_RELEASED 0 @@ -47,6 +48,7 @@ extern const int event_file_device; // Externally Declared Methods & Functions // (expected to be declared & defined in dependent libraries or in StenoByte_Core files) extern void setup_subvalues_array(); // StenoByte_Core.h/c +extern void action(); // Run the core action in the loop extern void compute_byte(); extern void print_bit_arr_summary(); extern void update_bit_arr(int key_code, bool new_state); diff --git a/includes/StenoByte_Helper_for_Linux.c b/includes/StenoByte_Helper_for_Linux.c index e3bf41b..a32348a 100644 --- a/includes/StenoByte_Helper_for_Linux.c +++ b/includes/StenoByte_Helper_for_Linux.c @@ -132,8 +132,7 @@ void run_stenobyte() { } process_key_presses(¤t_event); - print_bit_arr_summary(); - // TODO: Handle if in writer mode and to write to file if it is + action(); if (ready_to_compute_byte) { compute_byte(); From 0300b86c179cc297a2822772c3d983600d302fd5 Mon Sep 17 00:00:00 2001 From: Asami De Almeida Date: Mon, 9 Jun 2025 15:48:49 +1200 Subject: [PATCH 3/4] Byte Writer now works, removed action function --- includes/StenoByte_Core.c | 18 +----------------- includes/StenoByte_Core.h | 1 - includes/StenoByte_Helper.h | 1 - includes/StenoByte_Helper_for_Linux.c | 7 +++++-- 4 files changed, 6 insertions(+), 21 deletions(-) diff --git a/includes/StenoByte_Core.c b/includes/StenoByte_Core.c index 346f4d9..7843f56 100644 --- a/includes/StenoByte_Core.c +++ b/includes/StenoByte_Core.c @@ -59,22 +59,6 @@ int setup_stenobyte_writer(int argc, const char* argv[]) { return setup_stenobyte(); } -void action() { - // TODO: this could probably be done once during setup by setting a pointer to the function to run as the action - switch (mode) { - case DEMO: - print_bit_arr_summary(); - break; - case WRITER: - print_bit_arr_summary(); - write_byte_to_file(); - break; - default: - perror("No StenoByte Mode Set"); - exit(EXIT_FAILURE); - } -} - /* * Generates the Byte based on the bits in the array */ @@ -182,7 +166,7 @@ void print_bit_arr_summary() { } void write_byte_to_file() { - printf("This is where the writing will happen...\n"); + fprintf(output_file_ptr, "%c", (char) current_byte); } /* diff --git a/includes/StenoByte_Core.h b/includes/StenoByte_Core.h index 0c3e5a0..d7e6323 100644 --- a/includes/StenoByte_Core.h +++ b/includes/StenoByte_Core.h @@ -55,7 +55,6 @@ extern void end_stenobyte(); // Methods & Functions int setup_stenobyte_demo(); int setup_stenobyte_writer(int argc, const char* argv[]); -void action(); void compute_byte(); void setup_subvalues_array(); void get_byte_summary(char* msg); diff --git a/includes/StenoByte_Helper.h b/includes/StenoByte_Helper.h index c383eea..c8bea9a 100644 --- a/includes/StenoByte_Helper.h +++ b/includes/StenoByte_Helper.h @@ -48,7 +48,6 @@ extern const int event_file_device; // Externally Declared Methods & Functions // (expected to be declared & defined in dependent libraries or in StenoByte_Core files) extern void setup_subvalues_array(); // StenoByte_Core.h/c -extern void action(); // Run the core action in the loop extern void compute_byte(); extern void print_bit_arr_summary(); extern void update_bit_arr(int key_code, bool new_state); diff --git a/includes/StenoByte_Helper_for_Linux.c b/includes/StenoByte_Helper_for_Linux.c index a32348a..e586cb0 100644 --- a/includes/StenoByte_Helper_for_Linux.c +++ b/includes/StenoByte_Helper_for_Linux.c @@ -132,10 +132,13 @@ void run_stenobyte() { } process_key_presses(¤t_event); - action(); + print_bit_arr_summary(); if (ready_to_compute_byte) { compute_byte(); + if (mode == WRITER) { + write_byte_to_file(); + } } usleep(1000); // Small delay @@ -213,7 +216,7 @@ void process_key_presses(const struct input_event* current_event) { return; } - // Exits method if key even is not a key press or key repeat + // Exits method if key event is not a key press or key repeat if (current_event->value != EV_KEY_PRESSED && current_event->value != EV_KEY_REPEATED) { return; } From 6d8163b468abf22ecb8f96164ddd2ffbb208bf55 Mon Sep 17 00:00:00 2001 From: Asami De Almeida Date: Sun, 15 Jun 2025 19:04:28 +1200 Subject: [PATCH 4/4] Removing Compilation with Clang --- .github/workflows/cmake-multi-platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 884b71f..82eb136 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -30,7 +30,7 @@ jobs: # os: [ubuntu-latest, windows-latest] os: [ubuntu-latest] build_type: [Release] - c_compiler: [gcc, clang, cl] + c_compiler: [gcc, cl] include: # - os: windows-latest # c_compiler: cl