/***************************************************************************** * Method: oneWireTask * Description: This method runs the oneWire task ****************************************************************************/ void oneWire::oneWireTask (void) { static uint8_t runs = 0; uint8_t low_byte, high_byte; int16_t temp; int32_t temp_f; //if ((runs % 5) == 0) //{ //DBG(this->p_serial, "\r\noneWire Task Running on device: %d\r\n", dev_id); // perform temperature conversion reset(); write_byte(0xCC); // skip ROM write_byte(0x44); // single temp conversion // read in scratch pad reset(); write_byte(0xCC); // skip ROM write_byte(0xBE); // read scratchpad // read temperature low_byte = read_byte(); high_byte = read_byte(); temp = (high_byte << BYTE_SHIFT) | low_byte; temp = convert_temp(temp); temp_f = TEMP_C_TO_F((int32_t)temp); // update global value if (dev_id == ID_SURFACE_TEMP) { surf_temp = temp_f; } else if (dev_id == ID_UNDERWATER_TEMP) { sub_temp = temp_f; } //DBG(this->p_serial, "Temp sensor %d: %d.%02dC or %ld.%02ldF\r\n", // dev_id, // (temp / 100), (temp % 100), // (temp_f / 100), (temp_f % 100)); //} runs++; }
void task_i2c_get_temp_func(const struct task_item *task) { uint8_t temp[2]; int t_out, fract; /* * Wait in OS friendly way for request to run. */ if (!read_temp_enabled) { OS_EVENT_WAIT(event, OS_EVENT_FOREVER); } /* * Require I2C for exclusively reading temperature from FM75 and release it after operation. */ resource_acquire(RES_MASK(RES_ID_I2C1), RES_WAIT_FOREVER); set_target_address(FM75_ADDRESS); /* * Read actual temperature values from FM75. */ fm75_read_reg(FM75_REG_TEMP, temp, sizeof(temp)); resource_release(RES_MASK(RES_ID_I2C1)); /* * Send results to UART. */ t_out = convert_temp(temp, &fract); printf("current temperature: %d.%04d C" NEWLINE, t_out, fract); /* * Wait 1 second to get temperature again. */ OS_DELAY(1000); }
void send() { wildfire_packet_t * wp; net_packet_t * np; uint16_t sample; uint8_t sends; sends = 0; init_devs(); mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP); //sets power save mode //just wait while in init state while (state != GO) { mos_mdelay(500); } while (1) { if (state == SLEEPNODE) { disable_wind_speed(); //must disable the ext interrupts for power save sleep //mos_thread_set_suspend_state(SUSPEND_STATE_SLEEP); //sets power save mode mos_thread_sleep(SLEEP_INTERVAL - 1000); //extra 1000 to make sure it wakes up early //mos_thread_set_suspend_state(SUSPEND_STATE_IDLE); //idle mode while (state != GO) //awake, but not ready yet.. so just wait mos_mdelay(250); sends = 0; } //first populate the buffer with the net packet since this will //always be the header np = (net_packet_t *)&(sendBuf.data[0]); np->type = DATA; np->src = myID; np->dest = baseID; np->next_hop = myParentID; np->last_hop = myID; np->seqno = mySeqNo; np->pkt_dtb = myDTB; np->sender_dtb = myDTB; sendBuf.size = sizeof(net_packet_t); //for data packets, we now populate the buffer with the //wildfire packet information. Adding it to the end. wp = (wildfire_packet_t *)&(sendBuf.data[sendBuf.size]); //temp dev_open(DEV_MICA2_TEMP); dev_read(DEV_MICA2_TEMP, &sample, sizeof(sample)); dev_close(DEV_MICA2_TEMP); wp->temp = convert_temp(sample); //battery dev_open(DEV_MICA2_BATTERY); dev_read(DEV_MICA2_BATTERY, &sample, sizeof(sample)); dev_close(DEV_MICA2_BATTERY); wp->battery = sample; //humidity humidity_on(); mos_mdelay(200); //settling time dev_open(DEV_ADC); dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, AVR_ADC_CH_2); dev_read(DEV_ADC, &sample, sizeof(sample)); dev_close(DEV_ADC); humidity_off(); wp->humidity = convert_humidity(sample, wp->battery); //wind direction wind_dir_on(); dev_open(DEV_ADC); dev_ioctl(DEV_ADC, ADC_SET_CHANNEL, AVR_ADC_CH_1); dev_read(DEV_ADC, &sample, sizeof(sample)); dev_close(DEV_ADC); wind_dir_off(); wp->wind_direction = convert_direction(sample); //wind speed wp->wind_speed = wind_speed; sendBuf.size += sizeof(wildfire_packet_t); //debug info: /* printf("type\tsrc\tdest\tnext\tlast\tseq\tpktdtb\ts_dtb\n"); printf("%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", np->type, np->src, np->dest, np->next_hop, np->last_hop, np->seqno, np->pkt_dtb, np->sender_dtb); printf("temp\thmdty\tw_dir\tw_spd\tbat\n"); printf("%d\t%d\t%d\t%d\t%d\n", wp->temp, wp->humidity, wp->wind_direction, wp->wind_speed, wp->battery); */ if (rate == 0 || sends < rate*myDTB) { com_send(IFACE_RADIO, &sendBuf); mySeqNo++; sends++; } if (mySeqNo > 254) mySeqNo = 0; mos_mdelay(1000); } }