[En-Nut-Discussion] Newbie help ADC (possibly a fprintf problem) and HTML problem
Kathy Quinlan
katinkad at kaqelectronics.dyndns.org
Sun Dec 11 06:29:22 CET 2005
Kathy Quinlan wrote:
> The ADC problem is I think a problem with fprintf.
OOOOPPPSSSSS this should have said more :( The way the ADC is not
working is I get no value, just the string "f Volts" now I stuffed the
line adc_value =20; in JUST to get a value, but that did not help, so I
was back to thinking it is a fprintf problem
By problem I mean a problem I am doing, not anything wrong with the
library ;)
Regards,
Kat.
> Here is my code:
>
>
>
> #include <dev/adc.h> //at the top of the code with other includes
>
>
> /*!
> * \brief CGI callback function to display the value of the ADC Channel.
> *
> * Creates HTML code to show the value of ADC Channel 0.
> * The page will be automatically refreshed every 5 seconds.
> *
> *
> *
> *
> *
> * This function is called by the HTTP module when a browser requests
> * a CGI function, for which this routine has been registered via
> * NutRegisterCgi().
> *
> * \param stream Stream device of the HTTP connection.
> * \param req Pointer to the CGI REQUEST structure. Detailed information
> * is available in the Nut/OS API documentation.
> *
> * \return 0 on success or -1 in case of any failure.
> */
> int ADCStatus(FILE * stream, REQUEST * req)
> {
> u_short adc_value;
>
> static prog_char head[] = /* */
> "<html>" /* */
> "<head>" /* */
> "<meta http-equiv=\"refresh\" content=\"5; URL=" ADC_STATUS_CGI
> "\">" /* */
> "<title>Ethernut CPU ADC Status</title>" /* */
> "</head>" /* */
> "<body bgcolor=\"#C7D0D9\"><a href=\"/\">" /* */
> "<img src=\"/enmini.gif\" border=\"0\" width=\"70\"
> height=\"17\">" /* */
> "</a><div align=\"center\">" /* */
> "<table border=\"1\" cellspacing=\"0\">\r\n" /* */
> "<thead><tr><th rowspan=\"2\"> ADC Channel </th>" /* */
> "<th colspan=\"8\">Value</th></tr>" /* */
> "</thead><tfoot>\r\n";
>
> ADCInit();
> ADCSetChannel(0);
> ADCStartConversion();
> while (ADCRead(&adc_value))
> NutThreadYield();
>
>
> NutHttpSendHeaderTop(stream, req, 200, "Ok");
> NutHttpSendHeaderBot(stream, "text/html", -1);
>
> fputs_P(head, stream);
>
> adc_value =20; //Inserted to test code with fixed value
>
> fputs("<tr><th>0</th>", stream);
> fprintf(stream,"%4.1f Volts",adc_value /1023.0 * 5.0);
> fputs("</tr>\r\n", stream);
>
> fflush(stream);
> return 0;
> }
>
>
>
>
--
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.371 / Virus Database: 267.13.13/197 - Release Date: 9/12/2005
More information about the En-Nut-Discussion
mailing list