added lab 3
This commit is contained in:
parent
befa1f0507
commit
50db86ee9e
BIN
S3/contiki-sky.a
Normal file
BIN
S3/contiki-sky.a
Normal file
Binary file not shown.
2888
S3/contiki-sky.map
Normal file
2888
S3/contiki-sky.map
Normal file
File diff suppressed because it is too large
Load Diff
74
S3/sensor.c
74
S3/sensor.c
@ -3,24 +3,62 @@
|
||||
#include "dev/sht11-sensor.h"
|
||||
#include <stdio.h> /* For printf() */
|
||||
|
||||
typedef unsigned short USHORT;
|
||||
|
||||
//print a unsigned short (as returned from rand) picewise char by char
|
||||
void
|
||||
putShort(USHORT in)
|
||||
{
|
||||
// recursively shift each digit of the int to units from most to least significant
|
||||
if (in >= 10)
|
||||
{
|
||||
putShort(in / 10);
|
||||
}
|
||||
// isolate unit digit from each number by modulo and add '0' char to turn integer into corresponding ascii char
|
||||
putchar((in % 10) + '0');
|
||||
}
|
||||
|
||||
void
|
||||
putFloat(float in)
|
||||
{
|
||||
if(in < 0)
|
||||
{
|
||||
putchar('-'); // print negative sign if required
|
||||
in = -in;
|
||||
}
|
||||
|
||||
USHORT integerComponent = (USHORT) in; // truncate float to integer
|
||||
float fractionComponent = (in - integerComponent) * 1000; // take fraction only and promote to integer
|
||||
if (fractionComponent - (USHORT)fractionComponent >= 0.5) fractionComponent++; // round
|
||||
|
||||
putShort(integerComponent);
|
||||
putchar('.');
|
||||
putShort((USHORT) fractionComponent);
|
||||
}
|
||||
|
||||
float getTemperature(void)
|
||||
{
|
||||
int tempData;
|
||||
int tempData;
|
||||
|
||||
// NOTE: You only need to use one of the following
|
||||
// If you run the code in Cooja Simulator, please remove the second one
|
||||
//tempData = sht11_sensor.value(SHT11_SENSOR_TEMP_SKYSIM); // For Cooja Sim
|
||||
tempData = sht11_sensor.value(SHT11_SENSOR_TEMP); // For XM1000 mote
|
||||
// NOTE: You only need to use one of the following
|
||||
// If you run the code in Cooja Simulator, please remove the second one
|
||||
tempData = sht11_sensor.value(SHT11_SENSOR_TEMP_SKYSIM); // For Cooja Sim
|
||||
//tempData = sht11_sensor.value(SHT11_SENSOR_TEMP); // For XM1000 mote
|
||||
|
||||
float temp = tempData; // you need to implement the transfer function here
|
||||
return temp;
|
||||
float d1 = -39.6f;
|
||||
float d2 = 0.01f;
|
||||
float temp = d1 + (d2 * tempData); // you need to implement the transfer function here
|
||||
return temp;
|
||||
}
|
||||
|
||||
float getLight(void)
|
||||
{
|
||||
int lightData = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
float light = lightData; // you need to implement the transfer function here
|
||||
return light;
|
||||
int lightData = light_sensor.value(LIGHT_SENSOR_PHOTOSYNTHETIC);
|
||||
|
||||
float V_sensor = 1.5 * lightData / 4096;
|
||||
float I = V_sensor/1e5;
|
||||
float light = 0.625 * 1e6 * I * 1000; // you need to implement the transfer function here
|
||||
return light;
|
||||
}
|
||||
|
||||
|
||||
@ -32,8 +70,7 @@ PROCESS_THREAD(sensor_reading_process, ev, data)
|
||||
{
|
||||
static struct etimer timer;
|
||||
PROCESS_BEGIN();
|
||||
etimer_set(&timer, CLOCK_CONF_SECOND/4); // you need to put the correct
|
||||
// timer setting here
|
||||
etimer_set(&timer, CLOCK_SECOND); // you need to put the correct timer setting here
|
||||
SENSORS_ACTIVATE(light_sensor);
|
||||
SENSORS_ACTIVATE(sht11_sensor);
|
||||
|
||||
@ -45,8 +82,17 @@ PROCESS_THREAD(sensor_reading_process, ev, data)
|
||||
float temp = getTemperature();
|
||||
float light_lx = getLight();
|
||||
|
||||
printf("%d\n", ++counter); // you should also print the temperature
|
||||
// and light intensity here
|
||||
printf("%d\n", ++counter); // you should also print the temperature and light intensity here
|
||||
printf("Temperature: ");
|
||||
putFloat(temp);
|
||||
printf(" C");
|
||||
putchar('\n');
|
||||
|
||||
printf("Light: ");
|
||||
putFloat(light_lx);
|
||||
putchar('\n');
|
||||
|
||||
putchar('\n');
|
||||
|
||||
etimer_reset(&timer);
|
||||
}
|
||||
|
BIN
S3/sensor.sky
Normal file
BIN
S3/sensor.sky
Normal file
Binary file not shown.
4
S3/symbols.c
Normal file
4
S3/symbols.c
Normal file
@ -0,0 +1,4 @@
|
||||
#include "symbols.h"
|
||||
|
||||
const int symbols_nelts = 0;
|
||||
const struct symbols symbols[] = {{0,0}};
|
3
S3/symbols.h
Normal file
3
S3/symbols.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "loader/symbols.h"
|
||||
|
||||
extern const struct symbols symbols[1];
|
Loading…
Reference in New Issue
Block a user