/** * @brief 打开或关闭背景灯 * @param ison 操作方式, 1-打开, 0-关闭 */ void LcdBakLight(int ison) { if(ison) { set_io(AT91_PIN_PB30,1);//打开背景灯命令 } else { set_io(AT91_PIN_PB30,0); } }
/* ** Run semicolon ** @params self, shell, io ** @return return value */ int semicoma_run(t_command *self, t_shell *shell, t_io *io) { int status; set_io(io, 0, 1); status = 256; if (self->left != NULL) status = self->left->run(self->left, shell, io); set_io(io, 0, 1); if (self->right != NULL) status = self->right->run(self->right, shell, io); set_io(io, 0, 1); return (status); }
int YARPMEIDeviceDriver::setOutputPort(void *cmd) { int16 rc = 0; IOParameters *par = (IOParameters *) cmd; rc = set_io(par->port, (short) par->value); return rc; }
int main(int argc, char **argv, char **envp) { int fd; char *p; background_process(NAME, UID, GID); fd = serve_forever(PORT); set_io(fd); parse_http_request(); }
/** W przypadku kiedy flaga \ref OUTPUTS_CHANGE_FLAG w jest ustawiona należy zaktualizować stan wyjść. */ void outputs_update(void) { uint8_t i,j; uint8_t output_temp; if (OUTF(OUTPUTS_CHANGE_FLAG)) { for (i=0;i<OUTPUTS_DEVICES_NUM;i++) { output_temp = 0; for (j=0;j<OUTPUTS_NUM_PER_DEVICE;j++) { output_temp |= (outputs[i*OUTPUTS_NUM_PER_DEVICE+j].flags & _BV(OUTPUT_ACTIVE_FLAG)) >> (OUTPUTS_NUM_PER_DEVICE - 1 - j); } set_io(pgm_read_byte(&OUTPUTS_DEVICES_ADDRS[i]) & 0xFE,output_temp); } COUTF(OUTPUTS_CHANGE_FLAG); } }
int main(int argc, char **argv, char **envp) { int fd; char *username; /* Run the process as a daemon */ background_process(NAME, UID, GID); /* Wait for socket activity and return */ fd = serve_forever(PORT); /* Set the client socket to STDIN, STDOUT, and STDERR */ set_io(fd); get_requests(fd); }
static void valtopix(void) /* convert values to a pixel file */ { int dogamma; register COLOR *scanln; int y; register int x; scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); if (scanln == NULL) { fprintf(stderr, "%s: out of memory\n", progname); quit(1); } dogamma = gamcor < .95 || gamcor > 1.05; set_io(); for (y = 0; y < numscans(&picres); y++) { for (x = 0; x < scanlen(&picres); x++) { if (!dataonly) { fscanf(fin, "%*d %*d"); if (fin2 != NULL) { fscanf(fin2, "%*d %*d"); fscanf(fin3, "%*d %*d"); } } if ((*getval)(scanln[x]) < 0) { fprintf(stderr, "%s: read error\n", progname); quit(1); } if (dogamma) setcolor(scanln[x], pow(colval(scanln[x],RED), gamcor), pow(colval(scanln[x],GRN), gamcor), pow(colval(scanln[x],BLU), gamcor)); if (doexposure) multcolor(scanln[x], exposure); } if (fwritescan(scanln, scanlen(&picres), stdout) < 0) { fprintf(stderr, "%s: write error\n", progname); quit(1); } } free((void *)scanln); }
int main(int argc, char **argv, char **envp) { int fd; char *username; /* Run the process as a daemon */ background_process(NAME, UID, GID); /* Wait for socket activity and return */ fd = serve_forever(PORT); /* Set the client socket to STDIN, STDOUT, and STDERR */ set_io(fd); /* Don't do this :> */ srandom(time(NULL)); run(); }
irom static inline void clear_sda(void) { set_io(sda_mask, 0); }
static void pixtoval(void) /* convert picture to values */ { register COLOR *scanln; int dogamma; COLOR lastc; RREAL hv[2]; int startprim, endprim; long startpos; int y; register int x; scanln = (COLOR *)malloc(scanlen(&picres)*sizeof(COLOR)); if (scanln == NULL) { fprintf(stderr, "%s: out of memory\n", progname); quit(1); } dogamma = gamcor < .95 || gamcor > 1.05; if (putprim == ALL && !interleave) { startprim = RED; endprim = BLU; startpos = ftell(fin); } else { startprim = putprim; endprim = putprim; } for (putprim = startprim; putprim <= endprim; putprim++) { if (putprim != startprim && fseek(fin, startpos, 0)) { fprintf(stderr, "%s: seek error on input file\n", progname); quit(1); } set_io(); setcolor(lastc, 0.0, 0.0, 0.0); for (y = 0; y < numscans(&picres); y++) { if (freadscan(scanln, scanlen(&picres), fin) < 0) { fprintf(stderr, "%s: read error\n", progname); quit(1); } for (x = 0; x < scanlen(&picres); x++) { if (uniq) { if ( colval(scanln[x],RED) == colval(lastc,RED) && colval(scanln[x],GRN) == colval(lastc,GRN) && colval(scanln[x],BLU) == colval(lastc,BLU) ) continue; else copycolor(lastc, scanln[x]); } if (doexposure) multcolor(scanln[x], exposure); if (dogamma) setcolor(scanln[x], pow(colval(scanln[x],RED), 1.0/gamcor), pow(colval(scanln[x],GRN), 1.0/gamcor), pow(colval(scanln[x],BLU), 1.0/gamcor)); if (!dataonly) { pix2loc(hv, &picres, x, y); printf("%7d %7d ", (int)(hv[0]*picres.xr), (int)(hv[1]*picres.yr)); } if ((*putval)(scanln[x]) < 0) { fprintf(stderr, "%s: write error\n", progname); quit(1); } } } } free((void *)scanln); }
irom static inline void set_sda(void) { set_io(0, sda_mask); }
void Workspace::execute(Parser &parser) { if(parser.command.compare("demo") == 0) { ConsolePrinter::instance().feedback_rewrite( "Starting Demo... "); // run_tests(); return; } // classic network else if(parser.command.compare("cn") == 0) { NNInfo_uptr ret = classic_network(parser, networks); if(ret->result == NNOK) { ConsolePrinter::instance().network_write_nets(networks); } else { ConsolePrinter::instance().feedback_rewrite(ret->message); } return; } else if(parser.command.compare("use") == 0) { NNInfo_uptr ret = use_network(parser, networks, current_network); if(ret->result == NNOK) { ConsolePrinter::instance().network_write_active(current_network); } else { ConsolePrinter::instance().feedback_rewrite(ret->message); } return; } else if(parser.command.compare("set_io") == 0) { NNInfo_uptr ret = set_io(parser, networks, current_network); if(ret->result == NNOK) { ConsolePrinter::instance().feedback_rewrite("Input and Output loaded"); } else { ConsolePrinter::instance().feedback_rewrite(ret->message); } return; } else if(parser.command.compare("train") == 0) { NNInfo_uptr ret = train_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } return; } else if(parser.command.compare("eval") == 0) { NNInfo_uptr ret = eval_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } else { std::unique_ptr<double[]> out = current_network->get_output(); size_t out_len = current_network->output_layer_size_; // TODO: // Do not output from here. for(size_t ii = 0; ii < out_len; ii++) { std::string outstr = "Output "; double val = out[ii]*current_network->output_scale; outstr.append(std::to_string(ii)) .append(": Value: ") .append(std::to_string(val)); ConsolePrinter::instance().feedback_write(outstr); } } return; } else if(parser.command.compare("exit") == 0) { abort(); } else if(parser.command.compare("scale") == 0) { NNInfo_uptr ret = scale_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } else { ConsolePrinter::instance().feedback_rewrite("Scales set"); } return; } else if(parser.command.compare("plotSquare") == 0) { // NNInfo_uptr ret = plot_square(parser, current_network); // if(ret->result != NNOK) // { // ConsolePrinter::instance().feedback_rewrite(ret->message); // } // else // { // ConsolePrinter::instance().feedback_rewrite("Plot complete"); // } return; } else if(parser.command.compare("reset") == 0) { NNInfo_uptr ret = reset_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } else { ConsolePrinter::instance().feedback_rewrite("Weights are reset"); } return; } else if(parser.command.compare("retrain") == 0) { NNInfo_uptr ret = retrain_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } return; } else if(parser.command.compare("validate") == 0) { NNInfo_uptr ret = validate_network(parser, current_network); if(ret->result != NNOK) { ConsolePrinter::instance().feedback_rewrite(ret->message); } else { ConsolePrinter::instance().feedback_rewrite("Output file written"); } return; } else { std::string result = "Unrecognized command: "; result.append(parser.command).append(". Try demo"); ConsolePrinter::instance().feedback_rewrite(result); } }
static void fork_dvips(char **argv, struct save_or_print_info *info, childProcT proc) { int print_io[2]; int i; struct file_info *finfo = info->finfo; /* printlog_append(argv[0], strlen(argv[0])); */ FILE *fout = NULL; if (info->act == FILE_SAVE || info->print_target == TO_FILE) { /* printing to PS file, open file for writing */ const char *out_file; if (info->print_target == TO_FILE || info->fmt == FMT_PS) out_file = finfo->out_file; else out_file = finfo->tmp_ps_file; if ((fout = XFOPEN(out_file, "w")) == NULL) { popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Could not open %s for writing: %s.", out_file, strerror(errno)); return; } } printlog_popup(info); printlog_append_str(info, "Calling: `"); printlog_append_str(info, argv[0]); for (i = 1; argv[i] != NULL; i++) { printlog_append_str(info, " "); printlog_append_str(info, argv[i]); } printlog_append_str(info, "'\n"); if (xpipe(print_io) != 0) { perror("[xdvi] pipe"); return; } /* Fork process */ /* flush output buffers to avoid double buffering (i.e. data waiting in the output buffer being written twice, by the parent and the child) */ fflush(stderr); fflush(stdout); print_child.name = xstrdup(argv[0]); print_child.proc = proc; print_child.data = info; print_child.pid = fork(); if (print_child.pid == 0) { /* if child */ /* change into dir of DVI file so that included image files etc. are found */ (void)chdir(globals.dvi_file.dirname); /* make the input file pointer the STDIN of the dvips process */ if (info->page_selection == PAGE_MARKED) { /* printing selected pages from temporary file */ ASSERT(finfo->tmp_dvi_fp != NULL, "tmp fp mustn't be NULL!"); (void)dup2(fileno(finfo->tmp_dvi_fp), STDIN_FILENO); } else { /* printing from main or backup file */ (void)dup2(fileno(finfo->in_fp), STDIN_FILENO); } (void)lseek(0, 0, SEEK_SET); if (fout != NULL) { /* printing to file, make stdout of child go to fout */ (void)dup2(fileno(fout), STDOUT_FILENO); (void)close(fileno(fout)); } else { /* printing to printer, make stdout of child go to print_io[1] */ (void)dup2(print_io[1], STDOUT_FILENO); } /* make stderr of child go to print_io[1] */ (void)dup2(print_io[1], STDERR_FILENO); (void)close(print_io[1]); (void)close(print_io[0]); if (setsid() == -1) { /* so we can kill the process group */ perror("setsid"); fflush(stderr); _exit(1); } (void)execvp(*argv, argv); popup_message(globals.widgets.top_level, MSG_ERR, NULL, "Execution of \"%s\" failed: %s.\n", *argv, strerror(errno)); fflush(stderr); _exit(1); } if (fout != NULL) fclose(fout); if (print_child.pid == -1) { /* error */ perror("[xdvi] vfork"); return; } set_chld(&print_child); dvips_sig = SIGINT; (void)close(print_io[1]); /* Set up file descriptor for non-blocking I/O */ prep_fd(print_io[0], True); print_xio.fd = print_io[0]; print_xio.data = info; set_io(&print_xio); dvips_status = DVIPS_STAT_RUN; /* running */ }
/* Does all known instruction optimizations */ void cuc_optimize (cuc_func * func) { int modified = 0; int first = 1; log ("Optimizing.\n"); do { modified = 0; clean_deps (func); if (cuc_debug >= 6) print_cuc_bb (func, "AFTER_CLEAN_DEPS"); if (optimize_cmovs (func)) { if (cuc_debug >= 6) print_cuc_bb (func, "AFTER_OPT_CMOVS"); modified = 1; } if (cuc_debug) cuc_check (func); if (optimize_tree (func)) { if (cuc_debug >= 6) print_cuc_bb (func, "AFTER_OPT_TREE1"); modified = 1; } if (remove_nops (func)) { if (cuc_debug >= 6) print_cuc_bb (func, "NO_NOPS"); modified = 1; } if (cuc_debug) cuc_check (func); if (remove_dead (func)) { if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD"); modified = 1; } if (cuc_debug) cuc_check (func); if (cse (func)) { log ("Common subexpression elimination.\n"); if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_CSE"); modified = 1; } if (first) { insert_conditional_facts (func); if (cuc_debug >= 3) print_cuc_bb (func, "AFTER_COND_FACT"); if (cuc_debug) cuc_check (func); first = 0; } if (optimize_bb (func)) { if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_OPT_BB"); modified = 1; } if (cuc_debug) cuc_check (func); if (remove_nops (func)) { if (cuc_debug >= 6) print_cuc_bb (func, "NO_NOPS"); modified = 1; } if (remove_dead_bb (func)) { if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_DEAD_BB"); modified = 1; } if (remove_trivial_regs (func)) { if (cuc_debug >= 2) print_cuc_bb (func, "AFTER_TRIVIAL"); modified = 1; } if (remove_nops (func)) { if (cuc_debug >= 6) print_cuc_bb (func, "NO_NOPS"); modified = 1; } add_memory_dep (func, func->memory_order); if (cuc_debug >= 7) print_cuc_bb (func, "AFTER_MEMORY_DEP"); add_data_dep (func); if (cuc_debug >= 8) print_cuc_bb (func, "AFTER_DATA_DEP"); if (schedule_memory (func, func->memory_order)) { if (cuc_debug >= 7) print_cuc_bb (func, "AFTER_SCHEDULE_MEM"); modified = 1; } } while (modified); set_io (func); #if 0 detect_max_values (func); if (cuc_debug >= 5) print_cuc_bb (func, "AFTER_MAX_VALUES"); #endif }
Boolean initNeWS(void) { static NeWStoken newstoken; /* now try to open the connection to the NeWS server */ if (ps_open_PostScript() == (PSFILE *) NULL) return False; psio_sigpipe_handler_struct.sa_handler = psio_sigpipe_handler; sigemptyset(&psio_sigpipe_handler_struct.sa_mask); #if !FLAKY_SIGPOLL if (fcntl(PostScript->file, F_SETOWN, getpid()) == -1) perror("xdvi: fcntl F_SETOWN"); if (fcntl(PostScript->file, F_SETFL, fcntl(PostScript->file, F_GETFL, 0) | FASYNC) == -1) perror("xdvi: fcntl F_SETFL"); #endif /* not FLAKY_SIGPOLL */ if (PostScriptInput->file != PostScript->file) { #if !FLAKY_SIGPOLL if (fcntl(PostScriptInput->file, F_SETOWN, getpid()) == -1) perror("xdvi: fcntl F_SETOWN"); if (fcntl(PostScriptInput->file, F_SETFL, fcntl(PostScriptInput->file, F_GETFL, 0) | FASYNC) == -1) perror("xdvi: fcntl F_SETFL"); #endif /* not FLAKY_SIGPOLL */ NeWS_xout.xio_events &= ~XIO_IN; NeWS_xin.fd = PostScriptInput->file; set_io(&NeWS_xin); } NeWS_xout.fd = PostScript->file; set_io(&NeWS_xout); NeWS_active = False; NeWS_in_header = True; NeWS_ev_mask = NEWS_MASK_INIT; NeWS_pending = 1; ps_flush_PostScript(); NeWS_send(str0, (sizeof str0) - 1); /* get xid of window, then make this window the NeWS canvas */ (void)ps_token_from_xid(mane.win, &newstoken); if (newstoken != -1) { ps_setcanvas(newstoken); ps_flush_PostScript(); NeWS_send(preamble, (sizeof preamble) - 1); NeWS_send(psheader, psheaderlen); NeWS_send(preamble2, (sizeof preamble2) - 1); NeWS_in_header = False; post_send(); waitack(); } if (NeWS_destroyed) return False; /* success */ NeWS_mag = NeWS_shrink = -1; NeWS_page_w = globals.page.w; NeWS_page_h = globals.page.h; psp = news_procs; if (!resource.postscript) toggleNeWS(0); /* if we got a 'v' already */ return True; }
irom static inline void clear_scl(void) { set_io(scl_mask, 0); }
irom static inline void set_scl(void) { set_io(0, scl_mask); }