Skip to content
Closed
Show file tree
Hide file tree
Changes from 22 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);
Comment thread
Yaya-Cout marked this conversation as resolved.
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think these lines should be removed, because this pull request is marked as ready for review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't know because it add the possibility to disable the exam mode in the simulator without rebooting

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but it is marked as ready to merge…

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed because I think it can be a good idea to add the possibility to disable the exam mode in simulators ^^ The exam mode in simulator doesn't make any sense in the first place because you can always leave the simulator and open others app so I don't see the problem by adding the option

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, but if we look #131, it is built as a simulator, but it runs on the calculator…

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, I agree with Yaya-Cout

mode = GlobalPreferences::sharedGlobalPreferences()->examMode();
#endif
}
return mode;
}
Expand Down
4 changes: 2 additions & 2 deletions apps/settings/sub_menu/usb_protection_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace Shared;

namespace Settings {

UsbInfoController::UsbInfoController(Responder *parentResponder):
UsbInfoController::UsbInfoController(Responder *parentResponder) :
GenericSubController(parentResponder),
m_usbProtectionLevelController(this),
m_contentView(&m_selectableTableView)
Expand Down Expand Up @@ -101,7 +101,7 @@ void UsbInfoController::willDisplayCellForIndex(HighlightCell *cell, int index)

void UsbInfoController::didEnterResponderChain(Responder *previousFirstResponder) {
m_contentView.reload();
I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2, I18n::Message::USBExplanation3};
I18n::Message infoMessages[] = {I18n::Message::USBExplanation1, I18n::Message::USBExplanation2,I18n::Message::USBExplanation3};
m_contentView.setMessages(infoMessages, k_numberOfExplanationMessages);
}
}
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 setMyColor(KDColor color) {m_color = color; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
void setMyColor(KDColor color) {m_color = color; }
void setMyColor(KDColor color) { m_color = color; }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In fact, is it possible to give a better name to the function?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

setGraphColor ?

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->setMyColor(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
2 changes: 1 addition & 1 deletion ion/src/device/shared/boot/rt0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ void __attribute__((noinline)) start() {
Ion::Device::Board::initFPU();

/* Call static C++ object constructors
* The C++ compiler creates an initialization function for each static object.
* The C++ compiler creates an initialization function for each static object.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* The C++ compiler creates an initialization function for each static object.
* The C++ compiler creates an initialization function for each static object.

* The linker then stores the address of each of those functions consecutively
* between _init_array_start and _init_array_end. So to initialize all C++
* static objects we just have to iterate between theses two addresses and
Expand Down
6 changes: 3 additions & 3 deletions ion/src/device/shared/usb/dfu_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void DFUInterface::wholeDataSentCallback(SetupPacket *request, uint8_t *transfer
// Leave DFU routine: Leave DFU, reset device, jump to application code
leaveDFUAndReset();
} else if (m_state == State::dfuDNBUSY) {
m_state = State::dfuDNBUSY;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't understand this line...

if (m_largeBufferLength != 0) {
// Here, copy the data from the transfer buffer to the flash memory
writeOnMemory();
Expand Down Expand Up @@ -152,7 +153,7 @@ 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. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

// 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 @@ -188,7 +189,7 @@ void DFUInterface::changeAddressPointerIfNeeded() {

void DFUInterface::eraseCommand(uint8_t *transferBuffer, uint16_t transferBufferLength) {
/* We determine whether the commands asks for a mass erase or which sector to
* erase. The erase must be done after the next getStatus request. */
* erase. The erase must be done after the next getStatus request. */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

?

@Yaya-Cout Yaya-Cout Feb 3, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it has been squashed when merging, but this fork isn't up-to-date, so it isn't corrected in this repo

m_state = State::dfuDNLOADSYNC;

if (transferBufferLength == 1) {
Expand Down Expand Up @@ -217,7 +218,6 @@ void DFUInterface::eraseMemoryIfNeeded() {
if (m_erasePage < 0) {
return;
}

willErase();

#if 0 // We don't erase now the flash memory to avoid crash if writing is refused
Expand Down
11 changes: 4 additions & 7 deletions ion/src/device/shared/usb/dfu_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
#include <drivers/config/internal_flash.h>
#include <drivers/config/external_flash.h>

namespace Ion
{
namespace Device
{
namespace USB
{
namespace Ion {
namespace Device {
namespace USB {

class DFUInterface : public Interface {

Expand Down Expand Up @@ -210,7 +207,7 @@ class DFUInterface : public Interface {
uint8_t m_lastMemoryType; // -1: None; 0: internal; 1: external
uint8_t m_lastPageErased; // -1 default value
bool m_dfuUnlocked;
uint8_t m_dfuLevel; // 0: Upsilon only, 1: Omega-forked only, 2: No update
uint8_t m_dfuLevel;
};

}
Expand Down
Loading