Exemplo n.º 1
0
/**
*	\brief Creates a table with all sensors which are connected via OneWire.
*		
*		The table is created on the basis of a previous table which is stored
*		in the EEPROM. This helps to have a consistent assignment of the sensor ID
*		to the connected sensor. Otherwise this can change after a reset or if a 
*		sensor is removed.	
*/
error_t createAddressTable(void){
	uint8_t address[8];
	tempSensorTable.size=0;
	uint8_t index=0;
	tempSensorTable_t eepromTable;
	
	memset(&tempSensorTable,0,sizeof(tempSensorTable_t));
	
	int8_t deviceCount=sensors.getDeviceCount();
	for(int i=0; i<deviceCount; i++){
		if(sensors.getAddress(address, i)){
			memcpy(tempSensorTable.tableEntry[index].address,address,sizeof(address));
			tempSensorTable.tableEntry[index].tempSensorID=i;
			tempSensorTable.tableEntry[index].enabled=1;		//default: send temp sensor value
			++index;	
		}
	}
	tempSensorTable.size=index;
	
	if(!loadAddressTableFromEEPROM(&eepromTable)){
		//table found in EEPROM
		mergeTables(&eepromTable, &tempSensorTable);
	}
	
	writeAddressTableToEEPROM(&tempSensorTable);
	
	return ERR_NO_ERR;
}
Exemplo n.º 2
0
	void testMethods()
	{
		int n1, n2, r, d, i, answer;
		for (i = 0; i < 10; i++)
		{
			answer = mergeTables(testCase[i].n1, testCase[i].n2, testCase[i].r);
			d = compare(answer, testCase[i].output);
			if (d==1) printf("\nPASSED");
			else printf("\nFAILED");
		}
	}