static void putdata (PIC_PARM *pp) { //write data from the put queue to the output file long avail, ix; QUEUE *q; q = &pp->Put; if ((avail = bytes_in_queue(q)) <= 0) { return; //presumably due to yield } //something there -- it may wrap if (avail + q->Front <= q->End) { //all in one chunk writedata (q->Front, avail, pp); q->Front += avail; if (q->Front >= q->End) { q->Front = q->Start; } } else { writedata (q->Front, ix = (q->End - q->Front), pp); writedata (q->Start, ix = (avail - ix), pp); q->Front = q->Start + ix; } return; }
void setRotation(uint8_t m) { writecommand(ILI9340_MADCTL); rotation = m % 4; // can't be higher than 3 switch (rotation) { case 0: writedata(ILI9340_MADCTL_MX | ILI9340_MADCTL_BGR); _width = ILI9340_TFTWIDTH; _height = ILI9340_TFTHEIGHT; break; case 1: writedata(ILI9340_MADCTL_MV | ILI9340_MADCTL_BGR); _width = ILI9340_TFTHEIGHT; _height = ILI9340_TFTWIDTH; break; case 2: writedata(ILI9340_MADCTL_MY | ILI9340_MADCTL_BGR); _width = ILI9340_TFTWIDTH; _height = ILI9340_TFTHEIGHT; break; case 3: writedata(ILI9340_MADCTL_MV | ILI9340_MADCTL_MY | ILI9340_MADCTL_MX | ILI9340_MADCTL_BGR); _width = ILI9340_TFTHEIGHT; _height = ILI9340_TFTWIDTH; break; } }
void hangup(int sig) { char line[LINELTH]; /* I think I can just remove these calls to sigblock(), since the signal will * be ignored, delivered or not. sigblock(sigmask(SIGTSTP)); sigblock(sigmask(SIGTERM)); sigblock(sigmask(SIGHUP)); sigblock(sigmask(SIGINT));*/ signal(SIGTSTP, SIG_IGN); signal(SIGHUP, SIG_IGN); signal(SIGTERM, SIG_IGN); signal(SIGINT, SIG_IGN); sync(); if (country == 0) { writedata(); sync(); } else { /* fprintf(fexe, "L_NGOLD\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNAGOLD, country, curntn->tgold, "null"); fprintf(fexe, "L_NMETAL\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNAMETAL, country, curntn->metals, "null"); fprintf(fexe, "L_NJWLS\t%d \t%d \t%ld \t0 \t0 \t%s\n", XNARGOLD, country, curntn->jewels, "null"); */ writedata(); if (fexe) fclose(fexe); sprintf(line, "exec.%s", ntn[country].name); unlink(line); sync(); } /* close file */ /* if(fexe) {*/ /*fchmod(fileno(fexe),FCMASK);*/ /*fclose(fexe);}*/ /* remove any existing mail reading/writing file */ if (mailok != DONEMAIL) { extern char tmp_mail_name[]; unlink(tmp_mail_name); } /* remove the lock file */ unlink(fison); sprintf(line, "/tmp/%s.%03d-tmp", msgfile, country); chmod(line, (mode_t) FCMASK); unlink(line); /* send a message to God */ #ifndef SHUT_UP_DORKS if (mailopen(0) != (-1)) { fprintf(fm, "WARNING: Nation %s hungup on me.\n", curntn->name); mailclose(0); } #endif /* exit program */ sync(); exit(FAIL); }
void HT1632::writeRAM(uint8_t addr, uint8_t data) { //printf("Writing 0x%X to 0x%X\n", data&0xF, addr&0x7F); gpiobank->write(_cs, 0); writedata(HT1632_WRITE, HT1632_HEAD_LENGTH); writedata(addr, HT1632_ADDRESS_LENGTH); writedata(data, HT1632_WRITE_LENGTH); gpiobank->write(_cs, 1); }
void HT1632::writeRAMburst(uint8_t addr, uint8_t *data, uint8_t length) { uint8_t i; gpiobank->write(_cs, 0); writedata(HT1632_WRITE, HT1632_HEAD_LENGTH); writedata(addr, HT1632_ADDRESS_LENGTH); for (i = 0; i < length; i++) { //printf("Writing 0x%X to 0x%X\n", data[i], (addr+i)&0x7F); writedata(data[i], 2*HT1632_WRITE_LENGTH); } gpiobank->write(_cs, 1); }
void putchar(char character) { int tablept, count, char_column; if ((character<0x20)||(character>0x7f)) {return;} // Exit function if character is not found. tablept = ((5*character) - 160); // Point to the columns of the character in the table. for (count=5;count>0;count--) // Draw the columns to print the character. { char_column = table[tablept]; writedata(char_column); tablept++; } writedata(0x00); // 1 pixel spacing per character. }
void TFT_ILI9163C::setRotation(uint8_t m) { rotation = m % 4; // can't be higher than 3 switch (rotation) { case 0: _Mactrl_Data = 0b00001000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; case 1: _Mactrl_Data = 0b01101000; _width = _TFTHEIGHT;//-__OFFSET; _height = _TFTWIDTH; break; case 2: _Mactrl_Data = 0b11001000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; case 3: _Mactrl_Data = 0b10101000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; } colorSpace(_colorspaceData); #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_MADCTL); writedata8_last(_Mactrl_Data); endProc(); #else writecommand(CMD_MADCTL); writedata(_Mactrl_Data); #endif }
/* main output routine... */ int dooutput(lpTrajectory trajectory, int error) { if (error) posterr_error(error, (error > 0) ? errors_traj[error] : NULL); else { html_cgitext(); setup_openhead(); setup_body(); setup_info(TRAJ_VERSION); setup_header(2); html_horzrule(NULL, 0, 0, 0, 0); writedata(trajectory); html_horzrule(NULL, 0, 0, 0, 0); writetable(trajectory); html_closebody(); html_closehead(); } return 0; }
/* stringout - Print the contents of the character string "str" at the current cursor position. */ void stringout(char *str) { int i; for(i = 0; *(str+i)!='\0'; i++){ writedata(*(str+i)); } }
void Zpu_ILI9340::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { writecommand(ILI9340_CASET); // Column addr set writedata(x0 >> 8); writedata(x0 & 0xFF); // XSTART writedata(x1 >> 8); writedata(x1 & 0xFF); // XEND writecommand(ILI9340_PASET); // Row addr set writedata(y0>>8); writedata(y0); // YSTART writedata(y1>>8); writedata(y1); // YEND writecommand(ILI9340_RAMWR); // write to RAM }
int main() { const char* File_boy = "boys_rankings.txt"; const char* File_girl = "girls_rankings.txt"; const char* File_write = "result.txt"; //初始化 int boyarray[NUM][NUM] = {0}; int girlarray[NUM][NUM] = {0}; int boyperfer[NUM] = {0}; //记录每位男生选中的女生编号 int boystartid[NUM] = {0}; //记录每位男生选择的心目中的第几个女生,以便下次开始 int girlnow[NUM] = {0}; for (int i=0;i<NUM;i++) girlnow[i] = NIL; stack<int> boystack;//单身男生 //读入数据 read_from_file(File_boy,boyarray); read_from_file(File_girl,girlarray); for(int id = 0; id <NUM; id++) //所有男生向心目中最喜欢的女孩表白,第一轮 { findgirl(boystack,id,boyarray,girlarray,boyperfer,boystartid,girlnow); } while(boystack.size()!=0) //单身的再次向排序中的下一个女孩表白 { int id = boystack.top(); boystack.pop(); findgirl(boystack,id,boyarray,girlarray,boyperfer,boystartid,girlnow); } for(int i=0;i<NUM;i++) { cout<<"B"<<i<<"<----->G"<<boyperfer[i]<<endl; } writedata(File_write,boyperfer); return 0; }
/* stringout - Print the contents of the character string "str" at the current cursor position. */ void stringout(char *str) { while(*str != '\0') { writedata(*str); str++; } }
//LCD在任意位置写字符串 //列x=0~15,行y=0,1 void LCD_write_string(unsigned char x,unsigned char y,char *s) { writecom("\x80\xc0"[y] +x); while (*s) // 显示字符 { writedata( *s++ ); } }
void Adafruit_HX8357::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) { writecommand(HX8357_CASET); // Column addr set writedata(x0 >> 8); writedata(x0 & 0xFF); // XSTART writedata(x1 >> 8); writedata(x1 & 0xFF); // XEND writecommand(HX8357_PASET); // Row addr set writedata(y0>>8); writedata(y0); // YSTART writedata(y1>>8); writedata(y1); // YEND writecommand(HX8357_RAMWR); // write to RAM }
void bootwrite() { /* does bootstrapping and writes out data sets */ long i, j, rr, repdiv10; if (!(bootstrap || jackknife || permute || ild || lockhart)) reps = 1; repdiv10 = reps / 10; if (repdiv10 < 1) repdiv10 = 1; if (progress) putchar('\n'); for (rr = 1; rr <= (reps); rr++) { for (i = 0; i < spp; i++) for (j = 0; j < maxnewsites; j++) charorder[i][j] = j; if(rr==1) firstrep = true; else firstrep = false; if (ild) { charpermute(0, maxnewsites); for (i = 1; i < spp; i++) for (j = 0; j < maxnewsites; j++) charorder[i][j] = charorder[0][j]; } if (lockhart) for (i = 0; i < spp; i++) charpermute(i, maxnewsites); bootweights(); if (!justwts || permute || ild || lockhart) writedata(); if (justwts && !(permute || ild || lockhart)) writeweights(); if (categories) writecategories(); if (factors) writefactors(); if (mixture) writeauxdata(mixdata, outmixfile); if (ancvar) writeauxdata(ancdata, outancfile); if (progress && (bootstrap || jackknife || permute || ild || lockhart) && ((reps < 10) || rr % repdiv10 == 0)) { printf("completed replicate number %4ld\n", rr); #ifdef WIN32 phyFillScreenColor(); #endif } } if (progress) { if (justwts) printf("\nOutput weights written to file \"%s\"\n\n", outweightfilename); else printf("\nOutput written to file \"%s\"\n\n", outfilename); } } /* bootwrite */
void writestr(unsigned char *s) // send string message to LCD { unsigned char l,i; l = strlen(s); // get length of string for(i=0;i<l;i++) { writedata(*s); // till the length of string s++; // send characters one by one } }
bool LadderList::saveBinary() { if (saved) return true; std::string filename = prefs_get_ladderdir(); filename += "/"; filename += ladderFilename; std::ofstream fp (filename.c_str(), std::ios::out | std::ios::binary); if (!(fp)) { eventlog(eventlog_level_error,__FUNCTION__,"could not open file \"%s\" for writing (std::ofstream: %s)", filename.c_str(), std::strerror(errno)); return false; } writedata(fp,magick); //write the magick int as header unsigned int checksum = 0; unsigned int results[4]; for(LList::const_iterator lit(ladder.begin()); lit!=ladder.end(); lit++) { results[0] = lit->getUid(); results[1] = lit->getSecondary(); results[2] = lit->getPrimary(); results[3] = 0; writedata(fp,results,4); //calculate a checksum over saved data for (int count=0;count<4;count++) checksum+=results[count]; } writedata(fp,checksum); // add checksum at the en saved = true; eventlog(eventlog_level_info,__FUNCTION__,"successfully saved %s",filename.c_str()); return true; }
void printdata (struct lib_ccx_ctx *ctx, const unsigned char *data1, int length1, const unsigned char *data2, int length2, struct cc_subtitle *sub) { if (ccx_options.write_format==CCX_OF_DVDRAW) writeDVDraw (data1,length1,data2,length2,&ctx->wbout1); else /* Broadcast raw or any non-raw */ { if (length1 && ccx_options.extract != 2) { writedata(data1, length1, &ctx->context_cc608_field_1, sub); } if (length2) { if (ccx_options.extract != 1) writedata(data2, length2, &ctx->context_cc608_field_2, sub); else // User doesn't want field 2 data, but we want XDS. writedata (data2,length2,NULL, sub); } } }
///////////////アクチュエータモデル///////////////// int Model :: Set_actuator_model() { //////アクチュエータの寸法/////// double elast_R=0.012; //半径 double elast_H=0.03; double MRE_R=0.015; double MRE_H=0.04; //////////////////////////////// ////初期化されたmpsconfigクラスのデータ mpsconfig CON; //////////////////////////////////// //////粒子の直径//// double le=CON.get_distancebp(); //////////////////// //////粒子数格納////// int total_number; //この関数での全粒子数 int start_ID=0; //初期粒子数 ///////////////////// //////円筒形作成///// total_number=Model :: Set_cylinder(start_ID, le, MRE_R, MRE_H); //////////////////// for(int i=start_ID;i<total_number;i++) { if(pow(PART[i].Get_X(),2)+pow(PART[i].Get_Y(),2)<=pow(0.01,2) && PART[i].Get_Z()>0.01 && PART[i].Get_Z()<0.02+0.01){ writedata(fq,i,PART[i].Get_X(),PART[i].Get_Y(),PART[i].Get_Z()-(MRE_H/2),WALL,1,0,0,0,0,0,0,0,0);//粒子はWALL } else if(pow(PART[i].Get_X(),2)+pow(PART[i].Get_Y(),2)<=pow(elast_R,2) && PART[i].Get_Z()>0.005 && PART[i].Get_Z()<elast_H+0.0045){ writedata(fq,i,PART[i].Get_X(),PART[i].Get_Y(),PART[i].Get_Z()-(MRE_H/2),ELASTIC,1,0,0,0,0,0,0,0,0);//粒子はELASTIC } else writedata(fq,i,PART[i].Get_X(),PART[i].Get_Y(),PART[i].Get_Z()-(MRE_H/2),MAGELAST,1,0,0,0,0,0,0,0,1);//粒子はMAGELAST } return total_number; }
bool Gyro::configAutomatic(){ uint8_t ret = 0; std::vector<uint8_t> writedata(2); std::vector<uint8_t> readdata(1); writedata[0] = static_cast<uint8_t>(GyroCommands::CTRL2_G); writedata[1] = 0x8C; ret = rwMultiByte(readdata, writedata, 0, 2); writedata[0] = static_cast<uint8_t>(GyroCommands::CTRL1_XL); writedata[1] = 0x70; ret = rwMultiByte(readdata, writedata, 0, 2); return ret; }
bool Gyro::whoami(){ std::vector<uint8_t> writedata(1); std::vector<uint8_t> readdata(1); writedata[0] = static_cast<uint8_t>(GyroCommands::WHO_AM_I) | 0x80; readdata[0] = 0x00; auto retval = rwMultiByte(readdata, writedata, 1, 1); if(retval) return false; retval = configAutomatic(); if(retval) return false; if(readdata[0] == 0x69) return true; else return false; }
uint16_t Gyro::readAccelY(){ uint16_t ret = 0x0000; std::vector<uint8_t> writedata(1); std::vector<uint8_t> readdata(1); writedata[0] = static_cast<uint8_t>(GyroCommands::OUTY_H_XL) | 0x80; rwMultiByte(readdata, writedata, 1, 1); ret += (static_cast<uint16_t>(readdata[0]) << 8); writedata[0] = static_cast<uint8_t>(GyroCommands::OUTY_L_XL) | 0x80; rwMultiByte(readdata, writedata, 1, 1); ret += readdata[0]; return ret; }
void main(int argc, char **argv) { ulong i; int m, n; char *file; uchar hdr[MAXHDR]; ARGBEGIN { case 'n': nsects = argval(ARGF()); break; case 'z': sectsize = argval(ARGF()); break; default: usage(); } ARGEND if(argc != 1) usage(); file = argv[0]; sectbuff = emalloc9p(sectsize); initdata(file, 1); memmove(hdr, magic, MAGSIZE); m = putc3(&hdr[MAGSIZE], 0); n = putc3(&hdr[MAGSIZE + m], 0); clearsect(0); writedata(0, 0, hdr, MAGSIZE + m + n, 0); for(i = 1; i < nsects - 1; i++) clearsect(i); m = putc3(&hdr[MAGSIZE], 1); n = putc3(&hdr[MAGSIZE + m], 0); clearsect(nsects - 1); writedata(0, nsects - 1, hdr, MAGSIZE + m + n, 0); }
void lcdchar (uchar ch) { uchar xdata i; for (i=0;lcdbase[i][0]!=ch;i++) { if (i>102) //从0到102, { i=0x1c; break; //若未找到,则显示? } } writedata(lcdbase[i][1]); }
// Set the region of the screen RAM to be modified // Pixel colors are sent left to right, top to bottom // (same as Font table is encoded; different from regular bitmap) // Requires 11 bytes of transmission void static setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) { writecommand(ST7735_CASET); // Column addr set writedata(0x00); writedata(x0+ColStart); // XSTART writedata(0x00); writedata(x1+ColStart); // XEND writecommand(ST7735_RASET); // Row addr set writedata(0x00); writedata(y0+RowStart); // YSTART writedata(0x00); writedata(y1+RowStart); // YEND writecommand(ST7735_RAMWR); // write to RAM }
void GL_ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) { writecommand(ST7735_CASET); // column addr set writedata(0x00); writedata(x0+0); // XSTART writedata(0x00); writedata(x1+0); // XEND writecommand(ST7735_RASET); // row addr set writedata(0x00); writedata(y0+0); // YSTART writedata(0x00); writedata(y1+0); // YEND writecommand(ST7735_RAMWR); // write to RAM }
//ÏÔʾ×Ö·û void LCD_write_int(unsigned char x,unsigned char y,unsigned char data) { unsigned char address; //дµØÖ· if (y == 0) { address = 0x80 + x; } else { address = 0xc0 + x; } writecom( address); _delay_cycles(1); writedata(data); }
int Model :: Set_benchmark_model() { double bord_r=0.015; double bord_h=0.005; double elast_r=0.012; double elast_h=0.010; int total_number; int start_ID=0; mpsconfig CON; //初期化されたmpsconfigクラスのデータ double le=CON.get_distancebp(); total_number=Model :: Set_cylinder(start_ID, le, bord_r, bord_h); for(int i=start_ID;i<total_number;i++) writedata(fq,i,PART[i].Get_X(),PART[i].Get_Y(),PART[i].Get_Z()-(elast_h/2+bord_h),WALL,1,0,0,0,0,0,0,0,0);//粒子はWALL start_ID=total_number; total_number+=Model :: Set_cylinder(start_ID, le, elast_r, elast_h); for(int j=start_ID;j<total_number;j++) writedata(fq,j,PART[j].Get_X(),PART[j].Get_Y(),PART[j].Get_Z()-(elast_h/2),ELASTIC,1,0,0,0,0,0,0,0,0);//粒子はELASTIC /* start_ID=total_number; total_number+=Model :: Set_cylinder(start_ID, le, bord_r, bord_h); for(int k=start_ID;k<total_number;k++) writedata(fq,k,PART[k].Get_X(),PART[k].Get_Y(),PART[k].Get_Z()+(elast_h/2),WALL,1,0,0,0,0,0,0,0,0);//粒子はWALL */ return total_number; }
void Adafruit_ST7735::setAddrWindow(uint8_t x0, uint8_t y0, uint8_t x1, uint8_t y1) { writecommand(ST7735_CASET); // Column addr set writedata(0x00); writedata(x0+colstart); // XSTART writedata(0x00); writedata(x1+colstart); // XEND writecommand(ST7735_RASET); // Row addr set writedata(0x00); writedata(y0+rowstart); // YSTART writedata(0x00); writedata(y1+rowstart); // YEND writecommand(ST7735_RAMWR); // write to RAM }
static int writedump(FILE *f) { int rc; rc = writedata(f); if (rc != 0) return rc; rc = writeheader(f); if (rc != 0) return rc; return 0; }