Naereen/A-JavaScript-interpreter-for-the-NumWorks-calculator

Write some C wrapper code in Espruino, to expose some basic EADK lib functions to the JavaScript code, like for the Lua interpreter

Opened this issue · 7 comments

I want to write some C wrapper files, either in this project or in my Espruino fork (see https://github.com/Naereen/Espruino/), to expose some basic EADK lib functions to the JavaScript code, like for the Lua interpreter:

See these links for some documentation, regarding how to extend Espruino Embedded with a new module: (in order of decreasing importance, I think)

I've successfully added two functions to access the brightness (I picked easy functions to start with).

❌ Accessing the Battery levels

bool Eadk.battery_is_charging()

Indicates whether the battery is charging.

uint8_t Eadk.battery_level()

Returns a 8 bits integer giving the battery level.

float Eadk.battery_voltage()

Returns a floating value of the battery voltage (in Volt, I guess?).

These functions are missing from the hardware!
See this issue on NumWorks/epsilon's repository
TODO: try to mock these by SVC calls!

Miscellanious

bool Eadk.usb_is_plugged()

Indicates whether the USB is plugged.

Display

void Eadk.display_draw_string(const char* text, uint16_t x, uint16_t y, bool large_font, uint16_t text_color, uint16_t background_color)

TODO: I still haven't been able to define this one correctly, due to the char* text that I don't know how to declare in JSON (in the JSON to C process used by jswrap_ to generate the corresponding C code).

I have all the wrappers for basic functions, except for:

#ifndef EADK_H
#define EADK_H

#include <stdint.h>

// Types and constants

typedef struct {
  uint16_t x;
  uint16_t y;
} eadk_point_t;

typedef struct {
  uint16_t x;
  uint16_t y;
  uint16_t width;
  uint16_t height;
} eadk_rect_t;

// Keyboard and Events

#define EADK_SCREEN_WIDTH 320
#define EADK_SCREEN_HEIGHT 240
static const eadk_rect_t eadk_screen_rect = {0, 0, EADK_SCREEN_WIDTH, EADK_SCREEN_HEIGHT};

typedef uint64_t eadk_keyboard_state_t;
typedef enum { ... } eadk_key_t;

eadk_keyboard_state_t eadk_keyboard_scan();

static inline bool eadk_keyboard_key_down(eadk_keyboard_state_t state, eadk_key_t key);

typedef uint16_t eadk_event_t;
enum { ... }

eadk_event_t eadk_event_get(int32_t* timeout);

// Display

void eadk_display_push_rect(eadk_rect_t rect, const eadk_color_t* pixels);
void eadk_display_push_rect_uniform(eadk_rect_t rect, eadk_color_t color);
void eadk_display_pull_rect(eadk_rect_t rect, eadk_color_t* pixels);
bool eadk_display_wait_for_vblank();
void eadk_display_draw_string(const char* text, eadk_point_t point, bool large_font, eadk_color_t text_color, eadk_color_t background_color);

The last one is the one I've been working on for two hours... it displays a big fully-black rectangle... I have no idea how to debug this.

void eadk_display_draw_string(const char* text, eadk_point_t point, bool large_font, eadk_color_t text_color, eadk_color_t background_color);

AHAH I have a buggued eadk_display_draw_string, it's already cool!

AHAH I have a not buggued eadk_display_draw_string, it's even better!