gpt4 book ai didi

比较高值和低值以调用函数

转载 作者:太空宇宙 更新时间:2023-11-04 06:35:23 26 4
gpt4 key购买 nike

我想将温度传感器中的电流与我在程序中使用结构设置的上限值进行比较。如果温度传感器值超过当前上限我只想printf一个声明。

这段代码有什么问题,无论当前温度如何,它都不会打印出 printf 语句。请假定所有必要的头文件、定义等都已在程序中说明。

它作为一个整体工作正常,但我不明白为什么我不能让一个简单的 printf 命令出现!!请假定所有需要的定义都已完成,所有 typedef 都已相应定义。

这是我的结构

struct temperatureChannel_t { //set a structure that encompasses all of the follow elements in an array
temperature_t temperatureArray;
temperature_t temperatures[MAXSAMPLES];
temperature_t currentTemperature;
temperature_t lowLimit;
temperature_t highLimit;
temperature_t minTemperature;
temperature_t maxTemperature;

};

struct temperatureChannel_t temperatureChannel[MAXCHANNELS];

这是我如何初始化当前上限

void initializeTemperatureSubsystem()
{
currentInsertionPoint = 0;
for(int chID = 0; chID < MAXCHANNELS; chID++)
{
srand(time(NULL));
for(int i = 1; i < MAXSAMPLES; i++)
{
temperatureChannel[chID].temperatures[i] = rand()%100;
}
temperatureChannel[chID].lowLimit = 50;
temperatureChannel[chID].highLimit = 100;
temperatureChannel[chID].currentTemperature = 75;

averageIsValid = FALSE; //NEW line
}

}

这是我设置当前温度的方式,首先是调用函数

setCurrentTemperature(CH1, temperatureSensor1Reading);

然后是函数

temperature_t setCurrentTemperature(int channelID, temperature_t temperature)
{
return temperatureChannel[channelID].currentTemperature;
}

首先,我使用我正在使用的当前 channel 调用该函数

compareHighLimit(CH1);

那么这里是不会打印出 printf 命令的函数

void compareHighLimit (int channelID)
{
if (temperatureChannel[channelID].currentTemperature > temperatureChannel[channelID].highLimit)
printf("you have activated the high alarm!!");
}

最佳答案

您的 set temp 函数实际上并未设置值:

temperature_t setCurrentTemperature(int channelID, temperature_t temperature)
{
// you need to set the data here, not just return the existing value
return temperatureChannel[channelID].currentTemperature;
}

关于比较高值和低值以调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15602214/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com