[external] Updated for compatibility with KhiCAS

This commit is contained in:
Yaya-Cout
2022-04-29 21:55:50 +02:00
committed by Laury
parent 5b7bdc1ec1
commit 03ae762b4a
26 changed files with 395 additions and 125 deletions

View File

@@ -40,9 +40,10 @@ bool isExamModeAndFileNotExecutable(const TarHeader* tar) {
}
bool fileAtIndex(size_t index, File &entry) {
if (index == -1)
if (index == -1) {
return false;
}
const TarHeader* tar = reinterpret_cast<const TarHeader*>(0x90200000);
unsigned size = 0;
@@ -74,6 +75,8 @@ bool fileAtIndex(size_t index, File &entry) {
entry.data = reinterpret_cast<const uint8_t*>(tar) + sizeof(TarHeader);
entry.dataLength = size;
entry.isExecutable = (tar->mode[4] & 0x01) == 1;
// TODO: Handle the trash
entry.readable = true;
return true;
} else {
@@ -111,18 +114,31 @@ uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) {
return -1;
}
int indexFromName(const char *name) {
File entry;
for (int i = 0; fileAtIndex(i, entry); i++) {
if (strcmp(name, entry.name) == 0) {
return i;
}
#else
bool fileAtIndex(size_t index, File &entry) {
if (index != 0) {
return false;
}
return -1;
entry.name = "Built-in";
entry.data = NULL;
entry.dataLength = 0;
entry.isExecutable = true;
entry.readable = true;
return true;
}
extern "C" void extapp_main(void);
uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) {
extapp_main();
return 0;
}
#endif
size_t numberOfFiles() {
File dummy;
size_t count;
@@ -132,6 +148,18 @@ size_t numberOfFiles() {
return count;
}
int indexFromName(const char *name) {
File entry;
for (int i = 0; fileAtIndex(i, entry); i++) {
if (entry.readable && strcmp(name, entry.name) == 0) {
return i;
}
}
return -1;
}
bool executableAtIndex(size_t index, File &entry) {
File dummy;
size_t count;
@@ -144,16 +172,19 @@ bool executableAtIndex(size_t index, File &entry) {
entry.data = dummy.data;
entry.dataLength = dummy.dataLength;
entry.isExecutable = dummy.isExecutable;
entry.readable = dummy.readable;
return true;
}
final_count++;
}
}
return false;
}
size_t numberOfExecutables() {
if (!GlobalPreferences::sharedGlobalPreferences()->externalAppShown()) {
return false;
}
File dummy;
size_t count;
size_t final_count = 0;
@@ -165,48 +196,5 @@ size_t numberOfExecutables() {
return final_count;
}
#else
bool fileAtIndex(size_t index, File &entry) {
if (index != 0)
return false;
entry.name = "Built-in";
entry.data = NULL;
entry.dataLength = 0;
entry.isExecutable = true;
return true;
}
bool executableAtIndex(size_t index, File &entry) {
return fileAtIndex(index, entry);
}
size_t numberOfExecutables() {
return 1;
}
extern "C" void extapp_main(void);
uint32_t executeFile(const char *name, void * heap, const uint32_t heapSize) {
extapp_main();
return 0;
}
int indexFromName(const char *name) {
if (strcmp(name, "Built-in") == 0)
return 0;
else
return -1;
}
size_t numberOfFiles() {
return 1;
}
#endif
}
}

View File

@@ -14,6 +14,7 @@ struct File {
const uint8_t *data;
size_t dataLength;
bool isExecutable;
bool readable;
};
bool fileAtIndex(size_t index, File &entry);

View File

@@ -9,10 +9,16 @@
#include "../apps_container.h"
#include "../global_preferences.h"
#ifdef DEVICE
#include <ion/src/device/shared/drivers/reset.h>
#include <ion/src/device/shared/drivers/board.h>
#include <ion/src/device/shared/drivers/flash.h>
#endif
#include <python/port/port.h>
extern "C" {
#include <python/port/mphalport.h>
#include <python/port/mphalport.h>
}
uint64_t extapp_millis() {
@@ -30,7 +36,7 @@ uint64_t extapp_scanKeyboard() {
void extapp_pushRect(int16_t x, int16_t y, uint16_t w, uint16_t h, const uint16_t * pixels) {
KDRect rect(x, y, w, h);
Ion::Display::pushRect(rect, reinterpret_cast<const KDColor*>(pixels));
Ion::Display::pushRect(rect, reinterpret_cast<const KDColor *>(pixels));
}
void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color) {
@@ -42,10 +48,10 @@ void extapp_pushRectUniform(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16
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);
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) {
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();
@@ -56,7 +62,7 @@ int16_t extapp_drawTextLarge(const char *text, int16_t x, int16_t y, uint16_t fg
return point.x();
}
int16_t extapp_drawTextSmall(const char *text, int16_t x, int16_t y, uint16_t fg, uint16_t bg, bool fake) {
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();
@@ -71,7 +77,7 @@ bool extapp_waitForVBlank() {
return Ion::Display::waitForVBlank();
}
void extapp_clipboardStore(const char *text) {
void extapp_clipboardStore(const char * text) {
Clipboard::sharedClipboard()->store(text);
}
@@ -79,101 +85,103 @@ const char * extapp_clipboardText() {
return Clipboard::sharedClipboard()->storedText();
}
bool match(const char * filename, const char * extension) {
return strcmp(filename + strlen(filename) - strlen(extension), extension) == 0;
}
int extapp_fileListWithExtension(const char ** filenames, int maxrecords, const char * extension, int storage) {
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
int j = 0;
if (storage == EXTAPP_RAM_FILE_SYSTEM || storage == EXTAPP_BOTH_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();
for (; j < n; j++) {
filenames[j] = Ion::Storage::sharedStorage()->recordWithExtensionAtIndex(extension, j).fullName();
}
return n;
} else if(storage == EXTAPP_FLASH_FILE_SYSTEM) {
// TODO: filter by extension
int n = External::Archive::numberOfFiles();
if (n > maxrecords) {
n = maxrecords;
if (j == maxrecords) {
return j;
}
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;
}
// Don't read external files the exam mode is enabled
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) return j;
if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) {
int n = External::Archive::numberOfFiles();
for (int i = 0; i < n && j < maxrecords; i++) {
External::Archive::File entry;
// Filter extension
if (External::Archive::fileAtIndex(i, entry) && match(entry.name, extension)) {
filenames[j] = entry.name;
++j;
}
}
}
return j;
}
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;
if (storage == EXTAPP_RAM_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) {
if (!Ion::Storage::sharedStorage()->recordNamed(filename).isNull())
return true;
}
if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) {
return External::Archive::indexFromName(filename) >= 0;
}
return false;
}
bool extapp_fileErase(const char * filename, int storage) {
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
if (storage == EXTAPP_RAM_FILE_SYSTEM) {
Ion::Storage::Record record = Ion::Storage::sharedStorage()->recordNamed(filename);
if(record.isNull()) {
if (record.isNull()) {
return false;
} else {
record.destroy();
return true;
}
} else {
return false;
record.destroy();
return true;
}
return false;
}
const char * extapp_fileRead(const char * filename, size_t *len, int storage) {
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
const char * extapp_fileRead(const char * filename, size_t * len, int storage) {
if (storage == EXTAPP_RAM_FILE_SYSTEM || storage == EXTAPP_BOTH_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;
if (!record.isNull()){
int delta = 0;
if (match(filename, ".py") || match(filename, ".xw"))
delta++;
// skip record type
if (len)
*len = record.value().size - delta;
return (const char *)record.value().buffer + delta;
}
} else if(storage == EXTAPP_FLASH_FILE_SYSTEM) {
}
if (storage == EXTAPP_FLASH_FILE_SYSTEM || storage == EXTAPP_BOTH_FILE_SYSTEM) {
int index = External::Archive::indexFromName(filename);
if (index >= 0) {
External::Archive::File entry;
External::Archive::fileAtIndex(index, entry);
if(len) {
if (len) {
*len = entry.dataLength;
}
return (const char *)entry.data;
} else {
return NULL;
}
} else {
return NULL;
}
return NULL;
}
bool extapp_fileWrite(const char * filename, const char * content, size_t len, int storage) {
if(storage == EXTAPP_RAM_FILE_SYSTEM) {
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;
if (status == Ion::Storage::Record::ErrorStatus::None)
return true;
}
return false;
}
static void reloadTitleBar() {
@@ -244,19 +252,42 @@ const int16_t translated_keys[] =
#define TICKS_PER_MINUTE 11862
#endif
int extapp_getKey(bool allowSuspend, bool *alphaWasActive) {
int extapp_restoreBackup(int mode) {
// Restoring the backup is allowed even if the write protection is enabled, because it may have been writted by Khi.x
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode())
return 0;
size_t length = 32 * 1024;
if (mode == -1) { // restore backup saved when exam mode was set
uint8_t * src = (uint8_t *)(0x90800000 - 2 * length);
if (src[0] == 0xba && src[1] == 0xdd && src[2] == 0x0b && src[3] == 0xee) {
memcpy((uint8_t *)Ion::storageAddress(), src, length);
return 1;
}
}
if (mode >= 0 && mode < 16) {
uint8_t * src = (uint8_t *)(0x90180000 + mode * length);
if (src[0] == 0xba && src[1] == 0xdd && src[2] == 0x0b && src[3] == 0xee) {
memcpy((uint8_t *)Ion::storageAddress(), src, length);
return 1;
}
}
return 0;
}
int extapp_getKey(int allowSuspend, bool * alphaWasActive) {
int key = -1;
size_t t1 = Ion::Timing::millis();
for (;;) {
int timeout = 10000;
if(alphaWasActive) {
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) {
if (t2 - t1 > 3 * TICKS_PER_MINUTE) {
event = Ion::Events::OnOff;
}
} else {
@@ -270,10 +301,10 @@ int extapp_getKey(bool allowSuspend, bool *alphaWasActive) {
}
if (event.isKeyboardEvent()) {
key = static_cast<uint8_t>(event);
if (key == 17 || key == 4 || key == 5 || key == 52) {
if (key == (int)Ion::Keyboard::Key::Backspace || key == (int)Ion::Keyboard::Key::OK || key == (int)Ion::Keyboard::Key::Back || key == (int)Ion::Keyboard::Key::EXE) {
extapp_resetKeyboard();
}
if (allowSuspend && (key == 7 || key == 8)) { // power
if (allowSuspend && key == (int)Ion::Keyboard::Key::OnOff) {
Ion::Power::suspend(true);
extapp_pushRectUniform(0, 0, 320, 240, 65535);
Ion::Backlight::setBrightness(GlobalPreferences::sharedGlobalPreferences()->brightnessLevel());
@@ -285,6 +316,45 @@ int extapp_getKey(bool allowSuspend, bool *alphaWasActive) {
return translated_keys[key];
}
bool extapp_isKeydown(int key) {
Ion::Keyboard::State scan = Ion::Keyboard::scan();
return scan.keyDown(Ion::Keyboard::Key(key));
}
bool extapp_eraseSector(void * ptr) {
#ifdef DEVICE
if (ptr == 0)
Ion::Device::Reset::core();
// Disable flash writting
if (GlobalPreferences::sharedGlobalPreferences()->externalAppWritePermission()) {
int i = Ion::Device::Flash::SectorAtAddress((size_t)ptr);
if (i < 0)
return false;
Ion::Device::Flash::EraseSector(i);
return true;
}
#endif
return false;
}
bool extapp_writeMemory(unsigned char * dest, const unsigned char * data, size_t length) {
#ifdef DEVICE
// Disable flash writting
if (GlobalPreferences::sharedGlobalPreferences()->externalAppWritePermission()) {
int n = Ion::Device::Flash::SectorAtAddress((uint32_t)dest);
if (n < 0)
return false;
Ion::Device::Flash::WriteMemory(dest, (unsigned char *)data, length);
return true;
}
#endif
return false;
}
bool extapp_inExamMode() {
return GlobalPreferences::sharedGlobalPreferences()->isInExamMode();
}
extern "C" void (* const apiPointers[])(void) = {
(void (*)(void)) extapp_millis,
(void (*)(void)) extapp_msleep,
@@ -305,5 +375,10 @@ extern "C" void (* const apiPointers[])(void) = {
(void (*)(void)) extapp_lockAlpha,
(void (*)(void)) extapp_resetKeyboard,
(void (*)(void)) extapp_getKey,
(void (*)(void)) extapp_isKeydown,
(void (*)(void)) extapp_restoreBackup,
(void (*)(void)) extapp_eraseSector,
(void (*)(void)) extapp_writeMemory,
(void (*)(void)) extapp_inExamMode,
(void (*)(void)) nullptr,
};
};

View File

@@ -18,6 +18,7 @@
#define EXTAPP_RAM_FILE_SYSTEM 0
#define EXTAPP_FLASH_FILE_SYSTEM 1
#define EXTAPP_BOTH_FILE_SYSTEM 2
#define SCANCODE_Left ((uint64_t)1 << 0)
#define SCANCODE_Up ((uint64_t)1 << 1)
@@ -251,6 +252,10 @@ EXTERNC const char * extapp_fileRead(const char * filename, size_t *len, int sto
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);
EXTERNC int extapp_getKey(int allowSuspend, bool *alphaWasActive);
EXTERNC bool extapp_isKeydown(int key);
EXTERNC int extapp_restoreBackup(int mode); // Keep for compatibility with KhiCAS on Khi
EXTERNC bool extapp_eraseSector(void * ptr);
EXTERNC bool extapp_writeMemory(unsigned char * dest,const unsigned char * data,size_t length);
#endif

View File

@@ -51,6 +51,10 @@ public:
void setIdleBeforeDimmingSeconds(int m_idleBeforeDimmingSeconds);
int brightnessShortcut() const { return m_brightnessShortcut; }
void setBrightnessShortcut(int m_BrightnessShortcut);
bool externalAppWritePermission() const { return m_externalAppWritePermission; }
void setExternalAppWritePermission(bool extapp_write) { m_externalAppWritePermission = extapp_write; }
bool externalAppShown() const { return m_externalAppShown; }
void setExternalAppShown(bool externalAppShown) { m_externalAppShown = externalAppShown; }
private:
static_assert(I18n::NumberOfLanguages > 0, "I18n::NumberOfLanguages is not superior to 0"); // There should already have been an error when processing an empty EPSILON_I18N flag
static_assert(I18n::NumberOfCountries > 0, "I18n::NumberOfCountries is not superior to 0"); // There should already have been an error when processing an empty EPSILON_COUNTRIES flag
@@ -69,6 +73,8 @@ private:
m_idleBeforeSuspendSeconds(55),
m_idleBeforeDimmingSeconds(45),
m_brightnessShortcut(4),
m_externalAppWritePermission(false),
m_externalAppShown(true),
m_font(KDFont::LargeFont) {}
I18n::Language m_language;
I18n::Country m_country;
@@ -86,6 +92,8 @@ private:
int m_idleBeforeSuspendSeconds;
int m_idleBeforeDimmingSeconds;
int m_brightnessShortcut;
bool m_externalAppWritePermission;
bool m_externalAppShown;
const KDFont * m_font;
};

View File

@@ -26,6 +26,7 @@ app_settings_src = $(addprefix apps/settings/,\
sub_menu/math_options_controller.cpp \
sub_menu/selectable_view_with_messages.cpp \
sub_menu/usb_protection_controller.cpp \
sub_menu/external_controller.cpp \
sub_menu/brightness_controller.cpp\
)

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Leer "
SymbolArgDefaultFunction = "Argument "
MemUse = "Speicher"
DateTime = "Datum/Uhrzeit"
ExternalApps = "Externe Apps"
ActivateClock = "Uhr aktivieren"
Date = "Datum"
Time = "Uhrzeit"
@@ -84,3 +85,8 @@ Normal = "Normal"
IdleTimeBeforeDimming = "Abdunkeln nach (s)"
IdleTimeBeforeSuspend = "Anhalten nach (s)"
BrightnessShortcut = "Tastenkombinationsschritte"
ExtAppWrite = "Schreiben aktiviert"
ExtAppWriteExplanation1 = "Standardmäßig externe Anwendungen"
ExtAppWriteExplanation2 = "kann nicht in den Speicher schreiben"
ExtAppWriteExplanation3 = "Flash (dauerhaft) Ihres Rechners."
ExtAppEnabled = "Aufstecken"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Empty "
SymbolArgDefaultFunction = "Argument "
MemUse = "Memory"
DateTime = "Date/time"
ExternalApps = "External Apps"
ActivateClock = "Activate clock"
Date = "Date"
Time = "Time"
@@ -84,3 +85,8 @@ Normal = "Normal"
IdleTimeBeforeDimming = "Dim after (s)"
IdleTimeBeforeSuspend = "Suspend after (s)"
BrightnessShortcut = "Shortcut steps"
ExtAppWrite = "Write allowed"
ExtAppWriteExplanation1 = "By default, external applications"
ExtAppWriteExplanation2 = "cannot write to memory"
ExtAppWriteExplanation3 = "flash (persistent) of your calculator."
ExtAppEnabled = "Pin up"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Vacío "
SymbolArgDefaultFunction = "Argumento "
MemUse = "Memoria"
DateTime = "Fecha/Hora"
ExternalApps = "Aplicaciones externas"
ActivateClock = "Activar el reloj"
Date = "Fecha"
Time = "Hora"
@@ -84,3 +85,8 @@ Normal = "Normal"
IdleTimeBeforeDimming = "Oscurecer después de (s)"
IdleTimeBeforeSuspend = "Suspender después de (s)"
BrightnessShortcut = "Pasos de acceso directo"
ExtAppWrite = "Escritura habilitada"
ExtAppWriteExplanation1 = "Por defecto, las aplicaciones externas"
ExtAppWriteExplanation2 = "no se puede escribir en la memoria"
ExtAppWriteExplanation3 = "flash (persistente) de su calculadora."
ExtAppEnabled = "Fijar"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Vide "
SymbolArgDefaultFunction = "Arguments "
MemUse = "Mémoire"
DateTime = "Date/heure"
ExternalApps = "Applications externes"
ActivateClock = "Activer horloge"
Date = "Date"
Time = "Heure"
@@ -84,3 +85,8 @@ Normal = "Normale"
IdleTimeBeforeDimming = "Assombrir après (s)"
IdleTimeBeforeSuspend = "Éteindre après (s)"
BrightnessShortcut = "Étapes du raccourci"
ExtAppWrite = "Écriture autorisée"
ExtAppWriteExplanation1 = "Par défaut, les applications externes"
ExtAppWriteExplanation2 = "ne peuvent écrire dans la mémoire"
ExtAppWriteExplanation3 = "flash (persistante) de votre calculatrice."
ExtAppEnabled = "Afficher"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Üres "
SymbolArgDefaultFunction = "Argumentummal "
MemUse = "Memória"
DateTime = "Dátum/óra"
ExternalApps = "Külső alkalmazások"
ActivateClock = "Óra bekapcsolása"
Date = "Datum"
Time = "Óra"
@@ -84,3 +85,8 @@ Normal = "Normale"
IdleTimeBeforeDimming = "Assombrir après (s)"
IdleTimeBeforeSuspend = "Éteindre après (s)"
BrightnessShortcut = "Parancsikon lépések"
ExtAppWrite = "Írás engedélyezve"
ExtAppWriteExplanation1 = "Alapértelmezés szerint külső alkalmazások"
ExtAppWriteExplanation2 = "nem tud a memóriába írni"
ExtAppWriteExplanation3 = "villog (tartósan) a számológép."
ExtAppEnabled = "Feltűz"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Empty "
SymbolArgDefaultFunction = "Argument "
MemUse = "Memory"
DateTime = "Date/time"
ExternalApps = "App esterne"
ActivateClock = "Activate clock"
Date = "Date"
Time = "Time"
@@ -84,3 +85,8 @@ Normal = "Normale"
IdleTimeBeforeDimming = "Scurisci dopo (s)"
IdleTimeBeforeSuspend = "Sospendi dopo (s)"
BrightnessShortcut = "Passaggi di scelta rapida"
ExtAppWrite = "Scrittura abilitata"
ExtAppWriteExplanation1 = "Per impostazione predefinita, applicazioni esterne"
ExtAppWriteExplanation2 = "non può scrivere in memoria"
ExtAppWriteExplanation3 = "flash (persistente) della calcolatrice."
ExtAppEnabled = "Affiggere"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Empty "
SymbolArgDefaultFunction = "Argument "
MemUse = "Memory"
DateTime = "Date/time"
ExternalApps = "Externe apps"
ActivateClock = "Activate clock"
Date = "Date"
Time = "Time"
@@ -84,3 +85,8 @@ Normal = "Normaal"
IdleTimeBeforeDimming = "Donkerder maken na (s)"
IdleTimeBeforeSuspend = "Suspend after (s)"
BrightnessShortcut = "Snelkoppelingsstappen"
ExtAppWrite = "Schrijven ingeschakeld"
ExtAppWriteExplanation1 = "Standaard zijn externe toepassingen"
ExtAppWriteExplanation2 = "kan niet naar het geheugen schrijven"
ExtAppWriteExplanation3 = "flash (aanhoudend) van uw rekenmachine."
ExtAppEnabled = "Vastpinnen"

View File

@@ -65,6 +65,7 @@ SymbolArgFunction = "Vazio "
SymbolArgDefaultFunction = "Argumento "
MemUse = "Memória"
DateTime = "Date/time"
ExternalApps = "Aplicativos externos"
ActivateClock = "Activate clock"
Date = "Date"
Time = "Time"
@@ -84,3 +85,8 @@ Normal = "Normal"
IdleTimeBeforeDimming = "Diminuir depois (s)"
IdleTimeBeforeSuspend = "Suspender depois (s)"
BrightnessShortcut = "Passos de atalho"
ExtAppWrite = "Gravação ativada"
ExtAppWriteExplanation1 = "Por padrão, aplicativos externos"
ExtAppWriteExplanation2 = "não pode gravar na memória"
ExtAppWriteExplanation3 = "flash (persistente) de sua calculadora."
ExtAppEnabled = "Pôster"

View File

@@ -17,6 +17,7 @@ constexpr SettingsMessageTree s_modelDateTimeChildren[3] = {SettingsMessageTree(
constexpr SettingsMessageTree s_symbolChildren[4] = {SettingsMessageTree(I18n::Message::SymbolMultiplicationCross),SettingsMessageTree(I18n::Message::SymbolMultiplicationMiddleDot),SettingsMessageTree(I18n::Message::SymbolMultiplicationStar),SettingsMessageTree(I18n::Message::SymbolMultiplicationAutoSymbol)};
constexpr SettingsMessageTree s_usbProtectionChildren[2] = {SettingsMessageTree(I18n::Message::USBProtection), SettingsMessageTree(I18n::Message::USBProtectionLevel, s_usbProtectionLevelChildren)};
constexpr SettingsMessageTree s_usbProtectionLevelChildren[3] = {SettingsMessageTree(I18n::Message::USBDefaultLevel), SettingsMessageTree(I18n::Message::USBLowLevel), SettingsMessageTree(I18n::Message::USBParanoidLevel)};
constexpr SettingsMessageTree s_externalChildren[2] = {SettingsMessageTree(I18n::Message::ExtAppWrite), SettingsMessageTree(I18n::Message::ExtAppEnabled)};
constexpr SettingsMessageTree s_symbolFunctionChildren[3] = {SettingsMessageTree(I18n::Message::SymbolDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgDefaultFunction), SettingsMessageTree(I18n::Message::SymbolArgFunction)};
constexpr SettingsMessageTree s_modelMathOptionsChildren[6] = {SettingsMessageTree(I18n::Message::AngleUnit, s_modelAngleChildren), SettingsMessageTree(I18n::Message::DisplayMode, s_modelFloatDisplayModeChildren), SettingsMessageTree(I18n::Message::EditionMode, s_modelEditionModeChildren), SettingsMessageTree(I18n::Message::SymbolFunction, s_symbolFunctionChildren), SettingsMessageTree(I18n::Message::ComplexFormat, s_modelComplexFormatChildren), SettingsMessageTree(I18n::Message::SymbolMultiplication, s_symbolChildren)};
constexpr SettingsMessageTree s_brightnessChildren[4] = {SettingsMessageTree(I18n::Message::Brightness), SettingsMessageTree(I18n::Message::IdleTimeBeforeDimming), SettingsMessageTree(I18n::Message::IdleTimeBeforeSuspend), SettingsMessageTree(I18n::Message::BrightnessShortcut)};
@@ -44,7 +45,8 @@ MainController::MainController(Responder * parentResponder, InputEventHandlerDel
m_examModeController(this),
m_aboutController(this),
m_preferencesController(this),
m_usbInfoController(this)
m_usbInfoController(this),
m_externalController(this)
{
for (int i = 0; i < k_numberOfSimpleChevronCells; i++) {
m_cells[i].setMessageFont(KDFont::LargeFont);
@@ -103,6 +105,8 @@ bool MainController::handleEvent(Ion::Events::Event event) {
subController = &m_usbInfoController;
} else if (title == I18n::Message::CodeApp) {
subController = &m_codeOptionsController;
} else if (title == I18n::Message::ExternalApps) {
subController = &m_externalController;
} else {
subController = &m_preferencesController;
}

View File

@@ -13,6 +13,7 @@
#include "sub_menu/math_options_controller.h"
#include "sub_menu/preferences_controller.h"
#include "sub_menu/usb_protection_controller.h"
#include "sub_menu/external_controller.h"
#include "sub_menu/brightness_controller.h"
namespace Settings {
@@ -32,6 +33,7 @@ extern const Shared::SettingsMessageTree s_contributorsChildren[18];
extern const Shared::SettingsMessageTree s_modelAboutChildren[10];
extern const Shared::SettingsMessageTree s_usbProtectionChildren[2];
extern const Shared::SettingsMessageTree s_usbProtectionLevelChildren[3];
extern const Shared::SettingsMessageTree s_externalChildren[2];
extern const Shared::SettingsMessageTree s_brightnessChildren[4];
extern const Shared::SettingsMessageTree s_model;
@@ -82,6 +84,7 @@ private:
AboutController m_aboutController;
PreferencesController m_preferencesController;
UsbInfoController m_usbInfoController;
ExternalController m_externalController;
};
}

View File

@@ -17,9 +17,10 @@ constexpr SettingsMessageTree s_modelMenu[] =
SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren),
#endif
SettingsMessageTree(I18n::Message::BetaPopUp),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren),
// SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren)};
//SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::ExternalApps, s_externalChildren),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)};
constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu);

View File

@@ -17,7 +17,8 @@ constexpr SettingsMessageTree s_modelMenu[] =
#ifdef HAS_CODE
SettingsMessageTree(I18n::Message::CodeApp, s_codeChildren),
#endif
// SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
//SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::ExternalApps, s_externalChildren),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)};

View File

@@ -19,6 +19,8 @@ constexpr SettingsMessageTree s_modelMenu[] =
SettingsMessageTree(I18n::Message::UpdatePopUp),
SettingsMessageTree(I18n::Message::Accessibility, s_accessibilityChildren),
// SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::UsbSetting, s_usbProtectionChildren),
SettingsMessageTree(I18n::Message::ExternalApps, s_externalChildren),
SettingsMessageTree(I18n::Message::About, s_modelAboutChildren)};
constexpr SettingsMessageTree s_model = SettingsMessageTree(I18n::Message::SettingsApp, s_modelMenu);

View File

@@ -0,0 +1,72 @@
#include "external_controller.h"
#include <apps/i18n.h>
#include <apps/settings/main_controller.h>
#include <assert.h>
#include <ion/storage.h>
#include <poincare/preferences.h>
#include "../../apps_container.h"
#include "../../global_preferences.h"
using namespace Poincare;
using namespace Shared;
namespace Settings {
ExternalController::ExternalController(Responder *parentResponder):
GenericSubController(parentResponder),
m_contentView(&m_selectableTableView)
{
m_writeSwitchCell.setMessageFont(KDFont::LargeFont);
m_enabledSwitchCell.setMessageFont(KDFont::LargeFont);
}
bool ExternalController::handleEvent(Ion::Events::Event event) {
if ((Ion::Events::OK == event || Ion::Events::EXE == event || Ion::Events::Right == event) && selectedRow() == 0) {
bool externalWasUnlocked = GlobalPreferences::sharedGlobalPreferences()->externalAppWritePermission();
GlobalPreferences::sharedGlobalPreferences()->setExternalAppWritePermission(!externalWasUnlocked);
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
return true;
} else if ((Ion::Events::OK == event || Ion::Events::EXE == event || Ion::Events::Right == event) && selectedRow() == 1) {
bool extappWasShowed = GlobalPreferences::sharedGlobalPreferences()->externalAppShown();
GlobalPreferences::sharedGlobalPreferences()->setExternalAppShown(!extappWasShowed);
m_selectableTableView.reloadCellAtLocation(0, selectedRow());
return true;
}
return GenericSubController::handleEvent(event);
}
HighlightCell *ExternalController::reusableCell(int index, int type) {
if (index == 0) {
return &m_writeSwitchCell;
}
assert(index == 1);
return &m_enabledSwitchCell;
}
int ExternalController::reusableCellCount(int type) {
assert(type == 0);
return 2;
}
void ExternalController::willDisplayCellForIndex(HighlightCell *cell, int index) {
GenericSubController::willDisplayCellForIndex(cell, index);
if (index == 0) {
MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell;
SwitchView *mySwitch = (SwitchView *)myCell->accessoryView();
mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->externalAppWritePermission());
} else if (index == 1) {
MessageTableCellWithSwitch *myCell = (MessageTableCellWithSwitch *)cell;
SwitchView *mySwitch = (SwitchView *)myCell->accessoryView();
mySwitch->setState(GlobalPreferences::sharedGlobalPreferences()->externalAppShown());
}
}
void ExternalController::didEnterResponderChain(Responder *previousFirstResponder) {
m_contentView.reload();
I18n::Message infoMessages[] = {I18n::Message::ExtAppWriteExplanation1, I18n::Message::ExtAppWriteExplanation2, I18n::Message::ExtAppWriteExplanation3};
m_contentView.setMessages(infoMessages, k_numberOfExplanationMessages);
}
}

View File

@@ -0,0 +1,29 @@
#ifndef SETTINGS_EXTERNAL_CONTROLLER_H
#define SETTINGS_EXTERNAL_CONTROLLER_H
#include "generic_sub_controller.h"
#include "preferences_controller.h"
#include "selectable_view_with_messages.h"
namespace Settings {
class ExternalController : public GenericSubController {
public:
ExternalController(Responder* parentResponder);
View* view() override { return &m_contentView; }
bool handleEvent(Ion::Events::Event event) override;
TELEMETRY_ID("ExternalSettings");
void didEnterResponderChain(Responder* previousFirstResponder) override;
HighlightCell* reusableCell(int index, int type) override;
int reusableCellCount(int type) override;
void willDisplayCellForIndex(HighlightCell* cell, int index) override;
private:
static constexpr int k_numberOfExplanationMessages = 3;
SelectableViewWithMessages m_contentView;
MessageTableCellWithSwitch m_writeSwitchCell;
MessageTableCellWithSwitch m_enabledSwitchCell;
};
}
#endif