Skip to content

Commit

Permalink
button to clear save data
Browse files Browse the repository at this point in the history
  • Loading branch information
jrcurtis committed Mar 3, 2016
1 parent 7e0fdfe commit f673b65
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
1 change: 1 addition & 0 deletions include/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define CHANNEL_X (4)

#define SAVE_BUTTON_INDEX (81)
#define CLEAR_BUTTON_INDEX (11)

#define CHECKBOX_ROW (7)
#define CHECKBOX_ROW_INDEX (81)
Expand Down
1 change: 1 addition & 0 deletions include/serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ extern const uint16_t DATA_VERSION;

void serialize_app();
void deserialize_app();
void serialize_clear();

#endif
17 changes: 15 additions & 2 deletions src/seq.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ void session_mode_become_inactive()

void session_setup_become_active()
{
plot_pad(SAVE_BUTTON_INDEX, number_colors[0]);
plot_pad(SAVE_BUTTON_INDEX, number_colors[1]);
plot_pad(CLEAR_BUTTON_INDEX, number_colors[1]);
}

void session_setup_become_inactive()
Expand Down Expand Up @@ -158,7 +159,19 @@ uint8_t session_setup_handle_press(uint8_t index, uint8_t value)
}
else
{
plot_pad(SAVE_BUTTON_INDEX, number_colors[1]);
plot_pad(SAVE_BUTTON_INDEX, number_colors[2]);
}
}
else if (index == CLEAR_BUTTON_INDEX)
{
if (value > 0)
{
plot_pad(CLEAR_BUTTON_INDEX, on_color);
serialize_clear();
}
else
{
plot_pad(CLEAR_BUTTON_INDEX, number_colors[0]);
}
}
else
Expand Down
46 changes: 35 additions & 11 deletions src/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,25 @@ const uint16_t DATA_VERSION = 1;
#define read_bytes(d) { hal_read_flash(offset, (uint8_t*)&(d), sizeof(d)); \
offset += sizeof(d); }

uint8_t is_data_saved()
{
uint16_t temp;

hal_read_flash(0, (uint8_t*)&temp, sizeof(temp));
if (temp != APP_ID)
{
return 0;
}

hal_read_flash(sizeof(temp), (uint8_t*)&temp, sizeof(temp));
if (temp != DATA_VERSION)
{
return 0;
}

return 1;
}

/*******************************************************************************
* Serializer
******************************************************************************/
Expand Down Expand Up @@ -138,27 +157,32 @@ void serialize_app()
write_bytes(lp_note_bank);
}

void serialize_clear()
{
if (!is_data_saved())
{
return;
}

uint16_t temp = 0;
hal_write_flash(0, (uint8_t*)&temp, sizeof(temp));
hal_write_flash(sizeof(temp), (uint8_t*)&temp, sizeof(temp));
}

/*******************************************************************************
* Deserializer
******************************************************************************/

void deserialize_app()
{
uint32_t offset = 0;
uint16_t temp16 = 0;
uint8_t temp8 = 0;

read_bytes(temp16);
if (temp16 != APP_ID)
if (!is_data_saved())
{
return;
}

read_bytes(temp16);
if (temp16 != DATA_VERSION)
{
return;
}
uint32_t offset = sizeof(APP_ID) + sizeof(DATA_VERSION);
uint16_t temp16 = 0;
uint8_t temp8 = 0;

read_bytes(lp_midi_port);
read_bytes(lp_rcv_clock_port);
Expand Down

0 comments on commit f673b65

Please sign in to comment.