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
2 changes: 1 addition & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 3.30)
project(StenoByte_Prototype C)
project(StenoByte_Writer C)

set(CMAKE_C_STANDARD 23)

Expand Down Expand Up @@ -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)
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)
62 changes: 61 additions & 1 deletion includes/StenoByte_Core.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,36 @@ 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
enum stenobyte_mode mode = NOT_SET;

u_int8_t current_byte = 0x00; // The byte last computed from the bit array


// Methods & Functions

int setup_stenobyte_demo() {
printf("Starting StenoType...\n");
mode = DEMO;
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");
mode = WRITER;
return setup_stenobyte();
}

/*
* Generates the Byte based on the bits in the array
*/
Expand Down Expand Up @@ -74,13 +98,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
Expand Down Expand Up @@ -115,4 +163,16 @@ void print_bit_arr_summary() {
"Press ESC to exit\n"); // Prints 53 chars

printf("%s", msg);
}

void write_byte_to_file() {
fprintf(output_file_ptr, "%c", (char) current_byte);
}

/*
* Closes the File and frees up memory safely
*/
void end_stenobyte_writer() {
fclose(output_file_ptr);
end_stenobyte();
}
15 changes: 15 additions & 0 deletions includes/StenoByte_Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -34,6 +40,10 @@ 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
extern enum stenobyte_mode mode; // What mode is the program currently in



// Externally Declared Methods & Functions (expected to be declared & defined StenoByte_Helper files)
Expand All @@ -43,10 +53,15 @@ 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_current_mode(char* msg);
void print_bit_arr_summary();
void write_byte_to_file();
void end_stenobyte_writer();

#endif //STENOBYTE_CORE_H
1 change: 1 addition & 0 deletions includes/StenoByte_Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>

// Key Press States
#define EV_KEY_RELEASED 0
Expand Down
7 changes: 4 additions & 3 deletions includes/StenoByte_Helper_for_Linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,6 +136,9 @@ void run_stenobyte() {

if (ready_to_compute_byte) {
compute_byte();
if (mode == WRITER) {
write_byte_to_file();
}
}

usleep(1000); // Small delay
Expand Down Expand Up @@ -215,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;
}
Expand Down
4 changes: 2 additions & 2 deletions main.c → src/stenobyte_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
39 changes: 39 additions & 0 deletions src/stenobyte_writer.c
Original file line number Diff line number Diff line change
@@ -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;
}
Loading