MCPcopy Create free account
hub / github.com/Santroller/Santroller / update_aux_toggle

Function update_aux_toggle

src/config.cpp:1140–1164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1138
1139
1140void update_aux_toggle(uint32_t id, bool state)
1141{
1142 printf("update aux: %d %d %d\r\n", id, state, reinit);
1143 if (reinit)
1144 {
1145 return;
1146 }
1147 cycle_input_states[id] = state;
1148 // Aux region contains data that the firmware can update itself
1149 ConfigFooter *footer = reinterpret_cast<ConfigFooter *>(EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter));
1150 // move data to start of cache to make modifying easier
1151 memmove(EEPROM.writeCache, EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer->dataSize, footer->dataSize);
1152 pb_ostream_t auxOutputStream = pb_ostream_from_buffer(EEPROM.writeCache + footer->mainSize, EEPROM_SIZE_BYTES - footer->mainSize - sizeof(ConfigFooter));
1153 proto_AuxConfigBlock block;
1154 block.states.funcs.encode = encode_cycle_input_states;
1155 block.toggleStates.funcs.encode = encode_toggle_input_states;
1156 pb_encode(&auxOutputStream, proto_AuxConfigBlock_fields, &block);
1157 footer->auxSize = auxOutputStream.bytes_written;
1158 footer->dataSize = footer->mainSize + footer->auxSize;
1159 footer->dataCrc = CRC32::calculate(EEPROM.writeCache, footer->dataSize);
1160 // Move the encoded data to end where it should be
1161 memmove(EEPROM.writeCache + EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer->dataSize, EEPROM.writeCache, footer->dataSize);
1162 memset(EEPROM.writeCache, 0, EEPROM_SIZE_BYTES - sizeof(ConfigFooter) - footer->dataSize);
1163 EEPROM.commit_now();
1164}
1165
1166bool write_config_info(const uint8_t *buffer, uint16_t bufsize)
1167{

Callers 1

toggleMethod · 0.85

Calls 4

pb_ostream_from_bufferFunction · 0.85
pb_encodeFunction · 0.85
memsetFunction · 0.85
commit_nowMethod · 0.80

Tested by

no test coverage detected