lab3-2-4_working_with_c
This commit is contained in:
parent
b3f0a69fb5
commit
fc803713dd
@ -45,6 +45,8 @@ typedef struct SensorSetStruct
|
||||
{
|
||||
Sensor temperature;
|
||||
Sensor pressure;
|
||||
void (* Update)(struct SensorSetStruct *sensorSet);
|
||||
void (* Display)(struct SensorSetStruct *sensorSet);
|
||||
} SensorSet;
|
||||
|
||||
/**
|
||||
@ -53,7 +55,6 @@ typedef struct SensorSetStruct
|
||||
* @param sensorSet
|
||||
*/
|
||||
void defaultUpdateSensorValues(struct SensorSetStruct *sensorSet) {
|
||||
|
||||
int random = abs(esp_random());
|
||||
sensorSet->temperature.value.f = (random % 400) / 10;
|
||||
random = abs(esp_random());
|
||||
@ -75,10 +76,9 @@ void defaultPrintSensorValues(struct SensorSetStruct *sensorSet) {
|
||||
*
|
||||
* @param sensorSet
|
||||
*/
|
||||
void updateAndDisplaySensorValues(struct SensorSetStruct *sensorSet, void function()) {
|
||||
|
||||
function(sensorSet);
|
||||
function(sensorSet);
|
||||
void updateAndDisplaySensorValues(struct SensorSetStruct *sensorSet) {
|
||||
sensorSet->Update(sensorSet);
|
||||
sensorSet->Display(sensorSet);
|
||||
}
|
||||
|
||||
|
||||
@ -89,11 +89,13 @@ void updateAndDisplaySensorValues(struct SensorSetStruct *sensorSet, void functi
|
||||
|
||||
void app_main(void) {
|
||||
|
||||
|
||||
|
||||
/* TODO:
|
||||
Declare and init sensorSet variable (structure is SensorSetStruct)
|
||||
Tip: Use designated initializer
|
||||
*/
|
||||
struct SensorSetStruct houlou = {
|
||||
static struct SensorSetStruct houlou = {
|
||||
.temperature=
|
||||
{
|
||||
.name="TEMP",
|
||||
@ -105,18 +107,20 @@ void app_main(void) {
|
||||
.name="PRES",
|
||||
.type=INT,
|
||||
.value={.i=0}
|
||||
}
|
||||
},
|
||||
.Update= defaultUpdateSensorValues,
|
||||
.Display= defaultPrintSensorValues
|
||||
};
|
||||
|
||||
|
||||
while (1) {
|
||||
// Wait for 1 sec.
|
||||
usleep(1000000);
|
||||
updateAndDisplaySensorValues(&houlou,defaultPrintSensorValues);
|
||||
printf ("\n%d\n", sizeof (int));
|
||||
updateAndDisplaySensorValues(&houlou);
|
||||
|
||||
/*printf ("\n%d\n", sizeof (int));
|
||||
printf ("\n%d\n", sizeof (float));
|
||||
printf ("\n%d\n", sizeof (double));
|
||||
printf ("\n%d\n", sizeof (union SensorValueUnion));
|
||||
printf ("\n%d\n", sizeof (union SensorValueUnion));*/
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user