// Same as above, except uses default printf output void owPrintErrorMsgStd() { #ifdef DEBUG int l = owErrorStack[ owErrorPointer ].lineno; char *f = owErrorStack[ owErrorPointer ].filename; int err = owGetErrorNum(); printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]); #else int err = owGetErrorNum(); printf("Error %d: %s\r\n",err,owErrorMsg[err]); #endif }
//---------------------------------------------------------------------- // Main for tstfind // void main(void) { uchar rslt; int cnt; //use port for 1-wire uchar portnum = ONEWIRE_P; //initialize I/O port #if STDOUT_P==0 serial0_init(BAUD9600_TIMER_RELOAD_VALUE); #else serial1_init(BAUD9600_TIMER_RELOAD_VALUE); #endif printf("Beginning tstfindm\r\n"); // attempt to acquire the 1-Wire Net if (!owAcquire(portnum,NULL)) { printf("owAcquire failed\r\n"); while(owHasErrors()) printf(" - Error %d\r\n", owGetErrorNum()); return; } //---------------------------------------- // Introduction printf("\r\n/----------------\r\n"); printf(" All iButtons.\r\n\r\n"); do { printf("-- Start\r\n"); cnt = 0; // find the first device (all devices not just alarming) rslt = owFirst(portnum, TRUE, FALSE); while (rslt) { // print the device number cnt++; printf("(%d) ",cnt); // get and print the Serial Number of the device just found DisplaySerialNum(portnum); // find the next device rslt = owNext(portnum, TRUE, FALSE); } printf("-- End\r\n\r\nPress any key to continue searching\r\n"); rslt = getchar(); //printf("key pressed: %c\r\n",rslt); } while (rslt!='q'); // release the 1-Wire Net owRelease(portnum); return; }
void scu_init() { uchar FamilySN[MAXDEVICES][8]; int current_temp; int c_frac; int i = 0; int j = 0; int cnt = 0; int NumDevices = 0; SMALLINT didRead = 0; uchar read_buffer[32]; uchar write_buffer[32]; owInit(); uart_init(); uart_write_string("SCU\n"); //use port number for 1-wire uchar portnum = ONEWIRE_PORT; j = 0; // Find the device(s) NumDevices = 0; NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x42, MAXDEVICES-NumDevices); NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x20, MAXDEVICES-NumDevices); NumDevices += FindDevices(portnum, &FamilySN[NumDevices], 0x43, MAXDEVICES-NumDevices); if (NumDevices) { mprintf("\r\n"); // read the temperature and print serial number and temperature for (i = NumDevices; i; i--) { mprintf("(%d) ", j++); DisplaySerialNum(FamilySN[i-1]); if (FamilySN[i-1][0] == 0x43) { // if(!Write43(portnum, FamilySN[i-1], write_buffer)) // mprintf("write failed!\n"); owLevel(portnum, MODE_NORMAL); if (ReadMem43(portnum, FamilySN[i-1], read_buffer)) { for(cnt = 0; cnt < 32; cnt++) { mprintf("read_buffer[%x]: %x\n",cnt, read_buffer[cnt]); } } continue; } if (FamilySN[i-1][0] == 0x42) { didRead = ReadTemperature42(portnum, FamilySN[i-1],¤t_temp,&c_frac); } if (didRead) { mprintf(" %d",current_temp); if (c_frac) mprintf(".5"); else mprintf(".0"); mprintf(" deegree celsius\r\n"); } else { mprintf(" Convert failed. Device is"); if(!owVerify(portnum, FALSE)) mprintf(" not"); mprintf(" present.\r\n"); #ifdef SOCKIT_OWM_ERR_ENABLE while(owHasErrors()) mprintf(" - Error %d\r\n", owGetErrorNum()); #endif } } } else mprintf("No temperature devices found!\r\n"); }