I'm new to programming in C and would like a quick bit of help if possible.
Using the 'Hello, World!' example in the Primer manual as a basis I thought I'd display the temperature instead of the string. However, I just can't figure out how to get the data from UTIL_GetTemp().
Please can someone clarify if UTIL_GetTemp() can be used and if so how?
It might be intersting to know what you mean by you can not get data from this function. What have you been trying? You can post your code lines for instance.
Basically, I want to display the temperature on screen by using UTIL_GetTemp().
I know I shouldn't be using UTIL_int2str() as I'm guessing UTIL_GetTemp() will provide a floating number as opposed to an interger but I can't find a way of displaying a floating number on screen.
Code:
/************************* (C) COPYRIGHT 2007 RAISONANCE **********************
* File Name : Application.c
* Author :
* Date First Issued :
* Description : Circle_App CircleOS application template.
* Revision :
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "circle_api.h"
/* Private defines -----------------------------------------------------------*/
#define NEEDEDVERSION "V 1.5" // Put here the minimal CircleOS version needed by your application
/* Private variables ---------------------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
enum MENU_code MsgVersion(void);
/* Public variables ----------------------------------------------------------*/
const char Application_Name[8+1] = {"TempDisp"}; // max 8 characters for application name
/*******************************************************************************
* Function Name : Application_Ini
* Description : Initialization function of Circle_App. This function will
* be called only once by CircleOS.
* Input : None
* Return : MENU_CONTINUE_COMMAND
*******************************************************************************/
enum MENU_code Application_Ini ( void )
{
if(strcmp(UTIL_GetVersion(), NEEDEDVERSION) < 0)
{
return MsgVersion();
}
// TODO: Write your application initialization function here.
return MENU_CONTINUE_COMMAND;
}
/*******************************************************************************
* Function Name : Application_Handler
* Description : Management of the Circle_App.
*
* Input : None
* Return : MENU_CONTINUE
*******************************************************************************/
enum MENU_code Application_Handler ( void )
{
// TODO: Write your application handling here.
// This routine will get called repeatedly by CircleOS, until we
// return MENU_LEAVE
int temp;
char temptext[] ="";
temp = UTIL_GetTemp();
UTIL_int2str(temptext,temp,10,1);
DRAW_DisplayString( 5, 20, temptext, sizeof(temptext)); // X, Y, string, length
return MENU_CONTINUE; // Returning MENU_LEAVE will quit to CircleOS
}
/*******************************************************************************
* Function Name : MsgVersion
* Description : Display the current CircleOS version and the version needed
* exit to main menu after 4 secondes
*
* Input : None
* Return : MENU_CONTINUE
*******************************************************************************/
enum MENU_code MsgVersion(void)
{
int hh,mm,ss,ss2;
DRAW_DisplayString(5,60,"CircleOS",17);
DRAW_DisplayString(80,60,UTIL_GetVersion(),3);
DRAW_DisplayString(5,34,NEEDEDVERSION,3);
DRAW_DisplayString(40,34," required",12);
RTC_GetTime(&hh,&mm,&ss);
ss = ss + 4; // 4 secondes
ss = ss%60;
do
{
RTC_GetTime(&hh,&mm,&ss2);
}while (ss2 != ss); // do while < 4 secondes
return MENU_REFRESH;
}
I think the problem is that UTIL_GetTemp() has been added to Circle_api.h but only to the one in CircleOS ! To resolve this you can download CircleOS version 2 from "Resources" Then copy the file Circle_api.h from CircleOS\source\OS\ to your: C:\Program Files\Raisonance\Ride\Examples\ARM\Primer\STM32\toggle_with_CircleOS\src
Or you can can work directly from the projects in circleOS.
The above solution has now got my first code working. Two more questions now, sorry . . .
1) The numbers which are being displayed range from 450 to 470, I assume this is actually 45.0°C to 47.0°C as if I include UTIL_SetTempMode(1) the range changes to 1160 to 1200?
If the above is correct, I can use a floating number and divide the output by 10
Code:
float temp;
temp = UTIL_GetTemp()/10;
to correct the figure but I now can't find a way of converting a float to a char.
How can I convert a float to a char? The stuff I've found online hasn't helped/worked.
2) As previously mentioned, copying the CircleOS 2.0 circle_api.h file into C:\Program Files\Raisonance\Ride\Examples\ARM\Primer\STM32\toggle_with_CircleOS\src has worked, whoever this didn't work when I previously installed 2.0 as per these instructions: http://www.stm32circle.com/projects/project.php?id=49.