Skip to content

Commit 042c925

Browse files
committed
NXT temperaturesensor completed
Readout in °C and °F
1 parent 5d4c4bb commit 042c925

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

API/ev3sensor.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
//NXT Temperture
7979
#define NXT_TEMP_TYPE 6
8080
#define NXT_TEMP_C_MODE 0 // Temperature in C
81-
#define NXT_TEMP_C_MODE 1 // Temperature in F
81+
#define NXT_TEMP_F_MODE 1 // Temperature in F
8282
/***********************************/
8383

8484
int g_uartFile = 0;
@@ -322,7 +322,13 @@ int readSensor(int sensorPort)
322322
}
323323
return ((help>>4) & 0xFF)*10 + ((help & 0xF) * 10 / 15);
324324
case NXT_TEMP_F:
325-
return -1;
325+
help = (*data>>4) & 0x0FFF;
326+
if(help & 0x800)
327+
{
328+
help = ((help&0x7FF) ^ 0x7FF) + 1;
329+
return (-1)*(((help>>4) & 0xFF)*10 + ((help & 0xF) * 10 / 15)) * 9/5 + 320;
330+
}
331+
return (((help>>4) & 0xFF)*10 + ((help & 0xF) * 10 / 15)) * 9/5 + 320;
326332
default: break;
327333
}
328334
return *((DATA16*)data);
@@ -488,6 +494,9 @@ int setAllSensorMode(int name_1, int name_2, int name_3, int name_4)
488494
devCon.Mode[sensorPort] = NXT_TEMP_C_MODE;
489495
break;
490496
case NXT_TEMP_F:
497+
devCon.Connection[sensorPort] = CONN_NXT_IIC;
498+
devCon.Type[sensorPort] = NXT_TEMP_TYPE;
499+
devCon.Mode[sensorPort] = NXT_TEMP_F_MODE;
491500
break;
492501
default: return -1;
493502
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
This API supports the follwing functionallity:
33
* Easy initialistion with one header-file
44
* Controlling LEGO motors
5-
* Reading out of Touch, Ultrasonic, Color, Gyro, EV3-Infrared and NXT-Infrared Sensor
5+
* Reading out of Touch, Ultrasonic, Color, Gyro, EV3-Infrared, NXT-Infrared Sensor and NXT Temperaturesensor
66
* Controling Buttons and LED
77
* Printing text on LCD
88

0 commit comments

Comments
 (0)