Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions apps/apps_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ App::Snapshot * AppsContainer::usbConnectedAppSnapshot() {
return &m_usbConnectedSnapshot;
}

void AppsContainer::reset() {
// Empty storage (delete functions, variables, python scripts)
Ion::Storage::sharedStorage()->destroyAllRecords();
void AppsContainer::reset(bool storage) {
if (storage) {
// Empty storage (delete functions, variables, python scripts)
Ion::Storage::sharedStorage()->destroyAllRecords();
} else {
// Activate Quarantine
Ion::Storage::sharedStorage()->activateQuarantine();
}
// Empty clipboard
Clipboard::sharedClipboard()->reset();
for (int i = 0; i < numberOfApps(); i++) {
Expand Down Expand Up @@ -411,7 +416,7 @@ void AppsContainer::redrawWindow(bool force) {

void AppsContainer::activateExamMode(GlobalPreferences::ExamMode examMode) {
assert(examMode != GlobalPreferences::ExamMode::Off && examMode != GlobalPreferences::ExamMode::Unknown);
reset();
reset(examMode != GlobalPreferences::ExamMode::Standard);
Ion::LED::setColor(KDColorRed);
/* The Dutch exam mode LED is supposed to be orange but we can only make
* blink "pure" colors: with RGB leds on or off (as the PWM is used for
Expand Down
2 changes: 1 addition & 1 deletion apps/apps_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class AppsContainer : public Container, ExamPopUpControllerDelegate, Ion::Storag
App::Snapshot * hardwareTestAppSnapshot();
App::Snapshot * onBoardingAppSnapshot();
App::Snapshot * usbConnectedAppSnapshot();
void reset();
void reset(bool storage = true);
Poincare::Context * globalContext();
MathToolbox * mathToolbox();
MathVariableBoxController * variableBoxController();
Expand Down
1 change: 1 addition & 0 deletions apps/exam_pop_up_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ExamPopUpController::ExamPopUpController(ExamPopUpControllerDelegate * delegate)
GlobalPreferences::sharedGlobalPreferences()->setExamMode(mode);
AppsContainer * container = AppsContainer::sharedAppsContainer();
if (mode == GlobalPreferences::ExamMode::Off) {
Ion::Storage::sharedStorage()->deactivateQuarantine();
Ion::LED::setColor(KDColorBlack);
Ion::LED::updateColorWithPlugAndCharge();
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/settings/base.fr.i18n
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ USBExplanation1= "La protection USB protège votre"
USBExplanation2= "calculatrice contre un verrouillage"
USBExplanation3= "non-intentionnel"
USBProtection= "Protection USB"
USBProtectionLevel = "Mise à jour acceptées"
USBProtectionLevel = "Mises à jour acceptées"
USBDefaultLevel = "Basées sur Upsilon"
USBLowLevel = "Basées sur Omega"
USBParanoidLevel = "Aucune"
5 changes: 5 additions & 0 deletions apps/settings/sub_menu/exam_mode_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <cmath>
#include <poincare/preferences.h>
#include <apps/i18n.h>
#include <ion.h>

using namespace Poincare;
using namespace Shared;
Expand Down Expand Up @@ -112,7 +113,11 @@ GlobalPreferences::ExamMode ExamModeController::examMode() {
GlobalPreferences::ExamMode mode = GlobalPreferences::sharedGlobalPreferences()->tempExamMode();
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
// If the exam mode is already on, this re-activate the same exam mode
// #if ION_SIMULATOR_FILES
// mode = GlobalPreferences::ExamMode::Off;
// #else
mode = GlobalPreferences::sharedGlobalPreferences()->examMode();
// #endif
Comment on lines +116 to +120
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these comments can be removed.

}
return mode;
}
Expand Down
1 change: 1 addition & 0 deletions apps/shared/function.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Function : public ExpressionModelHandle {
}
bool isActive() const { return m_active; }
void setActive(bool active) { m_active = active; }
void setGraphColor(KDColor color) { m_color = color; }
private:
#if __EMSCRIPTEN__
/* For emscripten memory representation, loads and stores must be aligned;
Expand Down
10 changes: 9 additions & 1 deletion apps/shared/sequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <string.h>
#include <apps/i18n.h>
#include <cmath>
#include <ion/storage.h>

using namespace Poincare;

Expand Down Expand Up @@ -315,7 +316,14 @@ void Sequence::rangeForDisplay(float * xMin, float * xMax, float * yMin, float *
Sequence::RecordDataBuffer * Sequence::recordData() const {
assert(!isNull());
Ion::Storage::Record::Data d = value();
return reinterpret_cast<RecordDataBuffer *>(const_cast<void *>(d.buffer));
Sequence::RecordDataBuffer * buffer = reinterpret_cast<RecordDataBuffer *>(const_cast<void *>(d.buffer));
for (int i = 0; i < Shared::MaxNumberOfSequences; i++) {
if (Ion::Storage::strstr(fullName(), SequenceStore::k_sequenceNames[i])) {
buffer->setGraphColor(Palette::DataColor[i]);
break;
}
}
return buffer;
}

/* Sequence Model */
Expand Down
53 changes: 41 additions & 12 deletions ion/include/ion/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <stddef.h>
#include <stdint.h>

namespace Ion {

/* Storage : | Magic | Record1 | Record2 | ... | Magic |
Expand All @@ -17,7 +16,9 @@ class Storage {
public:
typedef uint16_t record_size_t;

constexpr static size_t k_storageSize = 64000;
constexpr static size_t k_storageSize = 63900;
constexpr static size_t k_fullNameMaxSize = 220 + 5;
constexpr static size_t k_extensionMaxSize = 10;
static_assert(UINT16_MAX >= k_storageSize, "record_size_t not big enough");

static Storage * sharedStorage();
Expand All @@ -27,6 +28,22 @@ class Storage {
static constexpr char expExtension[] = "exp";
static constexpr char funcExtension[] = "func";
static constexpr char seqExtension[] = "seq";
static constexpr char examPrefix[] = "exam";

static constexpr uint8_t eqMaxRecords = 6;
static constexpr uint8_t expMaxRecords = -1;
static constexpr uint8_t funcMaxRecords = -1;
static constexpr uint8_t seqMaxRecords = 3;

static constexpr uint8_t noMaxRecords = -1;


/* TODO
* Replace k_sequenceNames from sequence_store.h with this one
* */
static constexpr const char * k_sequenceNames[seqMaxRecords] = {
"u", "v", "w"
};

class Record {
/* A Record is identified by the CRC32 on its fullName because:
Expand Down Expand Up @@ -64,13 +81,13 @@ class Storage {
return m_fullNameCRC32 == 0;
}
const char * fullName() const {
return Storage::sharedStorage()->fullNameOfRecord(*this);
return Storage::sharedStorage()->fullNameOfRecord(*this, false);
}
ErrorStatus setBaseNameWithExtension(const char * baseName, const char * extension) {
return Storage::sharedStorage()->setBaseNameWithExtensionOfRecord(*this, baseName, extension);
return Storage::sharedStorage()->setBaseNameWithExtensionOfRecord(*this, baseName, extension, false);
}
ErrorStatus setName(const char * fullName) {
return Storage::sharedStorage()->setFullNameOfRecord(*this, fullName);
return Storage::sharedStorage()->setFullNameOfRecord(*this, fullName, false);
}
Data value() const {
return Storage::sharedStorage()->valueOfRecord(*this);
Expand All @@ -88,6 +105,7 @@ class Storage {

#if ION_STORAGE_LOG
void log();
void logMessage(const char * message);
#endif

size_t availableSize();
Expand All @@ -100,7 +118,7 @@ class Storage {
void notifyChangeToDelegate(const Record r = Record()) const;
Record::ErrorStatus notifyFullnessToDelegate() const;

int numberOfRecordsWithExtension(const char * extension);
int numberOfRecordsWithExtension(const char * extension, bool system = false);
static bool FullNameHasExtension(const char * fullName, const char * extension, size_t extensionLength);

// Record creation
Expand All @@ -120,11 +138,19 @@ class Storage {
void destroyRecordWithBaseNameAndExtension(const char * baseName, const char * extension);
void destroyRecordsWithExtension(const char * extension);

// Exam Mode
void activateQuarantine();
void deactivateQuarantine();
void setFullNameBufferWithPrefix(const char * prefix, const char * name);
static bool fullNameAuthorized(const char * fullname);
void deleteRecordByExtensionIfNeeded(const char * extension);

// Useful
static bool FullNameCompliant(const char * name);

static bool FullNameCompliant(const char * name, bool withoutExtension = false);
static bool strstr(const char * first, const char * second);

// User by Python OS module
int numberOfRecords();
int numberOfRecords(bool system = false);
Record recordAtIndex(int index);

private:
Expand All @@ -134,9 +160,9 @@ class Storage {
Storage();

/* Getters/Setters on recordID */
const char * fullNameOfRecord(const Record record);
Record::ErrorStatus setFullNameOfRecord(const Record record, const char * fullName);
Record::ErrorStatus setBaseNameWithExtensionOfRecord(const Record record, const char * baseName, const char * extension);
const char * fullNameOfRecord(const Record record, bool system = false);
Record::ErrorStatus setFullNameOfRecord(const Record record, const char *fullName, bool system = false);
Record::ErrorStatus setBaseNameWithExtensionOfRecord(const Record record, const char *baseName, const char *extension, bool system = false);
Record::Data valueOfRecord(const Record record);
Record::ErrorStatus setValueOfRecord(const Record record, Record::Data data);
void destroyRecord(const Record record);
Expand Down Expand Up @@ -186,6 +212,9 @@ class Storage {
StorageDelegate * m_delegate;
mutable Record m_lastRecordRetrieved;
mutable char * m_lastRecordRetrievedPointer;
bool m_quarantine;
int m_examNumber;
char m_fullNameBuffer[k_fullNameMaxSize];
};

/* Some apps memoize records and need to be notified when a record might have
Expand Down
3 changes: 1 addition & 2 deletions ion/src/device/shared/usb/dfu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ bool DFUInterface::processUploadRequest(SetupPacket *request, uint8_t *transferB
} else {
/* We decided to never protect Read operation. Else we would have to check
* here it is not protected before reading. */

// Compute the reading address
uint32_t readAddress = (request->wValue() - 2) * Endpoint0::MaxTransferSize + m_addressPointer;
// Copy the requested memory zone into the transfer buffer.
Expand Down Expand Up @@ -217,7 +216,7 @@ void DFUInterface::eraseMemoryIfNeeded() {
if (m_erasePage < 0) {
return;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove trailing space…

Suggested change

willErase();

#if 0 // We don't erase now the flash memory to avoid crash if writing is refused
Expand Down
Loading