Fix eeprom freeze, LED flash, Macro in config

This commit is contained in:
William Toohey
2017-05-22 01:35:47 +10:00
parent 3caa27d33b
commit 4a95c23bf4
3 changed files with 32 additions and 10 deletions
+2 -2
View File
@@ -51,8 +51,8 @@ static const PROGMEM sdvx_config_t defaults = {
void InitConfig(void) {
if (eeprom_read_byte(&firstRun) != MAGIC_NUMBER) { // store defaults
memcpy_P(&sdvxConfig, &defaults, sizeof(sdvx_config_t));
eeprom_write_block(&sdvxConfig, &eeConfig, sizeof(sdvx_config_t));
eeprom_write_byte(&firstRun, MAGIC_NUMBER); // defaults set
eeprom_update_block(&sdvxConfig, &eeConfig, sizeof(sdvx_config_t));
eeprom_update_byte(&firstRun, MAGIC_NUMBER); // defaults set
}
eeprom_read_block(&sdvxConfig, &eeConfig, sizeof(sdvx_config_t));
}
+5 -3
View File
@@ -66,11 +66,11 @@ uint8_t led_on_frame(void) {
void led_pattern_animate(void) {
if(flash) {
led_update_breather(FLASH_SPEED);
if(pattern.breathe.level < 5) {
if(pattern.breathe.level == 0) {
led_init_breathe();
flash = 0;
return;
}
return;
}
switch(sdvxConfig.lightPattern) {
case NONE:
@@ -92,9 +92,11 @@ void led_pattern_animate(void) {
void led_pattern_next(void) {
sdvxConfig.lightPattern++;
if(sdvxConfig.lightPattern > BREATHE)
if(sdvxConfig.lightPattern > BREATHE) {
// since we don't want the init flash
sdvxConfig.lightPattern = NONE;
}
UpdateConfig();
}
void led_overlay_knobs(void) {
+25 -5
View File
@@ -83,9 +83,9 @@ class BinaryBuffer {
this.offset = 0;
}
read(size) {
read(size, forceArray = false) {
let ret;
if(size == 1) {
if(size == 1 && !forceArray) {
ret = this.view.getUint8(this.offset);
} else {
ret = [];
@@ -250,7 +250,7 @@ class SettingKeys extends Setting {
}
read(buffer) {
var keys = buffer.read(this.byteCount);
var keys = buffer.read(this.byteCount, true);
for(var i = 0; i < this.switchCount; i++) {
this.selects[i].value = keys[i];
}
@@ -303,19 +303,38 @@ class SettingPin extends Setting {
}
class SettingMacro extends Setting {
constructor() {
super();
this.action = new SettingRadio();
this.keypress = new SettingKeys(1);
this.action.setCallback(this.fireCallback.bind(this));
this.keypress.setCallback(this.fireCallback.bind(this));
}
createUI(setting) {
var entry = document.createElement('p');
entry.textContent = setting.name + ':';
entry.appendChild(this.action.createUI({
id: setting.id + '-action', name: 'Action',
options : [{name: 'Keypress', val: 0},
{name: 'Macro PIN', val: 1},
{name: 'Cycle LED pattern', val: 2},
{name: 'Toggle LEDs', val: 3}]
}));
entry.appendChild(this.keypress.createUI({name: 'Key'}));
return entry;
}
read(buffer) {
this.keys = buffer.read(2);
this.action.read(buffer);
this.keypress.read(buffer);
}
write(buffer) {
buffer.write(this.keys);
this.action.write(buffer);
this.keypress.write(buffer);
}
}
@@ -528,6 +547,7 @@ class Config {
window.Config = Config;
var scancodes = [
{name: "None", value: 0x00},
{name: "A", value: 0x04},
{name: "B", value: 0x05},
{name: "C", value: 0x06},