mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
Merge pull request #99 from zardam/omega-extapp
External application, API v2
This commit is contained in:
@@ -18,22 +18,6 @@ EditorController::EditorController(MenuController * menuController, App * python
|
||||
m_editorView.setTextAreaDelegates(this, this);
|
||||
}
|
||||
|
||||
#ifdef MAX_SCRIPTSIZE
|
||||
void EditorController::setScript(Script script) {
|
||||
m_script = script;
|
||||
Script::Data scriptData = m_script.value();
|
||||
size_t s=scriptData.size,ms=sizeof(m_areaBuffer);
|
||||
if (s>ms)
|
||||
s=ms;
|
||||
size_t availableScriptSize = s + Ion::Storage::sharedStorage()->availableSize();
|
||||
if (availableScriptSize>ms)
|
||||
availableScriptSize=ms;
|
||||
// assert(sizeof(m_areaBuffer) >= availableScriptSize);
|
||||
// We cannot use strlcpy as the first char reprensenting the importation status can be 0.
|
||||
memcpy(m_areaBuffer, (const char *)scriptData.buffer, s);
|
||||
m_editorView.setText(m_areaBuffer+1, availableScriptSize-1); // 1 char is taken by the importation status flag
|
||||
}
|
||||
#else
|
||||
void EditorController::setScript(Script script) {
|
||||
m_script = script;
|
||||
Script::Data scriptData = m_script.value();
|
||||
@@ -43,7 +27,7 @@ void EditorController::setScript(Script script) {
|
||||
memcpy(m_areaBuffer, (const char *)scriptData.buffer, scriptData.size);
|
||||
m_editorView.setText(m_areaBuffer+1, availableScriptSize-1); // 1 char is taken by the importation status flag
|
||||
}
|
||||
#endif
|
||||
|
||||
// TODO: this should be done in textAreaDidFinishEditing maybe??
|
||||
bool EditorController::handleEvent(Ion::Events::Event event) {
|
||||
if (event == Ion::Events::OK || event == Ion::Events::Back || event == Ion::Events::Home) {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef CODE_EDITOR_CONTROLLER_H
|
||||
#define CODE_EDITOR_CONTROLLER_H
|
||||
|
||||
#define MAX_SCRIPTSIZE 12288
|
||||
|
||||
#include <escher.h>
|
||||
#include "script.h"
|
||||
#include "editor_view.h"
|
||||
@@ -41,7 +39,7 @@ private:
|
||||
/* m_areaBuffer first character is dedicated to the importation status.
|
||||
* Thereby, we avoid wasteful copy while adding the Script to the storage
|
||||
* (in order to add the importation status char before the areaBuffer). */
|
||||
char m_areaBuffer[Ion::Storage::k_storageSize>MAX_SCRIPTSIZE?MAX_SCRIPTSIZE:Ion::Storage::k_storageSize]; // this could be slightly optimize
|
||||
char m_areaBuffer[Ion::Storage::k_storageSize]; // this could be slightly optimize
|
||||
Script m_script;
|
||||
MenuController * m_menuController;
|
||||
};
|
||||
|
||||
3
apps/external/Makefile
vendored
3
apps/external/Makefile
vendored
@@ -11,10 +11,11 @@ app_external_src = $(addprefix apps/external/,\
|
||||
|
||||
SFLAGS += -Iapps/external/
|
||||
|
||||
EXTAPP_PATH ?= apps/external/app/
|
||||
ifeq ($(PLATFORM),device)
|
||||
SFLAGS += -DDEVICE
|
||||
else
|
||||
include apps/external/app/sources.mak
|
||||
include $(EXTAPP_PATH)/sources.mak
|
||||
endif
|
||||
|
||||
app_src += $(app_external_src)
|
||||
|
||||
9
apps/external/archive.cpp
vendored
9
apps/external/archive.cpp
vendored
@@ -1,5 +1,6 @@
|
||||
#include "archive.h"
|
||||
#include "extapp_api.h"
|
||||
#include "../global_preferences.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -34,12 +35,16 @@ bool isSane(const TarHeader* tar) {
|
||||
return !memcmp(tar->magic, "ustar ", 8) && tar->name[0] != '\x00' && tar->name[0] != '\xFF';
|
||||
}
|
||||
|
||||
bool isExamModeAndFileNotExecutable(const TarHeader* tar) {
|
||||
return GlobalPreferences::sharedGlobalPreferences()->examMode() && (tar->mode[4] & 0x01) == 0;
|
||||
}
|
||||
|
||||
bool fileAtIndex(size_t index, File &entry) {
|
||||
const TarHeader* tar = reinterpret_cast<const TarHeader*>(0x90200000);
|
||||
unsigned size = 0;
|
||||
|
||||
// Sanity check.
|
||||
if (!isSane(tar)) {
|
||||
if (!isSane(tar) || isExamModeAndFileNotExecutable(tar)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -58,7 +63,7 @@ bool fileAtIndex(size_t index, File &entry) {
|
||||
tar = reinterpret_cast<const TarHeader*>(reinterpret_cast<const char*>(tar) + stride);
|
||||
|
||||
// Sanity check.
|
||||
if (!isSane(tar)) {
|
||||
if (!isSane(tar) || isExamModeAndFileNotExecutable(tar)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
326
apps/external/extapp_api.cpp
vendored
326
apps/external/extapp_api.cpp
vendored
@@ -4,7 +4,10 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "archive.h"
|
||||
#include "extapp_api.h"
|
||||
#include "../apps_container.h"
|
||||
#include "../global_preferences.h"
|
||||
|
||||
#include <python/port/port.h>
|
||||
|
||||
@@ -36,30 +39,36 @@ void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16
|
||||
Ion::Display::pushRectUniform(rect, KDColor::RGB16(color));
|
||||
}
|
||||
|
||||
int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg) {
|
||||
void extapp_pullRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t * pixels) {
|
||||
KDRect rect(x, y, w, h);
|
||||
|
||||
Ion::Display::pullRect(rect, (KDColor *) pixels);
|
||||
}
|
||||
|
||||
int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake) {
|
||||
KDPoint point(x, y);
|
||||
|
||||
auto ctx = KDIonContext::sharedContext();
|
||||
ctx->setClippingRect(KDRect(0,0,320,240));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
ctx->drawString(text, point, KDFont::LargeFont, KDColor::RGB16(fg), KDColor::RGB16(bg));
|
||||
ctx->setClippingRect(KDRect(0, 0, 320, fake ? 0 : 240));
|
||||
ctx->setOrigin(KDPoint(0, 0));
|
||||
point = ctx->drawString(text, point, KDFont::LargeFont, KDColor::RGB16(fg), KDColor::RGB16(bg));
|
||||
|
||||
return point.x();
|
||||
}
|
||||
|
||||
int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg) {
|
||||
int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake) {
|
||||
KDPoint point(x, y);
|
||||
|
||||
auto ctx = KDIonContext::sharedContext();
|
||||
ctx->setClippingRect(KDRect(0,0,320,240));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
ctx->drawString(text, point, KDFont::SmallFont, KDColor::RGB16(fg), KDColor::RGB16(bg));
|
||||
ctx->setClippingRect(KDRect(0, 0, 320, fake ? 0 : 240));
|
||||
ctx->setOrigin(KDPoint(0, 0));
|
||||
point = ctx->drawString(text, point, KDFont::SmallFont, KDColor::RGB16(fg), KDColor::RGB16(bg));
|
||||
|
||||
return point.x();
|
||||
}
|
||||
|
||||
void extapp_waitForVBlank() {
|
||||
Ion::Display::waitForVBlank();
|
||||
bool extapp_waitForVBlank() {
|
||||
return Ion::Display::waitForVBlank();
|
||||
}
|
||||
|
||||
void extapp_clipboardStore(const char *text) {
|
||||
@@ -70,98 +79,231 @@ const char * extapp_clipboardText() {
|
||||
return Clipboard::sharedClipboard()->storedText();
|
||||
}
|
||||
|
||||
int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const char * extension, int storage) {
|
||||
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
|
||||
int n = Ion::Storage::sharedStorage()->numberOfRecordsWithExtension(extension);
|
||||
if (n > maxrecords) {
|
||||
n = maxrecords;
|
||||
}
|
||||
for(int i = 0; i < n; i++) {
|
||||
filenames[i] = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex(extension, i).fullName();
|
||||
}
|
||||
return n;
|
||||
} else if(storage == EXTAPP_FLASH_FILE_SYSTEM) {
|
||||
// TODO: filter by extension
|
||||
int n = External::Archive::numberOfFiles();
|
||||
if (n > maxrecords) {
|
||||
n = maxrecords;
|
||||
}
|
||||
for(int i = 0; i < n; i++) {
|
||||
External::Archive::File entry;
|
||||
External::Archive::fileAtIndex(i, entry);
|
||||
filenames[i] = entry.name;
|
||||
}
|
||||
return n;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool extapp_fileExists(const char * filename, int storage) {
|
||||
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
|
||||
return !Ion::Storage::sharedStorage()->recordNamed(filename).isNull();
|
||||
} else if(storage == EXTAPP_FLASH_FILE_SYSTEM) {
|
||||
return External::Archive::indexFromName(filename) >= 0;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool extapp_fileErase(const char * filename, int storage) {
|
||||
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
|
||||
Ion::Storage::Record record = Ion::Storage::sharedStorage()->recordNamed(filename);
|
||||
if(record.isNull()) {
|
||||
return false;
|
||||
} else {
|
||||
record.destroy();
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const char * extapp_fileRead(const char * filename, size_t *len, int storage) {
|
||||
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
|
||||
const Ion::Storage::Record record = Ion::Storage::sharedStorage()->recordNamed(filename);
|
||||
if (record.isNull()) {
|
||||
return NULL;
|
||||
} else {
|
||||
if(len) {
|
||||
*len = record.value().size;
|
||||
}
|
||||
return (const char *) record.value().buffer;
|
||||
}
|
||||
} else if(storage == EXTAPP_FLASH_FILE_SYSTEM) {
|
||||
int index = External::Archive::indexFromName(filename);
|
||||
if (index >= 0) {
|
||||
External::Archive::File entry;
|
||||
External::Archive::fileAtIndex(index, entry);
|
||||
if(len) {
|
||||
*len = entry.dataLength;
|
||||
}
|
||||
return (const char *)entry.data;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool extapp_fileWrite(const char * filename, const char * content, size_t len, int storage) {
|
||||
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
|
||||
Ion::Storage::Record::ErrorStatus status = Ion::Storage::sharedStorage()->createRecordWithFullName(filename, content, len);
|
||||
if (status == Ion::Storage::Record::ErrorStatus::NameTaken) {
|
||||
Ion::Storage::Record::Data data;
|
||||
data.buffer = content;
|
||||
data.size = len;
|
||||
return Ion::Storage::sharedStorage()->recordNamed(filename).setValue(data) == Ion::Storage::Record::ErrorStatus::None;
|
||||
} else if (status == Ion::Storage::Record::ErrorStatus::None) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static void reloadTitleBar() {
|
||||
AppsContainer::sharedAppsContainer()->setShiftAlphaStatus(Ion::Events::shiftAlphaStatus());
|
||||
AppsContainer::sharedAppsContainer()->refreshPreferences();
|
||||
AppsContainer::sharedAppsContainer()->updateBatteryState();
|
||||
AppsContainer::sharedAppsContainer()->reloadTitleBarView();
|
||||
AppsContainer::sharedAppsContainer()->redrawWindow();
|
||||
}
|
||||
|
||||
void extapp_lockAlpha() {
|
||||
Ion::Events::setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::AlphaLock);
|
||||
reloadTitleBar();
|
||||
}
|
||||
|
||||
void extapp_resetKeyboard() {
|
||||
Ion::Events::setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::Default);
|
||||
reloadTitleBar();
|
||||
}
|
||||
|
||||
const int16_t translated_keys[] =
|
||||
{
|
||||
// non shifted
|
||||
KEY_CTRL_LEFT,KEY_CTRL_UP,KEY_CTRL_DOWN,KEY_CTRL_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,KEY_CTRL_XTT,KEY_CTRL_VARS,KEY_CTRL_CATALOG,KEY_CTRL_DEL,
|
||||
KEY_CHAR_EXPN,KEY_CHAR_LN,KEY_CHAR_LOG,KEY_CHAR_IMGNRY,',',KEY_CHAR_POW,
|
||||
KEY_CHAR_SIN,KEY_CHAR_COS,KEY_CHAR_TAN,KEY_CHAR_PI,KEY_CHAR_ROOT,KEY_CHAR_SQUARE,
|
||||
'7','8','9','(',')',-1,
|
||||
'4','5','6','*','/',-1,
|
||||
'1','2','3','+','-',-1,
|
||||
'0','.',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
// shifted
|
||||
KEY_SHIFT_LEFT,KEY_CTRL_PAGEUP,KEY_CTRL_PAGEDOWN,KEY_SHIFT_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,KEY_CTRL_CUT,KEY_CTRL_CLIP,KEY_CTRL_PASTE,KEY_CTRL_AC,
|
||||
KEY_CHAR_LBRCKT,KEY_CHAR_RBRCKT,KEY_CHAR_LBRACE,KEY_CHAR_RBRACE,'_',KEY_CHAR_STORE,
|
||||
KEY_CHAR_ASIN,KEY_CHAR_ACOS,KEY_CHAR_ATAN,'=','<','>',
|
||||
KEY_CTRL_F7,KEY_CTRL_F8,KEY_CTRL_F9,KEY_CTRL_F13,KEY_CTRL_F14,-1,
|
||||
KEY_CTRL_F4,KEY_CTRL_F5,KEY_CTRL_F6,KEY_CHAR_FACTOR,'%',-1,
|
||||
KEY_CTRL_F1,KEY_CTRL_F2,KEY_CTRL_F3,KEY_CHAR_NORMAL,'\\',-1,
|
||||
KEY_CTRL_F10,KEY_CTRL_F11,KEY_CTRL_F12,KEY_SHIFT_ANS,KEY_CTRL_EXE,-1,
|
||||
// alpha
|
||||
KEY_CTRL_LEFT,KEY_CTRL_UP,KEY_CTRL_DOWN,KEY_CTRL_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,':',';','"',KEY_CTRL_DEL,
|
||||
'a','b','c','d','e','f',
|
||||
'g','h','i','j','k','l',
|
||||
'm','n','o','p','q',-1,
|
||||
'r','s','t','u','v',-1,
|
||||
'w','x','y','z',' ',-1,
|
||||
'?','!',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
// alpha shifted
|
||||
KEY_SHIFT_LEFT,KEY_CTRL_PAGEUP,KEY_CTRL_PAGEDOWN,KEY_SHIFT_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,':',';','\'','%',
|
||||
'A','B','C','D','E','F',
|
||||
'G','H','I','J','K','L',
|
||||
'M','N','O','P','Q',-1,
|
||||
'R','S','T','U','V',-1,
|
||||
'W','X','Y','Z',' ',-1,
|
||||
'?','!',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
};
|
||||
|
||||
#ifdef SIMULATOR
|
||||
#define TICKS_PER_MINUTE 60000
|
||||
#else
|
||||
#define TICKS_PER_MINUTE 11862
|
||||
#endif
|
||||
|
||||
int extapp_getKey(bool allowSuspend, bool *alphaWasActive) {
|
||||
int key = -1;
|
||||
size_t t1 = Ion::Timing::millis();
|
||||
for (;;) {
|
||||
int timeout = 10000;
|
||||
if(alphaWasActive) {
|
||||
*alphaWasActive = Ion::Events::isAlphaActive();
|
||||
}
|
||||
Ion::Events::Event event = Ion::Events::getEvent(&timeout);
|
||||
reloadTitleBar();
|
||||
if (event == Ion::Events::None) {
|
||||
size_t t2 = Ion::Timing::millis();
|
||||
if (t2 - t1 > 2 * TICKS_PER_MINUTE) {
|
||||
event = Ion::Events::OnOff;
|
||||
}
|
||||
} else {
|
||||
t1 = Ion::Timing::millis();
|
||||
}
|
||||
if (event.isKeyboardEvent()) {
|
||||
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
|
||||
}
|
||||
if (event == Ion::Events::Shift || event == Ion::Events::Alpha) {
|
||||
continue;
|
||||
}
|
||||
if (event.isKeyboardEvent()) {
|
||||
key = event.id();
|
||||
if (key == 17 || key == 4 || key == 5 || key == 52) {
|
||||
extapp_resetKeyboard();
|
||||
}
|
||||
if (allowSuspend && (key == 7 || key == 8)) { // power
|
||||
Ion::Power::suspend(true);
|
||||
extapp_pushRectUniform(0, 0, 320, 240, 65535);
|
||||
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
|
||||
reloadTitleBar();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return translated_keys[key];
|
||||
}
|
||||
|
||||
extern "C" void (* const apiPointers[])(void) = {
|
||||
(void (*)(void)) extapp_millis,
|
||||
(void (*)(void)) extapp_msleep,
|
||||
(void (*)(void)) extapp_scanKeyboard,
|
||||
(void (*)(void)) extapp_pushRect,
|
||||
(void (*)(void)) extapp_pushRectUniform,
|
||||
(void (*)(void)) extapp_pullRect,
|
||||
(void (*)(void)) extapp_drawTextLarge,
|
||||
(void (*)(void)) extapp_drawTextSmall,
|
||||
(void (*)(void)) extapp_waitForVBlank,
|
||||
(void (*)(void)) extapp_clipboardStore,
|
||||
(void (*)(void)) extapp_clipboardText,
|
||||
(void (*)(void)) extapp_fileListWithExtension,
|
||||
(void (*)(void)) extapp_fileExists,
|
||||
(void (*)(void)) extapp_fileErase,
|
||||
(void (*)(void)) extapp_fileRead,
|
||||
(void (*)(void)) extapp_fileWrite,
|
||||
(void (*)(void)) extapp_lockAlpha,
|
||||
(void (*)(void)) extapp_resetKeyboard,
|
||||
(void (*)(void)) extapp_getKey,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
(void (*)(void)) nullptr,
|
||||
|
||||
// khicas from here, subject to change
|
||||
(void (*)(void)) numworks_draw_string,
|
||||
(void (*)(void)) numworks_draw_string_small,
|
||||
(void (*)(void)) numworks_set_pixel,
|
||||
(void (*)(void)) numworks_fill_rect,
|
||||
(void (*)(void)) numworks_get_pixel,
|
||||
(void (*)(void)) numworks_hide_graph,
|
||||
(void (*)(void)) numworks_wait_1ms,
|
||||
(void (*)(void)) waitforvblank,
|
||||
(void (*)(void)) statuslinemsg,
|
||||
(void (*)(void)) statusline,
|
||||
(void (*)(void)) getkey,
|
||||
(void (*)(void)) GetKey,
|
||||
(void (*)(void)) alphawasactive,
|
||||
(void (*)(void)) lock_alpha,
|
||||
(void (*)(void)) reset_kbd,
|
||||
(void (*)(void)) back_key_pressed,
|
||||
(void (*)(void)) enable_back_interrupt,
|
||||
(void (*)(void)) disable_back_interrupt,
|
||||
(void (*)(void)) os_set_angle_unit,
|
||||
(void (*)(void)) os_get_angle_unit,
|
||||
(void (*)(void)) os_file_browser,
|
||||
(void (*)(void)) file_exists,
|
||||
(void (*)(void)) erase_file,
|
||||
(void (*)(void)) read_file,
|
||||
(void (*)(void)) write_file,
|
||||
(void (*)(void)) mp_hal_input,
|
||||
(void (*)(void)) nullptr
|
||||
};
|
||||
|
||||
282
apps/external/extapp_api.h
vendored
282
apps/external/extapp_api.h
vendored
@@ -2,8 +2,10 @@
|
||||
#define EXTERNAL_API_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define API_VERSION 1
|
||||
#define API_VERSION 2
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERNC extern "C"
|
||||
@@ -14,63 +16,241 @@
|
||||
#define LCD_WIDTH 320
|
||||
#define LCD_HEIGHT 240
|
||||
|
||||
#define KEY_Left ((uint64_t)1 << 0)
|
||||
#define KEY_Up ((uint64_t)1 << 1)
|
||||
#define KEY_Down ((uint64_t)1 << 2)
|
||||
#define KEY_Right ((uint64_t)1 << 3)
|
||||
#define KEY_OK ((uint64_t)1 << 4)
|
||||
#define KEY_Back ((uint64_t)1 << 5)
|
||||
#define KEY_Home ((uint64_t)1 << 6)
|
||||
#define KEY_OnOff (((uint64_t)1 << 7) || ((uint64_t)1 << 8))
|
||||
#define KEY_Shift ((uint64_t)1 << 12)
|
||||
#define KEY_Alpha ((uint64_t)1 << 13)
|
||||
#define KEY_XNT ((uint64_t)1 << 14)
|
||||
#define KEY_Var ((uint64_t)1 << 15)
|
||||
#define KEY_Toolbox ((uint64_t)1 << 16)
|
||||
#define KEY_Backspace ((uint64_t)1 << 17)
|
||||
#define KEY_Exp ((uint64_t)1 << 18)
|
||||
#define KEY_Ln ((uint64_t)1 << 19)
|
||||
#define KEY_Log ((uint64_t)1 << 20)
|
||||
#define KEY_Imaginary ((uint64_t)1 << 21)
|
||||
#define KEY_Comma ((uint64_t)1 << 22)
|
||||
#define KEY_Power ((uint64_t)1 << 23)
|
||||
#define KEY_Sine ((uint64_t)1 << 24)
|
||||
#define KEY_Cosine ((uint64_t)1 << 25)
|
||||
#define KEY_Tangent ((uint64_t)1 << 26)
|
||||
#define KEY_Pi ((uint64_t)1 << 27)
|
||||
#define KEY_Sqrt ((uint64_t)1 << 28)
|
||||
#define KEY_Square ((uint64_t)1 << 29)
|
||||
#define KEY_Seven ((uint64_t)1 << 30)
|
||||
#define KEY_Eight ((uint64_t)1 << 31)
|
||||
#define KEY_Nine ((uint64_t)1 << 32)
|
||||
#define KEY_LeftParenthesis ((uint64_t)1 << 33)
|
||||
#define KEY_RightParenthesis ((uint64_t)1 << 34)
|
||||
#define KEY_Four ((uint64_t)1 << 36)
|
||||
#define KEY_Five ((uint64_t)1 << 37)
|
||||
#define KEY_Six ((uint64_t)1 << 38)
|
||||
#define KEY_Multiplication ((uint64_t)1 << 39)
|
||||
#define KEY_Division ((uint64_t)1 << 40)
|
||||
#define KEY_One ((uint64_t)1 << 42)
|
||||
#define KEY_Two ((uint64_t)1 << 43)
|
||||
#define KEY_Three ((uint64_t)1 << 44)
|
||||
#define KEY_Plus ((uint64_t)1 << 45)
|
||||
#define KEY_Minus ((uint64_t)1 << 46)
|
||||
#define KEY_Zero ((uint64_t)1 << 48)
|
||||
#define KEY_Dot ((uint64_t)1 << 49)
|
||||
#define KEY_EE ((uint64_t)1 << 50)
|
||||
#define KEY_Ans ((uint64_t)1 << 51)
|
||||
#define KEY_EXE ((uint64_t)1 << 52)
|
||||
#define KEY_None ((uint64_t)1 << 54)
|
||||
#define EXTAPP_RAM_FILE_SYSTEM 0
|
||||
#define EXTAPP_FLASH_FILE_SYSTEM 1
|
||||
|
||||
#define SCANCODE_Left ((uint64_t)1 << 0)
|
||||
#define SCANCODE_Up ((uint64_t)1 << 1)
|
||||
#define SCANCODE_Down ((uint64_t)1 << 2)
|
||||
#define SCANCODE_Right ((uint64_t)1 << 3)
|
||||
#define SCANCODE_OK ((uint64_t)1 << 4)
|
||||
#define SCANCODE_Back ((uint64_t)1 << 5)
|
||||
#define SCANCODE_Home ((uint64_t)1 << 6)
|
||||
#define SCANCODE_OnOff (((uint64_t)1 << 7) || ((uint64_t)1 << 8))
|
||||
#define SCANCODE_Shift ((uint64_t)1 << 12)
|
||||
#define SCANCODE_Alpha ((uint64_t)1 << 13)
|
||||
#define SCANCODE_XNT ((uint64_t)1 << 14)
|
||||
#define SCANCODE_Var ((uint64_t)1 << 15)
|
||||
#define SCANCODE_Toolbox ((uint64_t)1 << 16)
|
||||
#define SCANCODE_Backspace ((uint64_t)1 << 17)
|
||||
#define SCANCODE_Exp ((uint64_t)1 << 18)
|
||||
#define SCANCODE_Ln ((uint64_t)1 << 19)
|
||||
#define SCANCODE_Log ((uint64_t)1 << 20)
|
||||
#define SCANCODE_Imaginary ((uint64_t)1 << 21)
|
||||
#define SCANCODE_Comma ((uint64_t)1 << 22)
|
||||
#define SCANCODE_Power ((uint64_t)1 << 23)
|
||||
#define SCANCODE_Sine ((uint64_t)1 << 24)
|
||||
#define SCANCODE_Cosine ((uint64_t)1 << 25)
|
||||
#define SCANCODE_Tangent ((uint64_t)1 << 26)
|
||||
#define SCANCODE_Pi ((uint64_t)1 << 27)
|
||||
#define SCANCODE_Sqrt ((uint64_t)1 << 28)
|
||||
#define SCANCODE_Square ((uint64_t)1 << 29)
|
||||
#define SCANCODE_Seven ((uint64_t)1 << 30)
|
||||
#define SCANCODE_Eight ((uint64_t)1 << 31)
|
||||
#define SCANCODE_Nine ((uint64_t)1 << 32)
|
||||
#define SCANCODE_LeftParenthesis ((uint64_t)1 << 33)
|
||||
#define SCANCODE_RightParenthesis ((uint64_t)1 << 34)
|
||||
#define SCANCODE_Four ((uint64_t)1 << 36)
|
||||
#define SCANCODE_Five ((uint64_t)1 << 37)
|
||||
#define SCANCODE_Six ((uint64_t)1 << 38)
|
||||
#define SCANCODE_Multiplication ((uint64_t)1 << 39)
|
||||
#define SCANCODE_Division ((uint64_t)1 << 40)
|
||||
#define SCANCODE_One ((uint64_t)1 << 42)
|
||||
#define SCANCODE_Two ((uint64_t)1 << 43)
|
||||
#define SCANCODE_Three ((uint64_t)1 << 44)
|
||||
#define SCANCODE_Plus ((uint64_t)1 << 45)
|
||||
#define SCANCODE_Minus ((uint64_t)1 << 46)
|
||||
#define SCANCODE_Zero ((uint64_t)1 << 48)
|
||||
#define SCANCODE_Dot ((uint64_t)1 << 49)
|
||||
#define SCANCODE_EE ((uint64_t)1 << 50)
|
||||
#define SCANCODE_Ans ((uint64_t)1 << 51)
|
||||
#define SCANCODE_EXE ((uint64_t)1 << 52)
|
||||
#define SCANCODE_None ((uint64_t)1 << 54)
|
||||
|
||||
// Character codes
|
||||
#define KEY_CHAR_0 0x30
|
||||
#define KEY_CHAR_1 0x31
|
||||
#define KEY_CHAR_2 0x32
|
||||
#define KEY_CHAR_3 0x33
|
||||
#define KEY_CHAR_4 0x34
|
||||
#define KEY_CHAR_5 0x35
|
||||
#define KEY_CHAR_6 0x36
|
||||
#define KEY_CHAR_7 0x37
|
||||
#define KEY_CHAR_8 0x38
|
||||
#define KEY_CHAR_9 0x39
|
||||
#define KEY_CHAR_DP 0x2e
|
||||
#define KEY_CHAR_EXP 0x0f
|
||||
#define KEY_CHAR_PMINUS 30200
|
||||
#define KEY_CHAR_PLUS 43
|
||||
#define KEY_CHAR_MINUS 45
|
||||
#define KEY_CHAR_MULT 42
|
||||
#define KEY_CHAR_DIV 47
|
||||
#define KEY_CHAR_FRAC 0xbb
|
||||
#define KEY_CHAR_LPAR 0x28
|
||||
#define KEY_CHAR_RPAR 0x29
|
||||
#define KEY_CHAR_COMMA 0x2c
|
||||
#define KEY_CHAR_STORE 0x0e
|
||||
#define KEY_CHAR_LOG 0x95
|
||||
#define KEY_CHAR_LN 0x85
|
||||
#define KEY_CHAR_SIN 0x81
|
||||
#define KEY_CHAR_COS 0x82
|
||||
#define KEY_CHAR_TAN 0x83
|
||||
#define KEY_CHAR_SQUARE 0x8b
|
||||
#define KEY_CHAR_POW 0xa8
|
||||
#define KEY_CHAR_IMGNRY 0x7f50
|
||||
#define KEY_CHAR_LIST 0x7f51
|
||||
#define KEY_CHAR_MAT 0x7f40
|
||||
#define KEY_CHAR_EQUAL 0x3d
|
||||
#define KEY_CHAR_PI 0xd0
|
||||
#define KEY_CHAR_ANS 0xc0
|
||||
#define KEY_SHIFT_ANS 0xc1
|
||||
#define KEY_CHAR_LBRCKT 0x5b
|
||||
#define KEY_CHAR_RBRCKT 0x5d
|
||||
#define KEY_CHAR_LBRACE 0x7b
|
||||
#define KEY_CHAR_RBRACE 0x7d
|
||||
#define KEY_CHAR_CR 0x0d
|
||||
#define KEY_CHAR_CUBEROOT 0x96
|
||||
#define KEY_CHAR_RECIP 0x9b
|
||||
#define KEY_CHAR_ANGLE 0x7f54
|
||||
#define KEY_CHAR_EXPN10 0xb5
|
||||
#define KEY_CHAR_EXPN 0xa5
|
||||
#define KEY_CHAR_ASIN 0x91
|
||||
#define KEY_CHAR_ACOS 0x92
|
||||
#define KEY_CHAR_ATAN 0x93
|
||||
#define KEY_CHAR_ROOT 0x86
|
||||
#define KEY_CHAR_POWROOT 0xb8
|
||||
#define KEY_CHAR_SPACE 0x20
|
||||
#define KEY_CHAR_DQUATE 0x22
|
||||
#define KEY_CHAR_VALR 0xcd
|
||||
#define KEY_CHAR_THETA 0xce
|
||||
#define KEY_CHAR_FACTOR 0xda
|
||||
#define KEY_CHAR_NORMAL 0xdb
|
||||
#define KEY_CHAR_A 0x41
|
||||
#define KEY_CHAR_B 0x42
|
||||
#define KEY_CHAR_C 0x43
|
||||
#define KEY_CHAR_D 0x44
|
||||
#define KEY_CHAR_E 0x45
|
||||
#define KEY_CHAR_F 0x46
|
||||
#define KEY_CHAR_G 0x47
|
||||
#define KEY_CHAR_H 0x48
|
||||
#define KEY_CHAR_I 0x49
|
||||
#define KEY_CHAR_J 0x4a
|
||||
#define KEY_CHAR_K 0x4b
|
||||
#define KEY_CHAR_L 0x4c
|
||||
#define KEY_CHAR_M 0x4d
|
||||
#define KEY_CHAR_N 0x4e
|
||||
#define KEY_CHAR_O 0x4f
|
||||
#define KEY_CHAR_P 0x50
|
||||
#define KEY_CHAR_Q 0x51
|
||||
#define KEY_CHAR_R 0x52
|
||||
#define KEY_CHAR_S 0x53
|
||||
#define KEY_CHAR_T 0x54
|
||||
#define KEY_CHAR_U 0x55
|
||||
#define KEY_CHAR_V 0x56
|
||||
#define KEY_CHAR_W 0x57
|
||||
#define KEY_CHAR_X 0x58
|
||||
#define KEY_CHAR_Y 0x59
|
||||
#define KEY_CHAR_Z 0x5a
|
||||
|
||||
// Control codes
|
||||
#define KEY_CTRL_NOP 30202
|
||||
#define KEY_CTRL_EXE 30201
|
||||
#define KEY_CTRL_DEL 30025
|
||||
#define KEY_CTRL_AC 30070
|
||||
#define KEY_CTRL_FD 30046
|
||||
#define KEY_CTRL_UNDO 30045
|
||||
#define KEY_CTRL_XTT 30001
|
||||
#define KEY_CTRL_EXIT 5
|
||||
#define KEY_CTRL_OK 4
|
||||
#define KEY_CTRL_SHIFT 30006
|
||||
#define KEY_CTRL_ALPHA 30007
|
||||
#define KEY_CTRL_OPTN 30008
|
||||
#define KEY_CTRL_VARS 30030
|
||||
#define KEY_CTRL_UP 1
|
||||
#define KEY_CTRL_DOWN 2
|
||||
#define KEY_CTRL_LEFT 0
|
||||
#define KEY_CTRL_RIGHT 3
|
||||
#define KEY_CTRL_F1 30009
|
||||
#define KEY_CTRL_F2 30010
|
||||
#define KEY_CTRL_F3 30011
|
||||
#define KEY_CTRL_F4 30012
|
||||
#define KEY_CTRL_F5 30013
|
||||
#define KEY_CTRL_F6 30014
|
||||
#define KEY_CTRL_F7 30015
|
||||
#define KEY_CTRL_F8 30016
|
||||
#define KEY_CTRL_F9 30017
|
||||
#define KEY_CTRL_F10 30018
|
||||
#define KEY_CTRL_F11 30019
|
||||
#define KEY_CTRL_F12 30020
|
||||
#define KEY_CTRL_F13 30021
|
||||
#define KEY_CTRL_F14 30022
|
||||
#define KEY_CTRL_CATALOG 30100
|
||||
#define KEY_CTRL_CAPTURE 30055
|
||||
#define KEY_CTRL_CLIP 30050
|
||||
#define KEY_CTRL_CUT 30250
|
||||
#define KEY_CTRL_PASTE 30036
|
||||
#define KEY_CTRL_INS 30033
|
||||
#define KEY_CTRL_MIXEDFRAC 30054
|
||||
#define KEY_CTRL_FRACCNVRT 30026
|
||||
#define KEY_CTRL_QUIT 30029
|
||||
#define KEY_CTRL_PRGM 30028
|
||||
#define KEY_CTRL_SETUP 30037
|
||||
#define KEY_CTRL_PAGEUP 30052
|
||||
#define KEY_CTRL_PAGEDOWN 30053
|
||||
#define KEY_CTRL_MENU 30003
|
||||
#define KEY_SHIFT_OPTN 30059
|
||||
#define KEY_CTRL_RESERVE1 30060
|
||||
#define KEY_CTRL_RESERVE2 30061
|
||||
#define KEY_SHIFT_LEFT 30062
|
||||
#define KEY_SHIFT_RIGHT 30063
|
||||
|
||||
#define KEY_PRGM_ACON 10
|
||||
#define KEY_PRGM_DOWN 37
|
||||
#define KEY_PRGM_EXIT 47
|
||||
#define KEY_PRGM_F1 79
|
||||
#define KEY_PRGM_F2 69
|
||||
#define KEY_PRGM_F3 59
|
||||
#define KEY_PRGM_F4 49
|
||||
#define KEY_PRGM_F5 39
|
||||
#define KEY_PRGM_F6 29
|
||||
#define KEY_PRGM_LEFT 38
|
||||
#define KEY_PRGM_NONE 0
|
||||
#define KEY_PRGM_RETURN 31
|
||||
#define KEY_PRGM_RIGHT 27
|
||||
#define KEY_PRGM_UP 28
|
||||
#define KEY_PRGM_1 72
|
||||
#define KEY_PRGM_2 62
|
||||
#define KEY_PRGM_3 52
|
||||
#define KEY_PRGM_4 73
|
||||
#define KEY_PRGM_5 63
|
||||
#define KEY_PRGM_6 53
|
||||
#define KEY_PRGM_7 74
|
||||
#define KEY_PRGM_8 64
|
||||
#define KEY_PRGM_9 54
|
||||
#define KEY_PRGM_A 76
|
||||
#define KEY_PRGM_F 26
|
||||
#define KEY_PRGM_ALPHA 77
|
||||
#define KEY_PRGM_SHIFT 78
|
||||
#define KEY_PRGM_MENU 48
|
||||
|
||||
EXTERNC uint64_t extapp_millis();
|
||||
EXTERNC void extapp_msleep(uint32_t ms);
|
||||
EXTERNC uint64_t extapp_scanKeyboard();
|
||||
EXTERNC void extapp_pushRect(int16_t x, int16_t y, uint16_t w, uint16_t h, const uint16_t * pixels);
|
||||
EXTERNC void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color);
|
||||
EXTERNC int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg);
|
||||
EXTERNC int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg);
|
||||
EXTERNC void extapp_waitForVBlank();
|
||||
EXTERNC void extapp_pullRect(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t * pixels);
|
||||
EXTERNC int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake);
|
||||
EXTERNC int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake);
|
||||
EXTERNC bool extapp_waitForVBlank();
|
||||
EXTERNC void extapp_clipboardStore(const char *text);
|
||||
EXTERNC const char * extapp_clipboardText();
|
||||
EXTERNC int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const char * extension, int storage);
|
||||
EXTERNC bool extapp_fileExists(const char * filename, int storage);
|
||||
EXTERNC bool extapp_fileErase(const char * filename, int storage);
|
||||
EXTERNC const char * extapp_fileRead(const char * filename, size_t *len, int storage);
|
||||
EXTERNC bool extapp_fileWrite(const char * filename, const char * content, size_t len, int storage);
|
||||
EXTERNC void extapp_lockAlpha();
|
||||
EXTERNC void extapp_resetKeyboard();
|
||||
EXTERNC int extapp_getKey(bool allowSuspend, bool *alphaWasActive);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -115,6 +115,7 @@ public:
|
||||
void destroyRecordWithBaseNameAndExtension(const char * baseName, const char * extension);
|
||||
void destroyRecordsWithExtension(const char * extension);
|
||||
|
||||
private:
|
||||
constexpr static uint32_t Magic = 0xEE0BDDBA;
|
||||
constexpr static size_t k_maxRecordSize = (1 << sizeof(record_size_t)*8);
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ public:
|
||||
static KDColor blend(KDColor first, KDColor second, uint8_t alpha);
|
||||
KDColor invert() const { return KDColor(~m_value); }
|
||||
operator uint16_t() const { return m_value; }
|
||||
constexpr KDColor(uint16_t value) : m_value(value) {}
|
||||
private:
|
||||
constexpr KDColor(uint16_t value) : m_value(value) {}
|
||||
uint16_t m_value;
|
||||
};
|
||||
|
||||
|
||||
@@ -33,10 +33,13 @@ public:
|
||||
void fillRectWithPixels(KDRect rect, const KDColor * pixels, KDColor * workingBuffer);
|
||||
void blendRectWithMask(KDRect rect, KDColor color, const uint8_t * mask, KDColor * workingBuffer);
|
||||
void strokeRect(KDRect rect, KDColor color);
|
||||
KDContext(KDPoint origin, KDRect clippingRect);
|
||||
|
||||
virtual void pushRect(KDRect, const KDColor * pixels) = 0;
|
||||
virtual void pushRectUniform(KDRect rect, KDColor color) = 0;
|
||||
virtual void pullRect(KDRect rect, KDColor * pixels) = 0;
|
||||
protected:
|
||||
KDContext(KDPoint origin, KDRect clippingRect);
|
||||
private:
|
||||
KDRect absoluteFillRect(KDRect rect);
|
||||
KDPoint pushOrPullString(const char * text, KDPoint p, const KDFont * font, KDColor textColor, KDColor backgroundColor, int maxByteLength, bool push, int * result = nullptr);
|
||||
KDPoint m_origin;
|
||||
|
||||
@@ -27,6 +27,7 @@ public:
|
||||
bool zoomInhibit;
|
||||
bool gammaEnabled;
|
||||
int zoomPosition;
|
||||
private:
|
||||
KDIonContext();
|
||||
void pushRect(KDRect rect, const KDColor * pixels) override;
|
||||
void pushRectUniform(KDRect rect, KDColor color) override;
|
||||
|
||||
@@ -129,8 +129,6 @@ Q(.)
|
||||
Q(EE)
|
||||
Q(Ans)
|
||||
Q(EXE)
|
||||
Q(get_key)
|
||||
Q(Pause)
|
||||
|
||||
// Turtle QSTRs
|
||||
Q(turtle)
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
#include "helpers.h"
|
||||
#include <ion.h>
|
||||
#ifdef SIMULATOR
|
||||
#include <FL/Fl.H>
|
||||
#endif
|
||||
extern "C" {
|
||||
#include "mphalport.h"
|
||||
}
|
||||
|
||||
@@ -8,22 +8,19 @@ extern "C" {
|
||||
#include "port.h"
|
||||
|
||||
static KDColor ColorForTuple(mp_obj_t tuple) {
|
||||
if (MP_OBJ_IS_SMALL_INT(tuple)) // BP change: accept int for color
|
||||
return MP_OBJ_SMALL_INT_VALUE(tuple);
|
||||
size_t len;
|
||||
mp_obj_t * elem;
|
||||
|
||||
size_t len;
|
||||
mp_obj_t * elem;
|
||||
mp_obj_get_array(tuple, &len, &elem);
|
||||
if (len != 3) {
|
||||
mp_raise_TypeError("color needs 3 components");
|
||||
}
|
||||
|
||||
mp_obj_get_array(tuple, &len, &elem);
|
||||
if (len != 3) {
|
||||
mp_raise_TypeError("color needs 3 components");
|
||||
}
|
||||
|
||||
return KDColor::RGB888(
|
||||
mp_obj_get_int(elem[0]),
|
||||
mp_obj_get_int(elem[1]),
|
||||
mp_obj_get_int(elem[2])
|
||||
);
|
||||
return KDColor::RGB888(
|
||||
mp_obj_get_int(elem[0]),
|
||||
mp_obj_get_int(elem[1]),
|
||||
mp_obj_get_int(elem[2])
|
||||
);
|
||||
}
|
||||
|
||||
static mp_obj_t TupleForRGB(uint8_t r, uint8_t g, uint8_t b) {
|
||||
@@ -186,117 +183,3 @@ mp_obj_t modkandinsky_get_keys() {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* C-- SDK (c) B. Parisse, 2019 */
|
||||
mp_obj_t modkandinsky_Pause(mp_obj_t x) {
|
||||
double d=mp_obj_get_float(x);
|
||||
numworks_wait_1ms(d*1000);
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
#define LCD_WIDTH_PX 320
|
||||
#define LCD_HEIGHT_PX 222
|
||||
|
||||
void numworks_set_pixel(int x, int y, int color) {
|
||||
if (x<0 || x>=LCD_WIDTH_PX || y<0 || y>=LCD_HEIGHT_PX)
|
||||
return;
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,0,320,240));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
KDColor c(color);
|
||||
KDPoint point(x,y+18);
|
||||
KDIonContext::sharedContext()->pushRect(KDRect(point, 1, 1), &c);
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
}
|
||||
|
||||
void numworks_fill_rect(int x,int y,int w,int h,int c){
|
||||
KDColor color = c;
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,0,320,240));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
#if 1
|
||||
if (x<0){
|
||||
w += x;
|
||||
x=0;
|
||||
}
|
||||
if (y<0){
|
||||
h += y;
|
||||
y=0;
|
||||
}
|
||||
if (h+y>=LCD_HEIGHT_PX)
|
||||
h=LCD_HEIGHT_PX-y;
|
||||
if (x+w>=LCD_WIDTH_PX)
|
||||
w=LCD_WIDTH_PX-x;
|
||||
if (h<=0 || w<=0)
|
||||
return;
|
||||
KDRect rect(x,y+18,w,h);
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,color);
|
||||
#else
|
||||
KDRect rect(x,y,w,h);
|
||||
KDIonContext::sharedContext()->fillRect(rect, color);
|
||||
#endif
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
}
|
||||
|
||||
int numworks_get_pixel(int x, int y) {
|
||||
KDPoint point(x,y);
|
||||
KDColor c = KDIonContext::sharedContext()->getPixel(point);
|
||||
return c;
|
||||
}
|
||||
|
||||
int numworks_draw_string(int x,int y,int c,int bg,const char * text,bool fake){
|
||||
auto ptr=MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
KDPoint point(x,y);
|
||||
if (ptr)
|
||||
ptr->displaySandbox();
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,18,320,fake?0:222));
|
||||
ctx->setOrigin(KDPoint(0,18));
|
||||
point=KDIonContext::sharedContext()->drawString(text, point, KDFont::LargeFont, c, bg);
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
return point.x();
|
||||
}
|
||||
|
||||
int numworks_draw_string_small(int x,int y,int c,int bg,const char * text,bool fake){
|
||||
auto ptr=MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
KDPoint point(x,y);
|
||||
if (ptr)
|
||||
ptr->displaySandbox();
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,18,320,fake?0:222));
|
||||
ctx->setOrigin(KDPoint(0,18));
|
||||
point=ctx->drawString(text, point, KDFont::SmallFont, c, bg);
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
return point.x();
|
||||
}
|
||||
|
||||
void numworks_hide_graph(){
|
||||
auto ptr=MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
if (ptr)
|
||||
ptr->hideSandbox();
|
||||
}
|
||||
|
||||
void numworks_show_graph(){
|
||||
auto ptr=MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
if (ptr)
|
||||
ptr->displaySandbox();
|
||||
}
|
||||
|
||||
// Python module get_key() addition
|
||||
mp_obj_t modkandinsky_get_key() {
|
||||
micropython_port_interrupt_if_needed();
|
||||
int key=getkey(false); // no suspend
|
||||
return mp_obj_new_int(key);
|
||||
}
|
||||
|
||||
@@ -7,5 +7,3 @@ mp_obj_t modkandinsky_draw_string(size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t modkandinsky_fill_rect(size_t n_args, const mp_obj_t *args);
|
||||
mp_obj_t modkandinsky_wait_vblank();
|
||||
mp_obj_t modkandinsky_get_keys();
|
||||
mp_obj_t modkandinsky_get_key();
|
||||
mp_obj_t modkandinsky_Pause(mp_obj_t x) ;
|
||||
|
||||
@@ -7,8 +7,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_draw_string_obj, 3, 5, m
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modkandinsky_fill_rect_obj, 5, 5, modkandinsky_fill_rect);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_wait_vblank_obj, modkandinsky_wait_vblank);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_keys_obj, modkandinsky_get_keys);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modkandinsky_get_key_obj, modkandinsky_get_key);
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(modkandinsky_Pause_obj, modkandinsky_Pause);
|
||||
|
||||
STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_kandinsky) },
|
||||
@@ -19,8 +17,6 @@ STATIC const mp_rom_map_elem_t modkandinsky_module_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR_fill_rect), (mp_obj_t)&modkandinsky_fill_rect_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_wait_vblank), (mp_obj_t)&modkandinsky_wait_vblank_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_keys), (mp_obj_t)&modkandinsky_get_keys_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_key), (mp_obj_t)&modkandinsky_get_key_obj },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Pause), (mp_obj_t)&modkandinsky_Pause_obj },
|
||||
};
|
||||
|
||||
STATIC MP_DEFINE_CONST_DICT(modkandinsky_module_globals, modkandinsky_module_globals_table);
|
||||
|
||||
@@ -1,14 +1,6 @@
|
||||
#ifdef SIMULATOR
|
||||
#include <FL/Fl.H>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include "port.h"
|
||||
|
||||
#include <ion.h>
|
||||
#include <kandinsky.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include "../../apps/apps_container.h"
|
||||
#include "../../apps/global_preferences.h"
|
||||
#include <ion/keyboard.h>
|
||||
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
@@ -86,9 +78,9 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
/* End of mp_obj_print_exception. */
|
||||
}
|
||||
|
||||
assert(sCurrentExecutionEnvironment == this);
|
||||
sCurrentExecutionEnvironment = nullptr;
|
||||
}
|
||||
assert(sCurrentExecutionEnvironment == this);
|
||||
sCurrentExecutionEnvironment = nullptr;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::interrupt() {
|
||||
mp_keyboard_interrupt();
|
||||
@@ -205,485 +197,11 @@ mp_import_stat_t mp_import_stat(const char *path) {
|
||||
}
|
||||
|
||||
void mp_hal_stdout_tx_strn_cooked(const char * str, size_t len) {
|
||||
if (sCurrentExecutionEnvironment != nullptr)
|
||||
sCurrentExecutionEnvironment->printText(str, len);
|
||||
assert(sCurrentExecutionEnvironment != nullptr);
|
||||
sCurrentExecutionEnvironment->printText(str, len);
|
||||
}
|
||||
|
||||
const char * mp_hal_input(const char * prompt) {
|
||||
if (sCurrentExecutionEnvironment != nullptr)
|
||||
return sCurrentExecutionEnvironment->inputText(prompt);
|
||||
return 0;
|
||||
assert(sCurrentExecutionEnvironment != nullptr);
|
||||
return sCurrentExecutionEnvironment->inputText(prompt);
|
||||
}
|
||||
|
||||
/* C-- SDK , (c) B. Parisse 2019 */
|
||||
|
||||
const char * read_file(const char * filename){
|
||||
#if 1
|
||||
Ion::Storage * s=Ion::Storage::sharedStorage();
|
||||
const Ion::Storage::Record r=s->recordNamed(filename);
|
||||
if (r.isNull())
|
||||
return 0;
|
||||
Ion::Storage::Record::Data d=r.value();
|
||||
const char * ptr=(const char *)d.buffer;
|
||||
if (ptr)
|
||||
return ptr+1;
|
||||
else
|
||||
return 0;
|
||||
#endif
|
||||
if (sScriptProvider != nullptr)
|
||||
return sScriptProvider->contentOfScript(filename);
|
||||
return "undef";
|
||||
}
|
||||
|
||||
bool write_file(const char * filename,const char * content,size_t len){
|
||||
Ion::Storage * s=Ion::Storage::sharedStorage();
|
||||
auto res=s->createRecordWithFullName(filename,content,strlen(content)+1);
|
||||
if (res==Ion::Storage::Record::ErrorStatus::NameTaken){
|
||||
auto r=s->recordNamed(filename);
|
||||
Ion::Storage::Record::Data d;
|
||||
d.buffer=content;
|
||||
d.size=(len?len:strlen(content))+1;
|
||||
return r.setValue(d)==Ion::Storage::Record::ErrorStatus::None;
|
||||
}
|
||||
if (res==Ion::Storage::Record::ErrorStatus::None)
|
||||
return write_file(filename,content,len);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool file_exists(const char * filename){
|
||||
Ion::Storage * s=Ion::Storage::sharedStorage();
|
||||
return s->isFullNameTaken(filename);
|
||||
}
|
||||
|
||||
bool erase_file(const char * filename){
|
||||
Ion::Storage * s=Ion::Storage::sharedStorage();
|
||||
auto r= s->recordNamed(filename);
|
||||
if (r.isNull())
|
||||
return false;
|
||||
r.destroy();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#if 1
|
||||
int os_file_browser(const char ** filenames,int maxrecords,const char * extension){
|
||||
Ion::Storage * s=Ion::Storage::sharedStorage();
|
||||
int n=s->numberOfRecordsWithExtension(extension);
|
||||
if (!n) return 0;
|
||||
if (n>maxrecords) n=maxrecords;
|
||||
for (int i=0;i<n;i++){
|
||||
const Ion::Storage::Record & r=s->recordWithExtensionAtIndex(extension, i);
|
||||
filenames[i]=r.fullName();
|
||||
}
|
||||
filenames[n]=0;
|
||||
return n;
|
||||
}
|
||||
// const char * ptr=(const char *)r.value().buffer;
|
||||
/* storage.h
|
||||
Ion::Storage::Record::Data structure avec 2 membres
|
||||
const void * buffer et size_t size
|
||||
|
||||
Record(const char * fullName = nullptr);
|
||||
Record(const char * basename, const char * extension);
|
||||
Data value();
|
||||
Ion::Storage::Record::ErrorStatus setValue(Ion::Storage::Record::Data);
|
||||
void destroy(void);
|
||||
|
||||
// Record creation
|
||||
Record::ErrorStatus createRecordWithFullName(const char * fullName, const void * data, size_t size);
|
||||
Record::ErrorStatus createRecordWithExtension(const char * baseName, const char * extension, const void * data, size_t size);
|
||||
|
||||
// Record getters
|
||||
Record recordWithExtensionAtIndex(const char * extension, int index);
|
||||
Record recordNamed(const char * fullName);
|
||||
Record recordBaseNamedWithExtension(const char * baseName, const char * extension);
|
||||
Record recordBaseNamedWithExtensions(const char * baseName, const char * const extension[], size_t numberOfExtensions);
|
||||
|
||||
// Record destruction
|
||||
void destroyAllRecords();
|
||||
void destroyRecordWithBaseNameAndExtension(const char * baseName, const char * extension);
|
||||
void destroyRecordsWithExtension(const char * extension);
|
||||
|
||||
|
||||
*/
|
||||
#endif
|
||||
|
||||
void statuslinemsg(const char * msg){
|
||||
AppsContainer::sharedAppsContainer()->reloadTitleBarView();
|
||||
auto ptr=MicroPython::ExecutionEnvironment::currentExecutionEnvironment();
|
||||
if (ptr)
|
||||
ptr->displaySandbox();
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,0,280,18));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
KDRect rect(0,0,280,18);
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,64934 /* Palette::YellowDark*/);
|
||||
if (strlen(msg)>25)
|
||||
ctx->drawString(msg, KDPoint(0,0), KDFont::SmallFont, 0, 64934);
|
||||
else
|
||||
ctx->drawString(msg, KDPoint(0,0), KDFont::LargeFont, 0, 64934);
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
}
|
||||
|
||||
bool os_set_angle_unit(int mode){
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
if (mode==0){ // rad
|
||||
preferences->setAngleUnit(Poincare::Preferences::AngleUnit::Radian);
|
||||
return true;
|
||||
}
|
||||
if (mode==1){ // deg
|
||||
preferences->setAngleUnit(Poincare::Preferences::AngleUnit::Degree);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if (mode==2){ // grad
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int os_get_angle_unit(){
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
if (preferences->angleUnit()==Poincare::Preferences::AngleUnit::Radian)
|
||||
return 0;
|
||||
if (preferences->angleUnit()==Poincare::Preferences::AngleUnit::Degree)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
#ifdef SIMULATOR
|
||||
#define TICKS_PER_MINUTE 60000
|
||||
#else
|
||||
#define TICKS_PER_MINUTE 11862
|
||||
extern const void * _stack_start;
|
||||
extern const void * _heap_start;
|
||||
#endif
|
||||
//int time_shift=0; // set it via time() command in KhiCAS
|
||||
void statusline(int mode, size_t heap){
|
||||
AppsContainer::sharedAppsContainer()->reloadTitleBarView();
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,0,320,18));
|
||||
ctx->setOrigin(KDPoint(0,0));
|
||||
KDRect rect(0,0,mode==1?320:280,18);
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,64934 /* Palette::YellowDark*/);
|
||||
const char * text=0;
|
||||
Poincare::Preferences * preferences = Poincare::Preferences::sharedPreferences();
|
||||
if (preferences->angleUnit() == Poincare::Preferences::AngleUnit::Radian)
|
||||
text="rad";
|
||||
else
|
||||
text="deg";
|
||||
// ctx->drawString(text, KDPoint(5,1), KDFont::SmallFont, 0, 63488 /* Palette::Red*/);
|
||||
ctx->drawString(text, KDPoint(5,1), KDFont::SmallFont, 0, 64934);
|
||||
#ifdef GIAC_LINKED
|
||||
if (khicas_eval)
|
||||
text="KHICAS";
|
||||
else
|
||||
text="PYTHON";
|
||||
#else
|
||||
text="KHICAS";
|
||||
#endif
|
||||
ctx->drawString(text, KDPoint(70,1), KDFont::SmallFont, 0, 64934);
|
||||
char bufheap[16];
|
||||
#if 0 //ndef SIMULATOR
|
||||
#endif
|
||||
int x;
|
||||
x=(heap&0xf0000000)>>28;
|
||||
bufheap[0]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf000000)>>24;
|
||||
bufheap[1]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf00000)>>20;
|
||||
bufheap[2]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf0000)>>16;
|
||||
bufheap[3]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf000)>>12;
|
||||
bufheap[4]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf00)>>8;
|
||||
bufheap[5]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf0)>>4;
|
||||
bufheap[6]=(x>9?'a'+(x-10):'0'+x);
|
||||
x=(heap&0xf);
|
||||
bufheap[7]=(x>9?'a'+(x-10):'0'+x);
|
||||
bufheap[8]=0;
|
||||
if(heap != 0) ctx->drawString(bufheap,KDPoint(130,1),KDFont::SmallFont, 0, 64934);
|
||||
#ifdef GIAC_SHOWTIME
|
||||
int d=(Ion::Timing::millis()/TICKS_PER_MINUTE +time_shift) % (24*60); // minutes
|
||||
char buf[32]={0,0,0,0};
|
||||
int h=d/60;
|
||||
buf[0]='0'+h/10;
|
||||
buf[1]='0'+(h%10);
|
||||
buf[2]=':';
|
||||
ctx->drawString(buf, KDPoint(148,1), KDFont::SmallFont, 0, 64934);
|
||||
int mn=d%60;
|
||||
buf[0]='0'+mn/10;
|
||||
buf[1]='0'+(mn%10);
|
||||
buf[2]=0;
|
||||
ctx->drawString(buf, KDPoint(168,1), KDFont::SmallFont, 0, 64934);
|
||||
#endif
|
||||
text=" ";
|
||||
if (Ion::Events::shiftAlphaStatus()==Ion::Events::ShiftAlphaStatus::Shift)
|
||||
text="shift ";
|
||||
else {
|
||||
if (Ion::Events::isAlphaActive()){
|
||||
if (Ion::Events::shiftAlphaStatus()==Ion::Events::ShiftAlphaStatus::AlphaLock)
|
||||
text="alphal";
|
||||
if (Ion::Events::shiftAlphaStatus()==Ion::Events::ShiftAlphaStatus::ShiftAlphaLock)
|
||||
text="ALPHAL";
|
||||
if (Ion::Events::shiftAlphaStatus()==Ion::Events::ShiftAlphaStatus::Alpha)
|
||||
text="1alpha";
|
||||
if (Ion::Events::shiftAlphaStatus()==Ion::Events::ShiftAlphaStatus::ShiftAlpha)
|
||||
text="1ALPHA";
|
||||
}
|
||||
}
|
||||
ctx->drawString(text, KDPoint(232,1), KDFont::SmallFont, 0, 64934 /* Palette::YellowDark*/);
|
||||
if (mode==1){
|
||||
if (Ion::USB::isPlugged())
|
||||
text="charge";
|
||||
else {
|
||||
auto c=Ion::Battery::level();
|
||||
if (c==Ion::Battery::Charge::EMPTY)
|
||||
text="empty ";
|
||||
if (c==Ion::Battery::Charge::LOW)
|
||||
text="low ";
|
||||
if (c==Ion::Battery::Charge::FULL)
|
||||
text="full ";
|
||||
}
|
||||
ctx->drawString(text, KDPoint(280,1), KDFont::SmallFont, 0, 64934 /* Palette::YellowDark*/);
|
||||
}
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
}
|
||||
|
||||
bool isalphaactive(){
|
||||
return Ion::Events::isAlphaActive();
|
||||
}
|
||||
|
||||
void lock_alpha(){
|
||||
Ion::Events::setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::AlphaLock);
|
||||
statusline(0,0);
|
||||
}
|
||||
|
||||
void reset_kbd(){
|
||||
Ion::Events::setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::Default);
|
||||
statusline(0,0);
|
||||
}
|
||||
|
||||
bool alphawasactive_=false;
|
||||
bool alphawasactive(){
|
||||
return alphawasactive_;
|
||||
}
|
||||
|
||||
bool waitforvblank(){
|
||||
return Ion::Display::waitForVBlank();
|
||||
}
|
||||
|
||||
bool back_key_pressed() {
|
||||
static int c = 0;
|
||||
|
||||
++c ;
|
||||
if (c<400 || (c & 0xf)!= 0) {
|
||||
return false;
|
||||
}
|
||||
#ifdef SIMULATOR
|
||||
Fl::wait(0.00001);
|
||||
#endif
|
||||
|
||||
Ion::Keyboard::State scan = Ion::Keyboard::scan();
|
||||
// if (scan!=16) std::cerr << scan << '\n';
|
||||
Ion::Keyboard::Key interruptKey = static_cast<Ion::Keyboard::Key>(mp_interrupt_char);
|
||||
if (scan.keyDown(interruptKey)
|
||||
// || scan.keyDown(static_cast<Ion::Keyboard::Key>(16))
|
||||
)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int getkey_raw(bool allow_suspend){
|
||||
int key=-1;
|
||||
size_t t1=Ion::Timing::millis();
|
||||
for (;;){
|
||||
int timeout=10000;
|
||||
alphawasactive_=Ion::Events::isAlphaActive();
|
||||
Ion::Events::Event event=Ion::Events::getEvent(&timeout);
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
KDRect save=ctx->m_clippingRect;
|
||||
KDPoint o=ctx->m_origin;
|
||||
ctx->setClippingRect(KDRect(0,0,320,240));
|
||||
ctx->setOrigin(KDPoint(0,18));
|
||||
KDRect rect(90,63,140,75);
|
||||
if (event==Ion::Events::None){
|
||||
size_t t2=Ion::Timing::millis();
|
||||
if (t2-t1>2*TICKS_PER_MINUTE){
|
||||
// KDIonContext::sharedContext()->pushRectUniform(rect,64934 /* Palette::YellowDark*/);
|
||||
event=Ion::Events::OnOff;
|
||||
}
|
||||
}
|
||||
else
|
||||
t1=Ion::Timing::millis();
|
||||
if (event == Ion::Events::USBPlug) {
|
||||
statusline(0,0);
|
||||
// KDIonContext::sharedContext()->pushRectUniform(rect,33333);
|
||||
if (Ion::USB::isPlugged()) {
|
||||
if (GlobalPreferences::sharedGlobalPreferences()->examMode()) {
|
||||
Ion::LED::setColor(KDColorBlack);
|
||||
Ion::LED::updateColorWithPlugAndCharge();
|
||||
GlobalPreferences::sharedGlobalPreferences()->setExamMode(false);
|
||||
// displayExamModePopUp(false);
|
||||
} else {
|
||||
Ion::USB::enable();
|
||||
}
|
||||
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
|
||||
} else {
|
||||
Ion::USB::disable();
|
||||
}
|
||||
}
|
||||
if (event == Ion::Events::USBEnumeration || event == Ion::Events::USBPlug || event == Ion::Events::BatteryCharging) {
|
||||
Ion::LED::updateColorWithPlugAndCharge();
|
||||
}
|
||||
if (event == Ion::Events::USBEnumeration
|
||||
) {
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,64934 /* Palette::YellowDark*/);
|
||||
if (Ion::USB::isPlugged()) {
|
||||
/* Just after a software update, the battery timer does not have time to
|
||||
* fire before the calculator enters DFU mode. As the DFU mode blocks the
|
||||
* event loop, we update the battery state "manually" here.
|
||||
* We do it before switching to USB application to redraw the battery
|
||||
* pictogram. */
|
||||
// updateBatteryState();
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,22222);
|
||||
auto ctx=KDIonContext::sharedContext();
|
||||
int y=58;
|
||||
ctx->drawString("Connecte ! ", KDPoint(100,y), KDFont::LargeFont, 65535, 0);
|
||||
y+=18;
|
||||
ctx->drawString(" DFU mode ", KDPoint(100,y), KDFont::LargeFont, 65535, 0);
|
||||
y+=18;
|
||||
ctx->drawString("Back quitte", KDPoint(100,y), KDFont::LargeFont, 65535, 0);
|
||||
y-=18;
|
||||
Ion::USB::DFU();
|
||||
KDIonContext::sharedContext()->pushRectUniform(rect,44444);
|
||||
ctx->drawString("Deconnecte!", KDPoint(100,y), KDFont::LargeFont, 65535, 0);
|
||||
// Update LED when exiting DFU mode
|
||||
Ion::LED::updateColorWithPlugAndCharge();
|
||||
} else {
|
||||
/* Sometimes, the device gets an ENUMDNE interrupts when being unplugged
|
||||
* from a non-USB communicating host (e.g. a USB charger). The interrupt
|
||||
* must me cleared: if not the next enumeration attempts will not be
|
||||
* detected. */
|
||||
Ion::USB::clearEnumerationInterrupt();
|
||||
}
|
||||
}
|
||||
if (event.isKeyboardEvent()) {
|
||||
// m_backlightDimmingTimer.reset();
|
||||
// m_suspendTimer.reset();
|
||||
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
|
||||
}
|
||||
ctx->setClippingRect(save);
|
||||
ctx->setOrigin(o);
|
||||
|
||||
if (event==Ion::Events::Shift || event==Ion::Events::Alpha){
|
||||
statusline(0,0);
|
||||
continue;
|
||||
}
|
||||
if (event.isKeyboardEvent()){
|
||||
key=event.id();
|
||||
if (key==17 || key==4 || key==5 || key==52)
|
||||
reset_kbd();
|
||||
if (allow_suspend && (key==7 || key==8) ){ // power
|
||||
Ion::Power::suspend(true);
|
||||
numworks_fill_rect(0,0,320,240,65535);
|
||||
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
|
||||
AppsContainer::sharedAppsContainer()->reloadTitleBarView();
|
||||
//AppsContainer::sharedAppsContainer()->redrawWindow();
|
||||
statusline(1,0);
|
||||
//continue;
|
||||
}
|
||||
else
|
||||
statusline(0,0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
const short int translated_keys[]=
|
||||
{
|
||||
// non shifted
|
||||
KEY_CTRL_LEFT,KEY_CTRL_UP,KEY_CTRL_DOWN,KEY_CTRL_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,KEY_CTRL_XTT,KEY_CTRL_VARS,KEY_CTRL_CATALOG,KEY_CTRL_DEL,
|
||||
KEY_CHAR_EXPN,KEY_CHAR_LN,KEY_CHAR_LOG,KEY_CHAR_IMGNRY,',',KEY_CHAR_POW,
|
||||
KEY_CHAR_SIN,KEY_CHAR_COS,KEY_CHAR_TAN,KEY_CHAR_PI,KEY_CHAR_ROOT,KEY_CHAR_SQUARE,
|
||||
'7','8','9','(',')',-1,
|
||||
'4','5','6','*','/',-1,
|
||||
'1','2','3','+','-',-1,
|
||||
'0','.',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
// shifted
|
||||
KEY_SHIFT_LEFT,KEY_CTRL_PAGEUP,KEY_CTRL_PAGEDOWN,KEY_SHIFT_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,KEY_CTRL_CUT,KEY_CTRL_CLIP,KEY_CTRL_PASTE,KEY_CTRL_AC,
|
||||
KEY_CHAR_LBRCKT,KEY_CHAR_RBRCKT,KEY_CHAR_LBRACE,KEY_CHAR_RBRACE,'_',KEY_CHAR_STORE,
|
||||
KEY_CHAR_ASIN,KEY_CHAR_ACOS,KEY_CHAR_ATAN,'=','<','>',
|
||||
KEY_CTRL_F7,KEY_CTRL_F8,KEY_CTRL_F9,KEY_CTRL_F13,KEY_CTRL_F14,-1,
|
||||
KEY_CTRL_F4,KEY_CTRL_F5,KEY_CTRL_F6,KEY_CHAR_FACTOR,'%',-1,
|
||||
KEY_CTRL_F1,KEY_CTRL_F2,KEY_CTRL_F3,KEY_CHAR_NORMAL,'\\',-1,
|
||||
KEY_CTRL_F10,KEY_CTRL_F11,KEY_CTRL_F12,KEY_SHIFT_ANS,KEY_CTRL_EXE,-1,
|
||||
// alpha
|
||||
KEY_CTRL_LEFT,KEY_CTRL_UP,KEY_CTRL_DOWN,KEY_CTRL_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,':',';','"',KEY_CTRL_DEL,
|
||||
'a','b','c','d','e','f',
|
||||
'g','h','i','j','k','l',
|
||||
'm','n','o','p','q',-1,
|
||||
'r','s','t','u','v',-1,
|
||||
'w','x','y','z',' ',-1,
|
||||
'?','!',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
// alpha shifted
|
||||
KEY_SHIFT_LEFT,KEY_CTRL_PAGEUP,KEY_CTRL_PAGEDOWN,KEY_SHIFT_RIGHT,KEY_CTRL_OK,KEY_CTRL_EXIT,
|
||||
KEY_CTRL_MENU,KEY_PRGM_ACON,KEY_PRGM_ACON,9,10,11,
|
||||
KEY_CTRL_SHIFT,KEY_CTRL_ALPHA,':',';','\'','%',
|
||||
'A','B','C','D','E','F',
|
||||
'G','H','I','J','K','L',
|
||||
'M','N','O','P','Q',-1,
|
||||
'R','S','T','U','V',-1,
|
||||
'W','X','Y','Z',' ',-1,
|
||||
'?','!',KEY_CHAR_EXPN10,KEY_CHAR_ANS,KEY_CTRL_EXE,-1,
|
||||
};
|
||||
|
||||
int getkey(bool allow_suspend){
|
||||
int k=getkey_raw(allow_suspend);
|
||||
// translate
|
||||
return translated_keys[k];
|
||||
}
|
||||
|
||||
// Casio prototype
|
||||
void GetKey(int * key){
|
||||
*key=getkey(true);
|
||||
}
|
||||
|
||||
|
||||
void numworks_wait_1ms(int ms){
|
||||
for (int i=0;i<ms/128;++i){
|
||||
#ifdef SIMULATOR
|
||||
Fl::wait(0.00001);
|
||||
#endif
|
||||
Ion::Keyboard::State scan = Ion::Keyboard::scan();
|
||||
// if (scan!=16) std::cerr << scan << '\n';
|
||||
Ion::Keyboard::Key interruptKey = static_cast<Ion::Keyboard::Key>(Ion::Keyboard::Key::Back);
|
||||
if (scan.keyDown(interruptKey))
|
||||
return;
|
||||
Ion::Timing::msleep(128);
|
||||
}
|
||||
Ion::Timing::msleep(ms % 128);
|
||||
}
|
||||
|
||||
void enable_back_interrupt(){
|
||||
mp_interrupt_char = (int)Ion::Keyboard::Key::Back;
|
||||
}
|
||||
|
||||
void disable_back_interrupt(){
|
||||
mp_interrupt_char = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,212 +36,4 @@ void registerScriptProvider(ScriptProvider * s);
|
||||
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
basic SDK for direct control of the calculator like in KhiCAS
|
||||
*/
|
||||
bool waitforvblank();
|
||||
int os_file_browser(const char ** filenames,int maxrecords,const char * extension);
|
||||
void numworks_hide_graph();
|
||||
void numworks_show_graph();
|
||||
void enable_back_interrupt();
|
||||
void disable_back_interrupt();
|
||||
int os_get_angle_unit();
|
||||
bool os_set_angle_unit(int mode);
|
||||
const char * read_file(const char * filename);
|
||||
bool write_file(const char * filename,const char * content,size_t len);
|
||||
int getkey_raw(bool allow_suspend); // Numworks scan code
|
||||
int getkey(bool allow_suspend); // transformed
|
||||
void GetKey(int * key); // Casio like
|
||||
bool isalphaactive();
|
||||
bool alphawasactive(); // alpha status before getkey
|
||||
bool back_key_pressed() ;
|
||||
void lock_alpha();
|
||||
void reset_kbd();
|
||||
void statusline(int mode=0, size_t=0); // display status line
|
||||
void statuslinemsg(const char * msg); // display a message in statusline
|
||||
void numworks_fill_rect(int x,int y,int w,int h,int c); // y=0 is automatically translated by 18 for statusline
|
||||
void numworks_set_pixel(int x,int y,int c);
|
||||
int numworks_get_pixel(int x,int y);
|
||||
/* draw_string returns new x position, use fake=true to compute without drawing */
|
||||
int numworks_draw_string(int x,int y,int c,int bg,const char * s,bool fake=false);
|
||||
int numworks_draw_string_small(int x,int y,int c,int bg,const char * s,bool fake=false);
|
||||
// scriptstore
|
||||
bool file_exists(const char * filename);
|
||||
bool erase_file(const char * filename);
|
||||
const char * read_file(const char * filename);
|
||||
bool write_file(const char * filename,const char * s,size_t len=0);
|
||||
int giac_filebrowser(char * filename,const char * extension,const char * title);
|
||||
void numworks_wait_1ms(int ms);
|
||||
//double millis();
|
||||
//extern int time_shift; // shift for the clock
|
||||
|
||||
|
||||
// Character codes
|
||||
#define KEY_CHAR_0 0x30
|
||||
#define KEY_CHAR_1 0x31
|
||||
#define KEY_CHAR_2 0x32
|
||||
#define KEY_CHAR_3 0x33
|
||||
#define KEY_CHAR_4 0x34
|
||||
#define KEY_CHAR_5 0x35
|
||||
#define KEY_CHAR_6 0x36
|
||||
#define KEY_CHAR_7 0x37
|
||||
#define KEY_CHAR_8 0x38
|
||||
#define KEY_CHAR_9 0x39
|
||||
#define KEY_CHAR_DP 0x2e
|
||||
#define KEY_CHAR_EXP 0x0f
|
||||
#define KEY_CHAR_PMINUS 30200
|
||||
#define KEY_CHAR_PLUS 43
|
||||
#define KEY_CHAR_MINUS 45
|
||||
#define KEY_CHAR_MULT 42
|
||||
#define KEY_CHAR_DIV 47
|
||||
#define KEY_CHAR_FRAC 0xbb
|
||||
#define KEY_CHAR_LPAR 0x28
|
||||
#define KEY_CHAR_RPAR 0x29
|
||||
#define KEY_CHAR_COMMA 0x2c
|
||||
#define KEY_CHAR_STORE 0x0e
|
||||
#define KEY_CHAR_LOG 0x95
|
||||
#define KEY_CHAR_LN 0x85
|
||||
#define KEY_CHAR_SIN 0x81
|
||||
#define KEY_CHAR_COS 0x82
|
||||
#define KEY_CHAR_TAN 0x83
|
||||
#define KEY_CHAR_SQUARE 0x8b
|
||||
#define KEY_CHAR_POW 0xa8
|
||||
#define KEY_CHAR_IMGNRY 0x7f50
|
||||
#define KEY_CHAR_LIST 0x7f51
|
||||
#define KEY_CHAR_MAT 0x7f40
|
||||
#define KEY_CHAR_EQUAL 0x3d
|
||||
#define KEY_CHAR_PI 0xd0
|
||||
#define KEY_CHAR_ANS 0xc0
|
||||
#define KEY_SHIFT_ANS 0xc1
|
||||
#define KEY_CHAR_LBRCKT 0x5b
|
||||
#define KEY_CHAR_RBRCKT 0x5d
|
||||
#define KEY_CHAR_LBRACE 0x7b
|
||||
#define KEY_CHAR_RBRACE 0x7d
|
||||
#define KEY_CHAR_CR 0x0d
|
||||
#define KEY_CHAR_CUBEROOT 0x96
|
||||
#define KEY_CHAR_RECIP 0x9b
|
||||
#define KEY_CHAR_ANGLE 0x7f54
|
||||
#define KEY_CHAR_EXPN10 0xb5
|
||||
#define KEY_CHAR_EXPN 0xa5
|
||||
#define KEY_CHAR_ASIN 0x91
|
||||
#define KEY_CHAR_ACOS 0x92
|
||||
#define KEY_CHAR_ATAN 0x93
|
||||
#define KEY_CHAR_ROOT 0x86
|
||||
#define KEY_CHAR_POWROOT 0xb8
|
||||
#define KEY_CHAR_SPACE 0x20
|
||||
#define KEY_CHAR_DQUATE 0x22
|
||||
#define KEY_CHAR_VALR 0xcd
|
||||
#define KEY_CHAR_THETA 0xce
|
||||
#define KEY_CHAR_FACTOR 0xda
|
||||
#define KEY_CHAR_NORMAL 0xdb
|
||||
#define KEY_CHAR_A 0x41
|
||||
#define KEY_CHAR_B 0x42
|
||||
#define KEY_CHAR_C 0x43
|
||||
#define KEY_CHAR_D 0x44
|
||||
#define KEY_CHAR_E 0x45
|
||||
#define KEY_CHAR_F 0x46
|
||||
#define KEY_CHAR_G 0x47
|
||||
#define KEY_CHAR_H 0x48
|
||||
#define KEY_CHAR_I 0x49
|
||||
#define KEY_CHAR_J 0x4a
|
||||
#define KEY_CHAR_K 0x4b
|
||||
#define KEY_CHAR_L 0x4c
|
||||
#define KEY_CHAR_M 0x4d
|
||||
#define KEY_CHAR_N 0x4e
|
||||
#define KEY_CHAR_O 0x4f
|
||||
#define KEY_CHAR_P 0x50
|
||||
#define KEY_CHAR_Q 0x51
|
||||
#define KEY_CHAR_R 0x52
|
||||
#define KEY_CHAR_S 0x53
|
||||
#define KEY_CHAR_T 0x54
|
||||
#define KEY_CHAR_U 0x55
|
||||
#define KEY_CHAR_V 0x56
|
||||
#define KEY_CHAR_W 0x57
|
||||
#define KEY_CHAR_X 0x58
|
||||
#define KEY_CHAR_Y 0x59
|
||||
#define KEY_CHAR_Z 0x5a
|
||||
|
||||
|
||||
// Control codes
|
||||
#define KEY_CTRL_NOP 30202
|
||||
#define KEY_CTRL_EXE 30201
|
||||
#define KEY_CTRL_DEL 30025
|
||||
#define KEY_CTRL_AC 30070
|
||||
#define KEY_CTRL_FD 30046
|
||||
#define KEY_CTRL_UNDO 30045
|
||||
#define KEY_CTRL_XTT 30001
|
||||
#define KEY_CTRL_EXIT 5
|
||||
#define KEY_CTRL_OK 4
|
||||
#define KEY_CTRL_SHIFT 30006
|
||||
#define KEY_CTRL_ALPHA 30007
|
||||
#define KEY_CTRL_OPTN 30008
|
||||
#define KEY_CTRL_VARS 30030
|
||||
#define KEY_CTRL_UP 1
|
||||
#define KEY_CTRL_DOWN 2
|
||||
#define KEY_CTRL_LEFT 0
|
||||
#define KEY_CTRL_RIGHT 3
|
||||
#define KEY_CTRL_F1 30009
|
||||
#define KEY_CTRL_F2 30010
|
||||
#define KEY_CTRL_F3 30011
|
||||
#define KEY_CTRL_F4 30012
|
||||
#define KEY_CTRL_F5 30013
|
||||
#define KEY_CTRL_F6 30014
|
||||
#define KEY_CTRL_F7 30015
|
||||
#define KEY_CTRL_F8 30016
|
||||
#define KEY_CTRL_F9 30017
|
||||
#define KEY_CTRL_F10 30018
|
||||
#define KEY_CTRL_F11 30019
|
||||
#define KEY_CTRL_F12 30020
|
||||
#define KEY_CTRL_F13 30021
|
||||
#define KEY_CTRL_F14 30022
|
||||
#define KEY_CTRL_CATALOG 30100
|
||||
#define KEY_CTRL_CAPTURE 30055
|
||||
#define KEY_CTRL_CLIP 30050
|
||||
#define KEY_CTRL_CUT 30250
|
||||
#define KEY_CTRL_PASTE 30036
|
||||
#define KEY_CTRL_INS 30033
|
||||
#define KEY_CTRL_MIXEDFRAC 30054
|
||||
#define KEY_CTRL_FRACCNVRT 30026
|
||||
#define KEY_CTRL_QUIT 30029
|
||||
#define KEY_CTRL_PRGM 30028
|
||||
#define KEY_CTRL_SETUP 30037
|
||||
#define KEY_CTRL_PAGEUP 30052
|
||||
#define KEY_CTRL_PAGEDOWN 30053
|
||||
#define KEY_CTRL_MENU 30003
|
||||
#define KEY_SHIFT_OPTN 30059
|
||||
#define KEY_CTRL_RESERVE1 30060
|
||||
#define KEY_CTRL_RESERVE2 30061
|
||||
#define KEY_SHIFT_LEFT 30062
|
||||
#define KEY_SHIFT_RIGHT 30063
|
||||
|
||||
#define KEY_PRGM_ACON 10
|
||||
#define KEY_PRGM_DOWN 37
|
||||
#define KEY_PRGM_EXIT 47
|
||||
#define KEY_PRGM_F1 79
|
||||
#define KEY_PRGM_F2 69
|
||||
#define KEY_PRGM_F3 59
|
||||
#define KEY_PRGM_F4 49
|
||||
#define KEY_PRGM_F5 39
|
||||
#define KEY_PRGM_F6 29
|
||||
#define KEY_PRGM_LEFT 38
|
||||
#define KEY_PRGM_NONE 0
|
||||
#define KEY_PRGM_RETURN 31
|
||||
#define KEY_PRGM_RIGHT 27
|
||||
#define KEY_PRGM_UP 28
|
||||
#define KEY_PRGM_1 72
|
||||
#define KEY_PRGM_2 62
|
||||
#define KEY_PRGM_3 52
|
||||
#define KEY_PRGM_4 73
|
||||
#define KEY_PRGM_5 63
|
||||
#define KEY_PRGM_6 53
|
||||
#define KEY_PRGM_7 74
|
||||
#define KEY_PRGM_8 64
|
||||
#define KEY_PRGM_9 54
|
||||
#define KEY_PRGM_A 76
|
||||
#define KEY_PRGM_F 26
|
||||
#define KEY_PRGM_ALPHA 77
|
||||
#define KEY_PRGM_SHIFT 78
|
||||
#define KEY_PRGM_MENU 48
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user