void hwWriteConfig(int adr, uint8_t value) { uint8_t curr = hwReadConfig(adr); if (curr != value) { hwWriteConfigBlock(&value, reinterpret_cast<void*>(adr), 1); } }
uint8_t transportGetRoute(const uint8_t node) { uint8_t result; #if defined(MY_RAM_ROUTING_TABLE_ENABLED) result = _transportRoutingTable.route[node]; #else result = hwReadConfig(EEPROM_ROUTES_ADDRESS + node); #endif return result; }
void _begin() { #if !defined(MY_DISABLED_SERIAL) hwInit(); #endif // Call before() in sketch (if it exists) if (before) before(); debug(PSTR("Starting " MY_NODE_TYPE " (" MY_CAPABILITIES ", " LIBRARY_VERSION ")\n")); signerInit(); #if defined(MY_RADIO_FEATURE) _failedTransmissions = 0; // Setup radio if (!transportInit()) { debug(PSTR("Radio init failed. Check wiring.\n")); // Nothing more we can do _infiniteLoop(); } else { debug(PSTR("Radio init successful.\n")); } #endif #if defined(MY_GATEWAY_FEATURE) #if defined(MY_INCLUSION_BUTTON_FEATURE) inclusionInit(); #endif // initialize the transport driver if (!gatewayTransportInit()) { debug(PSTR("Transport driver init fail\n")); // Nothing more we can do _infiniteLoop(); } #endif #if defined(MY_LEDS_BLINKING_FEATURE) ledsInit(); #endif // Read latest received controller configuration from EEPROM hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig)); if (_cc.isMetric == 0xff) { // Eeprom empty, set default to metric _cc.isMetric = 0x01; } #if defined(MY_GATEWAY_FEATURE) // Set configuration for gateway _nc.parentNodeId = GATEWAY_ADDRESS; _nc.distance = 0; _nc.nodeId = GATEWAY_ADDRESS; #elif defined(MY_RADIO_FEATURE) // Read settings from eeprom hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); #ifdef MY_OTA_FIRMWARE_FEATURE // Read firmware config from EEPROM, i.e. type, version, CRC, blocks hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig)); #endif _autoFindParent = MY_PARENT_NODE_ID == AUTO; if (!_autoFindParent) { _nc.parentNodeId = MY_PARENT_NODE_ID; // Save static parent id in eeprom (used by bootloader) hwWriteConfig(EEPROM_PARENT_NODE_ID_ADDRESS, MY_PARENT_NODE_ID); // We don't actually know the distance to gw here. Let's pretend it is 1. // If the current node is also repeater, be aware of this. _nc.distance = 1; } else if (!isValidParent(_nc.parentNodeId)) { // Auto find parent, but parent in eeprom is invalid. Try find one. transportFindParentNode(); } if (MY_NODE_ID != AUTO) { // Set static id _nc.nodeId = MY_NODE_ID; // Save static id in eeprom hwWriteConfig(EEPROM_NODE_ID_ADDRESS, MY_NODE_ID); } else if (_nc.nodeId == AUTO && isValidParent(_nc.parentNodeId)) { // Try to fetch node-id from gateway transportRequestNodeId(); } #endif #ifdef MY_NODE_LOCK_FEATURE // Check if node has been locked down if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) { // Node is locked, check if unlock pin is asserted, else hang the node pinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP); // Make a short delay so we are sure any large external nets are fully pulled unsigned long enter = hwMillis(); while (hwMillis() - enter < 2); if (digitalRead(MY_NODE_UNLOCK_PIN) == 0) { // Pin is grounded, reset lock counter hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); // Disable pullup pinMode(MY_NODE_UNLOCK_PIN, INPUT); debug(PSTR("Node is unlocked.\n")); } else { // Disable pullup pinMode(MY_NODE_UNLOCK_PIN, INPUT); nodeLock("LDB"); //Locked during boot } } else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) { // Reset walue hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX); } #endif // Call sketch setup if (setup) setup(); #if defined(MY_RADIO_FEATURE) transportPresentNode(); #endif if (presentation) presentation(); debug(PSTR("Init complete, id=%d, parent=%d, distance=%d\n"), _nc.nodeId, _nc.parentNodeId, _nc.distance); }
uint8_t loadState(uint8_t pos) { return hwReadConfig(EEPROM_LOCAL_CONFIG_ADDRESS+pos); }