uint8_t read_DHT11(uint8_t *buf){ uint16_t dt[42]; uint16_t cnt; uint8_t i, check_sum; //reset DHT11 Delay(500); GPIO_LOW(GPIOA,GPIO_Pin_2); Delay(20); GPIO_HIGH(GPIOA,GPIO_Pin_2); //start reading cnt = 0; for(i=0;i<83 && cnt<MAX_TICS;i++){ if (i & 1){ cnt = read_cycle(cnt, 1); } else { cnt = read_cycle(cnt, 0); dt[i/2]= cnt; } } //release line GPIO_HIGH(GPIOA,GPIO_Pin_2); if (cnt>=MAX_TICS) return DHT11_NO_CONN; //convert data for(i=2;i<42;i++){ (*buf) <<= 1; if (dt[i]>20) { (*buf)++; } if (!((i-1)%8) && (i>2)) { buf++; } } //calculate checksum buf -= 5; check_sum = 0; for(i=0;i<4;i++){ check_sum += *buf; buf++; } if (*buf != check_sum) return DHT11_CS_ERROR; return DHT11_OK; //return check_sum; }
void animate(void) { char string[MAX_STRING]; if (file_done){ glutIdleFunc(NULL); show_stat = HOLD; } if (file_done && jpeg) { jpeg = False; moldyn_update_graphics(); glutPostRedisplay(); sprintf(string, "cat %s????.jpg | ffmpeg -y -v 0 -r 30 -f image2pipe -vcodec mjpeg -i - -vcodec mpeg4 %s.mov", name, name); system(string); return; } /* Redraw for animation (no display lists) */ read_cycle(); moldyn_update_graphics(); glutPostRedisplay(); if (jpeg) { moldyn_export_(MOLDYN_EXPORT_TO_JPEG, window_width, window_height); } }
static void moldyn_menu_frame_(int value) { switch (value) { case 0: if (current_cycle == 1) { break; } show_stat = SHOW_PREV; current_cycle -= 2; file_done = 0; if (feof(fptr)) rewind(fptr); if (fsetpos(fptr, &cycle_position[current_cycle])) moldyn_error("can't position file"); read_cycle(); moldyn_update_graphics(); glutPostRedisplay(); break; case 1: if (file_done && last_init_done) { break; } else { show_stat = SHOW_NEXT; read_cycle(); moldyn_update_graphics(); glutPostRedisplay(); break; } case 2: if (show_stat == HOLD && !file_done) { glutIdleFunc(animate); show_stat = SHOW_ALL; } else if (show_stat == SHOW_ALL) { jpeg = False; show_stat = HOLD; moldyn_update_graphics(); glutPostRedisplay(); } break; } }
void makePov(int type) { int xres, yres; float x,y,z; double c1 = cos(torad(-rotation-10)); double s1 = sin(torad(-rotation-10)); double c2 = cos(torad(-tilt-20)); double s2 = sin(torad(-tilt-20)); xres = resolution * 1.25 + 0.5; yres = 0.8 * xres + 0.5; while (True) { if (1.0 * xres / yres > 1.25) { yres++; } else if (1.0 * xres / yres < 1.25) { xres++; } else { break; } } x = -c1 * xeye + s1 * zeye; y = s1 * s2 * xeye - c2 * yeye + s2 * c1 * zeye; z = -c2 * s1 * xeye - s2 * yeye - c2 * c1 * zeye; gr3_setlightdirection(x, y, z); gr3_setquality(GR3_QUALITY_POVRAY_8X_SSAA); if (povray == -9999) { moldyn_export_(type,xres,yres); } else if (povray > 0) { rewind(fptr); current_cycle = 0; while (True) { read_cycle(); if (file_done) break; moldyn_update_graphics(); moldyn_export_(type,xres,yres); } } gr3_setquality(GR3_QUALITY_OPENGL_NO_SSAA); gr3_setlightdirection(0, 0, 0); }
int main(int argc, char **argv) { ac = argc; avp = argv; reset_element_information(); if (argc < 2) { moldyn_usage(); } moldyn_init_graphics(&argc, argv, argv[1]); read_dat(); if (autoscale) { analyze(); } read_cycle(); range = fabs(zmax) + fabs(zmin); if (range < fabs(xmax) + fabs(xmin)) range = fabs(xmax) + fabs(xmin); if (range < fabs(ymax) + fabs(ymin)) range = fabs(ymax) + fabs(ymin); magnification = pow(1.2, (double) magstep); zeye = -2.0 * range * magnification; moldyn_update_graphics(); if (povray <= 0) { start_mainloop(); } else { makePov(MOLDYN_EXPORT_TO_PNG); } return 0; }
static void keyboard(unsigned char key, int x, int y) { switch (key) { case 'a': povray = pix = -9999; makePov(MOLDYN_EXPORT_TO_PNG); break; case 'r': if (magstep <= 10) { magstep++; magnification = pow(1.2, (double) magstep); zeye = -2 * range * magnification; glutPostRedisplay(); } break; case 'm': if (magstep >= -10) { magstep--; magnification = pow(1.2, (double) magstep); zeye = -2 * range * magnification; glutPostRedisplay(); } break; case 's': if (move_stat == ROTATE) { move_stat = TRANSLATE; } else if (move_stat == TRANSLATE) { move_stat = ROTATE; } break; case 'n': if (file_done && last_init_done) { break; } else { show_stat = SHOW_NEXT; read_cycle(); moldyn_update_graphics(); glutPostRedisplay(); break; } case 'b': if (current_cycle == 1) { break; } show_stat = SHOW_PREV; current_cycle -= 2; file_done = 0; if (feof(fptr)) rewind(fptr); if (fsetpos(fptr, &cycle_position[current_cycle])) moldyn_error("can't position file"); read_cycle(); moldyn_update_graphics(); glutPostRedisplay(); break; case 'h': case 'j': if (show_stat == HOLD && !file_done) { if (key == 'j') { jpeg = True; moldyn_export_(MOLDYN_EXPORT_TO_JPEG, window_width, window_height); } glutIdleFunc(animate); show_stat = SHOW_ALL; } else if (show_stat == SHOW_ALL) { jpeg = False; show_stat = HOLD; moldyn_update_graphics(); glutPostRedisplay(); } break; case 'c': case 'C': moldyn_export_(MOLDYN_EXPORT_TO_JPEG, 800, 800); break; case 'J': moldyn_export_(MOLDYN_EXPORT_TO_JPEG, window_width, window_height); break; case 'p': { char *argv[] = {"jpeg2ps", "-o", "moldyn.eps", path}; moldyn_export_(MOLDYN_EXPORT_TO_JPEG, 2000, 2000); jpeg2ps_main(sizeof(argv)/sizeof(char *),argv); } #ifdef _WIN32 system("copy moldyn.eps %PRINTER%"); #else system("lpr -h moldyn.eps"); #endif break; case '0': xeye = 0.0; yeye = 0.0; zeye = -2.0 * range; glutPostRedisplay(); break; case '?': hint = (hint) ? False : True; glutPostRedisplay(); break; case 'T': case 't': numbers = (numbers) ? False : True; glutPostRedisplay(); break; case 'q': case 'Q': case GLUT_KEY_ESCAPE: moldyn_exit(0); break; } }