嵌入式开发实践的柱状图代码

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include <fcntl.h>
#include "s3c2410-adc.h"

#define ADC_DEV "/dev/adc/0raw"
static int adc_fd = -1;

static int init_ADdevice(void)
{
if((adc_fd=open(ADC_DEV, O_RDWR))<0){
printf("Error opening %s adc device\n", ADC_DEV);
return -1;
}
}

static int GetADresult(int channel)
{
int PRESCALE=0XFF;
int data=ADC_WRITE(channel, PRESCALE);
write(adc_fd, &data, sizeof(data));
read(adc_fd, &data, sizeof(data));
return data;
}
static int stop=0;
int main(void)
{
int i;
float d1=0;
float d2=0;
float d3=0;
void * retval;

//set s3c44b0 AD register and start AD
if(init_ADdevice()<0)
return -1;

/* Create the threads */
if( stop == 0){
d1=((float)GetADresult(0)*3.3)/1024.0;
d2=((float)GetADresult(1)*3.3)/1024.0;
d3=((float)GetADresult(2)*3.3)/1024.0;
printf("<html>
<head><h1>Picture--XXXXX</h1>
<meta http-equiv='refresh' content='1' />
<style>

html, body { width : 100%; height : 100%; margin :30% ; padding : 30%; }

.wrapper { position : relative; width : 420px; margin : 0 auto; padding : 0; font-size : 0;

}

.icon { position : relative; display : inline-block; width : 100px; height : 100px; margin :

20px; border-radius : 18px; -webkit-box-sizing : border-box; -moz-box-sizing : border-box;

box-sizing : border-box; }

body { padding: 0; margin: 40px; font-size: 9pt; font-family: Helvetica, Geneva, sans-serif;

}

h3 { font-weight: normal; display: block; width: 600px; text-align: center; }

ul#q-graph { border: 2px solid #0063be; background: #adfe12; height: 300px !important;

height: 304px; width: 600px; position: relative; list-style: none; margin: 1.1em 1em 3.5em;

padding: 0; }

#q-graph li { position: absolute; text-align: center; bottom: 0; padding:0 margin:0;

}

li.qtr { width: 150px; height: 300px; border-right: 1px dotted #41a3e2; z-index: 2; }

li#q1 { left: 0; }

h1 {
padding-bottom: 20px;
border-bottom-width: medium;
border-bottom-style: solid;
border-bottom-color: #333333;
height: auto;
width: 1999px;
}
#qq {
padding-left: 30%;
}
li#q2 { left: 150px; }

li#q3 { left: 300px; }

li#q4 { left: 450px; border-right: none; }

#q-graph ul { list-style: none; }

li.bar { width: 34px; color: #fff; }

li.v1 { left: 36px; background: ");
if(d1<=1.5)
printf( "green");
else if(d1<=2.7)
printf( "yellow");
else
printf("red");
printf( "; }
li.v2 { left: 36px; background: ");
if(d2<=1.5)
printf( "green");
else if(d2<=2.7)
printf( "yellow");
else
printf("red");
printf("; }
li.v3 { left: 36px; background: ");
if(d3<=1.5)
printf( "green");
else if(d3<=2.7)
printf( "yellow");
else
printf("red");
printf("; }
li#ticks { left: 0; height: 300px; width: 100%; z-index: 1; }

div.ticks { position: relative; height: 60px; border-top: 1px dotted #41a3e2; }

div.ticks:first-child { border-top: none; }

div.ticks p { position: absolute; left: 103%; top: -11pt; }

</style>
</head>
<body>
<h1>xxxxxxxxxxxxPIcXXXXXXXXXXX</h1>
<div id="qq">
<ul id='q-graph'>

<li id='q1' class='qtr'>V1

<ul>
<li class='v1 bar' style='height:%fpx;'>%4.2f",d1*90,d1);
printf("</li>
</ul>

</li>

<li id='q2' class='qtr'>V2

<ul>
<li class='v2 bar' style='height:%fpx;'>%4.2f",d2*90,d2);
printf("</li>
</ul>

</li>

<li id='q3' class='qtr'>V3

<ul>
<li class='v3 bar' style='height:%fpx;'>%4.2f",d3*90,d3);
printf("</li>
</ul>

</li>

<li id="ticks">

<div class="ticks">

<p>3.3</p>

</div>

<div class="ticks">

<p>2.6</p>

</div>

<div class="ticks">

<p>2.0</p>

</div>

<div class="ticks">

<p>1.3</p>

</div>

<div class="ticks">

<p>0.6</p>

</div>

</li>

</ul>
</div>
</body>
</html>

");
}

/* Wait until producer and consumer finish. */
}

猜你喜欢

转载自www.cnblogs.com/dys6/p/11304130.html
今日推荐