static THD_FUNCTION(ThreadGFXVal, arg) { (void)arg; chRegSetThreadName("GFXVal"); while (true) { gwinSetText(ghlblV, util_floatToString(loadvoltage, UNIT_V), TRUE); gwinSetText(ghlblA, util_floatToString(current_mA, UNIT_MA), TRUE); gwinSetText(ghlblW, util_floatToString(((current_mA*loadvoltage)/1000), UNIT_W), TRUE); //gwinSetText(ghlblAH, util_floatToString(milliamphours, UNIT_MAH), TRUE); if ((scaleChanged) && (activeGraph != 3)) { char str[7]; snprintf(str, 7, "%d%s", autoscale_limits[activeGraph][graph_MAX[activeGraph]], units[graphUnits[activeGraph]]); gwinSetText(ghBtnScale, str, TRUE); drawGraphLines(ghContainerGraphC); scaleChanged = false; } if (activeGraph == 3) { char str[7]; snprintf(str, 7, "%d%s", autoscale_limits[0][graph_MAX[0]], units[graphUnits[0]]); gwinSetText(ghBtnScale, str, TRUE); scaleChanged = false; snprintf(str, 7, "%d%s", autoscale_limits[1][graph_MAX[1]], units[graphUnits[1]]); gwinDrawString(ghContainerGraphCV_2, gwinGetWidth(ghContainerGraphCV_2)-25, 5, str); drawGraphLines(ghContainerGraphCV_1); drawGraphLines(ghContainerGraphCV_2); } chThdSleepMilliseconds(500); } }
/* new window size or exposure */ static void setup(void) { GLfloat h = (GLfloat) gwinGetWidth(gh) / (GLfloat) gwinGetHeight(gh); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef( 0.0, 0.0, -40.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); }
int main(void) { GHandle gh; uint16_t i; gfxInit(); { GWindowInit wi; gwinClearInit(&wi); wi.show = TRUE; wi.x = wi.y = 0; wi.width = gdispGetWidth(); wi.height = gdispGetHeight(); gh = gwinGraphCreate(&g, &wi); } gwinGraphSetOrigin(gh, gwinGetWidth(gh)/2, gwinGetHeight(gh)/2); gwinGraphSetStyle(gh, &GraphStyle1); gwinGraphDrawAxis(gh); for(i = 0; i < gwinGetWidth(gh); i++) gwinGraphDrawPoint(gh, i-gwinGetWidth(gh)/2, 80*fsin(2*i/5)); //sin(2*0.2*M_PI*i/180)); gwinGraphStartSet(gh); GraphStyle1.point.color = uGreen; gwinGraphSetStyle(gh, &GraphStyle1); for(i = 0; i < gwinGetWidth(gh)*5; i++) gwinGraphDrawPoint(gh, i/5-gwinGetWidth(gh)/2, 95*fsin(2*i/5)); //sin(2*0.2*M_PI*i/180)); gwinGraphStartSet(gh); gwinGraphSetStyle(gh, &GraphStyle2); gwinGraphDrawPoints(gh, data, sizeof(data)/sizeof(data[0])); while(TRUE) { gfxSleepMilliseconds(100); } }
void drawGraphLines(GHandle gh) { //color_t oldColor; //oldColor = gh->color; // gh->color=White; // //Vertical Line // gwinDrawLine(gh, 5,0, 5,gwinGetHeight(gh)); // gwinDrawLine(gh, 0,(gwinGetHeight(gh)/2)-5, 5,(gwinGetHeight(gh)/2)-5); //half way tick // gwinDrawLine(gh, 3,(gwinGetHeight(gh)/4)-5, 5,(gwinGetHeight(gh)/4)-5); //qtr ticks // gwinDrawLine(gh, 3,((gwinGetHeight(gh)/4)*3)-5, 5,((gwinGetHeight(gh)/4)*3)-5); //qtr ticks // gwinDrawLine(gh, 0,0, 5,0); //top end // //Horizontal Line // gwinDrawLine(gh, 0,gwinGetHeight(gh)-5, gwinGetWidth(gh),gwinGetHeight(gh)-5); // gwinDrawLine(gh, (gwinGetWidth(gh)/2)+5, gwinGetHeight(gh)-5, (gwinGetWidth(gh)/2)+5, gwinGetHeight(gh)); //half way tickhttps://www.google.com/webhp?hl=en // gwinDrawLine(gh, (gwinGetWidth(gh)/4)+5, gwinGetHeight(gh)-5, (gwinGetWidth(gh)/4)+5, gwinGetHeight(gh)-3); //qtr tick // gwinDrawLine(gh, ((gwinGetWidth(gh)/4)*3)+5, gwinGetHeight(gh)-5, ((gwinGetWidth(gh)/4)*3)+5, gwinGetHeight(gh)-3); //qtr way tick // gwinDrawLine(gh, gwinGetWidth(gh)-1, gwinGetHeight(gh)-5, gwinGetWidth(gh)-1, gwinGetHeight(gh)); //bottom end coord_t i, j; color_t r,g,b; coord_t width = gwinGetWidth(gh); coord_t height = gwinGetHeight(gh); for (i = 0; i < width; i++) { for(j = 0; j < height; j++) { //r = ((((_acgraphH[i+(j*width)] >> 11) & 0x1F)*527)+23) >> 6; //g = ((((_acgraphH[i+(j*width)] >> 5) & 0x3f)*259)+33) >> 6; //b = (((_acgraphH[i+(j*width)]) & 0x1f) + 23) >> 6; if (activeGraph == 3 || gh->parent == ghContainerGraphCV) { r = RED_OF(_acgraphH2[i+(j*width)] >> 11); g = GREEN_OF(_acgraphH2[i+(j*width)] >> 5); b = BLUE_OF(_acgraphH2[i+(j*width)]); surface2[j*width+i]=(RGB2COLOR(r,g,b)); } else { r = RED_OF(_acgraphH[i+(j*width)] >> 11); g = GREEN_OF(_acgraphH[i+(j*width)] >> 5); b = BLUE_OF(_acgraphH[i+(j*width)]); surface[j*width+i]=(RGB2COLOR(r,g,b)); } //gwinDrawPixel(pixmap,i, j); }