Skip to content

Docs for devs

Virus Rpi edited this page Dec 12, 2023 · 23 revisions

Docs for devs

Tip: use table of contents at the right to skip to sections Disclaimer: If the headline is italic the section is AI generated

Create new window

  1. Create new class that inherits from Window

1.1. Create the methods update_window() that returns Bitarray2D

1.2. Create method handle_key_down(KeyPress keypress)

  1. Add a new MenuOption to MainMenuWindow.cpp and change size of options vector
  2. Implement all the functions you need

Tipps

  • To get screen size you can do #include "constant/Constants.h" and then use SCREEN_HEIGHT and SCREEN_WIDTH
  • To get time since boot do #include "utils/Utils.h" and then use Utils::us_since_boot()
  • To check for a key press use keypress.key_calculator == Chars::KEY_MAP.at("1") (you can also use keypress.key_raw or keypress.key_keyboard)
  • To check if alpha or shift is activated use keypress.alpha or keypress.shift

Docs for Classes (WIP)

Bitset2D

You can create a Bitset2D with the following methods:

  • Bitset2D() for dynamic size and a starting size of 0, 0
  • Bitset2D(uint32_t width, uint32_t height, bool value) to initialize with a specific size and a default value
  • Bitset2D(uint32_t width, const DynamicBitset& other) to initialize with a width. The height and values are copied from the dynamic bit set
  • Bitset2D(uint32_t width, uint32_t height, const std::vector<std::vector<uint8_t>>& plane) same as above but height also specific
  • Bitset2D(const Bitset2D& other) copies the bit set passed in (height, width, values)

Methods:

  • .at(uint32_t index) to get the value at an index in the dynamic bit set
  • .width() to get the width of the bit set
  • .height() to get the height of the bit set
  • .get_bit(uint32_t coord_x, uint32_t coord_y) to get the bit at a specific x and y coordinate
  • .copy(uint32_t x_start, uint32_t y_start, uint32_t width, uint32_t height, Bitset2D& destination) copies a section of a bit set into another
  • .put_chars(uint32_t coord_x, uint32_t coord_y, const std::map<KEY, Bitset2D>& font, KEY_SET text, bool resize_if_needed) to but a character on a specific coordinate with the option to extend the bit set if needed
  • .set(uint32_t coord_x, uint32_t coord_y, const Bitset2D& other, bool resize_if_needed) inserts a bit set into another at a coordinate with the option to extend the bit set if needed
  • .set_column(uint32_t coord_x, const DynamicBitset& other) replaces a column in the bit set with a dynamic bit set
  • .set_bit(uint32_t coord_x, uint32_t coord_y, bool value) to set a value of one pixel at a coordinate
  • .erase_x(uint32_t coord_x) to remove a column at a specific x coordinate
  • .erase_y(uint32_t coord_y) to remove a row at a specific y coordinate
  • .pop_back_x() to remove the last column in the bit set
  • .clear() to clear the bit set
  • .push_back(const DynamicBitset& other) to add a dynamic bit set to the end of the bit set
  • .push_front(const DynamicBitset& other) to add a dynamic bit set to the beginning of the bit set
  • .extend_right(const Bitset2D& other) to extend the bit set to the right with another bit set
  • .extend_right(uint32_t length, bool value) to extend the bit set to the right with a specific length and value
  • .extend_down(const Bitset2D& other) to extend the bit set downwards with another bit set
  • .extend_down(uint32_t length, bool value) to extend the bit set downwards with a specific length and value
  • .extend_left(const Bitset2D& other) to extend the bit set to the left with another bit set
  • .extend_left(uint32_t length, bool value) to extend the bit set to the left with a specific length and value
  • .extend_up(const Bitset2D& other) to extend the bit set upwards with another bit set
  • .extend_up(uint32_t length, bool value) to extend the bit set upwards with a specific length and value
  • .to_string() to convert the bit set to a string
  • .to_string_formatted() to convert the bit set to a formatted string

Behavior with operators:

  • Bitset2D::operator[](uint32_t index) to get the dynamic bit set at an index in the 2D bit set
  • Bitset2D::operator==(const Bitset2D& other) to check if two 2D bit sets are equal
  • Bitset2D::operator!=(const Bitset2D& other) to check if two 2D bit sets are not equal
  • Bitset2D::operator=(const Bitset2D& other) to assign one 2D bit set to another
  • Bitset2D::operator+(const Bitset2D& other) to concatenate two 2D bit sets

DynamicBitset

You can create a DynamicBitset with the following methods:

  • DynamicBitset() for dynamic size and a starting size of 0
  • DynamicBitset(uint32_t count, bool value) to initialize with a specific size and a default value
  • DynamicBitset(uint32_t count, std::vector<uint8_t> values) to initialize with a specific size and values from a vector of bytes
  • DynamicBitset(uint32_t count, std::vector<bool> values) to initialize with a specific size and values from a vector of booleans
  • DynamicBitset(const DynamicBitset& other) copies the bit set passed in (size, values)

Methods:

  • .at(uint32_t index) to get the value at an index in the dynamic bit set
  • .size() to get the size of the bit set
  • .get_bytes() to get the bytes of the bit set
  • .copy(uint32_t start, uint32_t width) copies a section of a bit set
  • .set(uint32_t index, bool value) to set a value of one bit at an index
  • .set(uint32_t index, const DynamicBitset& other) inserts a bit set into another at an index
  • .insert(uint32_t index, bool bit) to insert a bit at a specific index
  • .insert(uint32_t index, const DynamicBitset& bits) to insert a bit set at a specific index
  • .erase(uint32_t index) to remove a bit at a specific index
  • .clear() to clear the bit set
  • .push_back(bool bit) to add a bit to the end of the bit set
  • .push_front(bool bit) to add a bit to the beginning of the bit set
  • .pop_back() to remove the last bit in the bit set
  • .pop_front() to remove the first bit in the bit set
  • .extend(const DynamicBitset& other) to extend the bit set with another bit set
  • .extend(uint32_t length, bool value) to extend the bit set with a specific length and value
  • .extend_left(const DynamicBitset& other) to extend the bit set to the left with another bit set
  • .extend_left(uint32_t length, bool value) to extend the bit set to the left with a specific length and value
  • .to_string() to convert the bit set to a string
  • .to_string_formatted(uint32_t bytes_per_line) to convert the bit set to a formatted string

Behavior with operators:

  • DynamicBitset::operator[](uint32_t i) to get the bit at an index in the dynamic bit set
  • DynamicBitset::operator==(const DynamicBitset& other) to check if two dynamic bit sets are equal
  • DynamicBitset::operator!=(const DynamicBitset& other) to check if two dynamic bit sets are not equal
  • DynamicBitset::operator=(const DynamicBitset& other) to assign one dynamic bit set to another
  • DynamicBitset::operator+(const DynamicBitset& other) to concatenate two dynamic bit sets

Window

The Window class is used to manage the window of the application. It provides methods to update the window, get the render canvas, add graphics to the window, clear the window, clear symbols, change symbols, scroll left and right, and handle key down and up events.

You can create a Window with the following methods:

  • Window() to initialize the window

Methods:

  • .update_window() to update the window and return the render canvas
  • .get_render_canvas() to get the render canvas of the window
  • .add_to_window(const Bitset2D& graphic, int corner_x, int corner_y) to add a graphic to the window at a specific corner
  • .clear_window() to clear the window
  • .clear_symbols() to clear the symbols
  • .change_symbol(std::string symbol, bool state) to change the state of a symbol
  • .scroll_left() to scroll the window to the left
  • .scroll_right() to scroll the window to the right
  • .handle_key_down(KeyPress keypress) to handle the key down event
  • .handle_key_up(KeyPress keypress) to handle the key up event
  • .got_focus() to handle the event when the window got focus
  • .lost_focus() to handle the event when the window lost focus

Decimal

The Decimal class is used to represent decimal numbers with a high precision. It provides methods for creating decimals, comparing them, and performing arithmetic operations.

You can create a Decimal with the following methods:

  • Decimal() to initialize the decimal with a value of 0
  • Decimal(double value) to initialize the decimal with a specific double value
  • Decimal(int64_t value, int16_t exp) to initialize the decimal with a specific integer value and exponent

Methods:

  • .sign() to get the sign of the decimal (returns 1 for positive, -1 for negative, and 0 for zero)
  • .normalize() to normalize the decimal (removes trailing zeros and adjusts the exponent)
  • .shift_comma(int8_t shift) to shift the decimal point by a specific amount
  • .change_accuracy(int8_t shift) to change the accuracy of the decimal by shifting the decimal point

Behavior with operators:

  • Decimal::operator==(const Decimal& other) to check if two decimals are equal
  • Decimal::operator!=(const Decimal& other) to check if two decimals are not equal
  • Decimal::operator<(const Decimal& other) to check if one decimal is less than another
  • Decimal::operator>(const Decimal& other) to check if one decimal is greater than another
  • Decimal::operator<=(const Decimal& other) to check if one decimal is less than or equal to another
  • Decimal::operator>=(const Decimal& other) to check if one decimal is greater than or equal to another
  • Decimal::operator-() to negate the decimal
  • Decimal::operator=(const Decimal& other) to assign one decimal to another
  • Decimal::operator+(const Decimal& other) to add two decimals

Graphics

You can create a Graphics with:

  • Graphics()

Methods:

  • Graphics::create_text(const std::string& text, FONT& table, const uint16_t spacing) to create a Bitset2D text from string
  • Graphics::create_text(const KEY_SET text, FONT& table, const uint16_t spacing) to create a Bitset2D text from a set of keys

Constants:

  • Graphics::EMPTY_SCREEN to represent an empty screen
  • Graphics::LOGO_SCREEN to represent a logo screen
  • Graphics::SCREEN_SYMBOLS to represent screen symbols

Fonts:

  • Graphics::SYMBOLS_9_HIGH to represent symbols with a height of 9
  • Graphics::SYMBOLS_7_HIGH to represent symbols with a height of 7
  • Graphics::SYMBOLS_6_HIGH to represent symbols with a height of 6

Docs for modules (WIP)

Utils

The Utils class provides utility functions that are used throughout the application. It provides methods for sleeping, getting the time since boot, setting the time start point, and getting the total and free heap.

Methods:

  • Utils::sleep_for_ms(int milliseconds) to sleep for a specific number of milliseconds
  • Utils::us_since_boot() to get the time in microseconds since the system boot
  • Utils::set_time_start_point() to set the start point for the time measurement
  • Utils::get_total_heap() to get the total heap size
  • Utils::get_free_heap() to get the free heap size

Error

Methods:

  • throw_error(ErrorType err) throws a error
  • error_thrown() returns if a error waas thrown
  • get_error() returns the current error
  • render_error() returns a Bitset2D that displays the current error
  • error_handled() unthrows the error (sets error to FINE)

Docs for constants

Chars

Constants:

  • KEY_MAP a map from string to keycode
  • KEY_MAP_SHIFT a map from string to keycode if shift is on
  • KEY_MAP_ALPHA a map form string to keycode if alpha is on

Methods:

  • in_key_set(KEY value, const KEY_SET& vector) checks if a KEY is in a KEY_SET

Constants

  • SCREEN_WIDTH the width of the screen (96)
  • SCREEN_HEIGHT the height of the screen (31)
  • OS_VERSION the version of the CasioOS running

Error

Types of errors:

  • MATH_ERROR
  • PUFFER_ERROR
  • SYNTAX_ERROR
  • ARGUMENT_ERROR
  • STORAGE_ERROR
  • TIME_ERROR
  • FINE (this is the state of "error" that indicates that there is no error)

LCDConstants

LCDConstants defines a set of constants that are used for LCD control. These constants represent various commands, modes, addresses, and statuses related to the LCD.

Constants:

  • SET_MODE to set the mode of the LCD

  • SET_START_BANK to set the start bank of the LCD

  • DEVICE_SELECT to select the device

  • RAM_ACCESS to access the RAM

  • LOAD_X_ADDRESS to load the X address

  • C_LAST_COMMAND to represent the last command

  • C_COMMAND_FOLLOWING to represent the command following

  • T_ROW_MODE to set the row mode

  • T_MIXED_MODE to set the mixed mode

  • E_BLANK_STATUS to represent the blank status

  • E_NORMAL_STATUS to represent the normal status

  • E_ALL_ON_STATUS to represent the all on status

  • E_INVERSE_STATUS to represent the inverse status

  • M_1_32_MULTIPLEX to set the multiplex

  • B_SET_START_BANK_0 to set the start bank 0

  • B_SET_START_BANK_1 to set the start bank 1

  • B_SET_START_BANK_2 to set the start bank 2

  • B_SET_START_BANK_3 to set the start bank 3

  • G_RAM_CHARACTER_MODE to set the character mode in RAM

  • G_RAM_HALF_GRAPHIC_MODE to set the half graphic mode in RAM

  • G_RAM_FULL_GRAPHIC_MODE to set the full graphic mode in RAM

  • G_RAM_NOT_ALLOWED_MODE to represent the not allowed mode in RAM

  • A_MASTER_ADDRESS to represent the master address

  • A_SUB_ADDRESS_0 to represent the sub address 0

  • A_SUB_ADDRESS_1 to represent the sub address 1

  • A_SUB_ADDRESS_2 to represent the sub address 2

  • DEVICE_ADDRESS to represent the device address

  • COLUMN_ZERO_ADDRESS to represent the column zero address

  • BANK_ZERO_ADDRESS to represent the bank zero address

Helper Scrips

keyMapCreator.py

You can use this script to convert characters to a map of characters and thier keycode. Type "esc" to escape the entering and start the converting.

main.py

This will ask you for dimentions and then start a gui window to create a screen. If you close the window it will output your result.

picoKeybordMapCreator.py

// TODO

Networking & Bluetooth

DesktopHttpClient

The DesktopHttpClient class is a concrete implementation of the IHttpClient interface for desktop platforms. It uses the httplib library to perform HTTP requests.

You can create a DesktopHttpClient with the following methods:

  • DesktopHttpClient(std::string _base_url) to initialize the HTTP client with a base URL

Methods:

  • .get(std::string path, HttpRequest req) to perform a GET request to a specific path with a request object
  • .post(std::string path, HttpRequest req) to perform a POST request to a specific path with a request object
  • .set_bearer_auth_token(std::string token) to set the bearer token for authentication

The DesktopHttpClient class is defined in the DesktopHttpClient.h header file and implemented in the DesktopHttpClient.cpp source file. It uses the HttpRequest and HttpResponse classes for managing the HTTP requests and responses.

IHttpClient

The IHttpClient class is an interface that defines the methods that an HTTP client should implement.

You can create an IHttpClient with the following methods:

  • IHttpClient(std::string _base_url) to initialize the HTTP client with a base URL

Methods:

  • .get(std::string path, HttpRequest req) to perform a GET request to a specific path with a request object (pure virtual method)
  • .post(std::string path, HttpRequest req) to perform a POST request to a specific path with a request object (pure virtual method)
  • .set_bearer_auth_token(std::string token) to set the bearer token for authentication (pure virtual method)

Note: The IHttpClient class is defined in the IHttpClient.h header file. It uses the HttpRequest and HttpResponse classes for managing the HTTP requests and responses.