[En-Nut-Discussion] Newbie help ADC (possibly a fprintf problem) and HTML problem

Kathy Quinlan katinkad at kaqelectronics.dyndns.org
Sun Dec 11 06:23:38 CET 2005


Hi all,

First off thanks to Harald and the rest of the crew for such a great 
product.

My problems

I am adding some code into the webport utility to read the ADC, right 
now it is just ADC0 (ie the first channel)

The HTML issue is just that I do not get a value in the box, I get the 
word "Volts" above the table with an "f" in front of it.

The ADC problem is I think a problem with fprintf.


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;

     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