⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processor.c

📁 嵌入式linux下液晶编程院代码, 可以在LINUX2.4内核下运行
💻 C
📖 第 1 页 / 共 2 页
字号:
  case T_LOAD_2:  case T_LOAD_3:  case T_SENSOR:    val=query(token);    if (val<10.0)      *p+=sprintf (*p, "%5.2f", val);    else if (val<100.0)      *p+=sprintf (*p, "%5.1f", val);    else      *p+=sprintf (*p, "%5.0f", val);    break;  case T_CPU_USER:  case T_CPU_NICE:  case T_CPU_SYSTEM:  case T_CPU_BUSY:  case T_CPU_IDLE:    *p+=sprintf (*p, "%3.0f", 100.0*query(token));    break;  case T_ETH_RX:  case T_ETH_TX:  case T_ETH_MAX:  case T_ETH_TOTAL:    val=query(token);    if (net.bytes)      val/=1024.0;    *p+=sprintf (*p, "%5.0f", val);    break;  case T_ISDN_IN:  case T_ISDN_OUT:  case T_ISDN_MAX:  case T_ISDN_TOTAL:    if (isdn.usage)      *p+=sprintf (*p, "%5.0f", query(token));    else      *p+=sprintf (*p, " ----");    break;  case T_ISDN_USED:    if (isdn.usage)      *p+=sprintf (*p, "*");    else      *p+=sprintf (*p, " ");    break;  case T_SETI_PRC:    val=100.0*query(token);    if (val<100.0)       *p+=sprintf (*p, "%4.1f", val);    else      *p+=sprintf (*p, " 100");    break;  case T_SETI_CPU:    val=query(token);    *p+=sprintf (*p, "%2d.%2.2d:%2.2d", (int)val/86400, 		 (int)((int)val%86400)/3600,		 (int)(((int)val%86400)%3600)/60 );    break;      case T_BATT_PERC:    *p+=sprintf(*p, "%3.0f", query(token));    break;  case T_BATT_STAT:      { int ival = (int) query(token);    switch (ival) {    case 0: **p = '='; break;    case 1: **p = '+'; break;    case 2: **p = '-'; break;    default: **p = '?'; break;    }    }    (*p)++;    break;  case T_BATT_DUR:    {      char eh = 's';      val = query(token);      if (val > 99) {	val /= 60;	eh = 'm';      }      if (val > 99) {	val /= 60;	eh = 'h';      }      if (val > 99) {	val /= 24;	eh = 'd';      }      *p+=sprintf(*p, "%2.0f%c", val, eh);    }    break;  case T_DVB_STRENGTH:  case T_DVB_SNR:    *p+=sprintf (*p, "%5.1f", 100.0*query(token));    break;  case T_EXEC:    i = (token>>8)-'0';    *p+=sprintf (*p, "%.*s",cols-(*p-start), exec[i].s);    break;      default:    *p+=sprintf (*p, "%5.0f", query(token));  }}static void collect_data (void) {  int i;  if (token_usage[C_MEM]) {    Ram (&ram.total, &ram.free, &ram.shared, &ram.buffer, &ram.cache);     ram.used=ram.total-ram.free;    ram.avail=ram.free+ram.buffer+ram.cache;  }    if (token_usage[C_LOAD]) {    Load (&load.load1, &load.load2, &load.load3);  }    if (token_usage[C_CPU]) {    Busy (&busy.user, &busy.nice, &busy.system, &busy.idle);  }    if (token_usage[C_DISK]) {    Disk (&disk.read, &disk.write);    disk.total=disk.read+disk.write;    disk.max=disk.read>disk.write?disk.read:disk.write;    if (disk.max>disk.peak) disk.peak=disk.max;  }    if (token_usage[C_ETH]) {    Net (&net.rx, &net.tx, &net.bytes);    net.total=net.rx+net.tx;    net.max=net.rx>net.tx?net.rx:net.tx;    if (net.max>net.peak) net.peak=net.max;  }  if (token_usage[C_ISDN]) {    Isdn (&isdn.in, &isdn.out, &isdn.usage);    isdn.total=isdn.in+isdn.out;    isdn.max=isdn.in>isdn.out?isdn.in:isdn.out;    if (isdn.max>isdn.peak) isdn.peak=isdn.max;  }  if (token_usage[C_PPP]) {    PPP (0, &ppp.rx, &ppp.tx);    ppp.total=ppp.rx+ppp.tx;    ppp.max=ppp.rx>ppp.tx?ppp.rx:ppp.tx;    if (ppp.max>ppp.peak) ppp.peak=ppp.max;  }  if (token_usage[C_SETI]) {    Seti (&seti.perc, &seti.cput);  }  if (token_usage[C_BATT]) {    Battery (&batt.perc, &batt.stat, &batt.dur);  }    if (token_usage[C_DVB]) {    DVB (&dvb.strength, &dvb.snr);  }    for (i=0; i<=MAILBOXES; i++) {    if (token_usage[T_MAIL]&(1<<i) || token_usage[T_MAIL_UNSEEN]&(1<<i) ) {      Mail (i, &mail[i].num, &mail[i].unseen);    }  }    for (i=0; i<=SENSORS; i++) {    if (token_usage[T_SENSOR]&(1<<i)) {      Sensor (i, &sensor[i].val, &sensor[i].min, &sensor[i].max);    }  }  for (i=0; i<=EXECS; i++) {    if (token_usage[T_EXEC]&(1<<i)) {      Exec (i, exec[i].s, &exec[i].val);    }  }}static char *process_row (char *data, int row, int len){  static char buffer[256];  char *p=buffer;  char *s=data;  int token;  int n;    do {    if (*s=='%') {      token = *(unsigned char*)++s;      if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8;      print_token (token, &p, buffer);	    } else if (*s=='$') {      double val1, val2;      int i, type, len;      type=*++s;      len=*++s;      token = *(unsigned char*)++s;      if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8;      val1=query_bar(token);      val2=val1;      if (type & (BAR_H2 | BAR_V2)) {	token = *(unsigned char*)++s;	if (token>T_EXTENDED) token += (*(unsigned char*)++s)<<8;	val2=query_bar(token);      }      else if (type & BAR_T)	val2 = *(unsigned char*)++s; /* width */      if (type & BAR_H)	lcd_bar (type, row, p-buffer+1, len*xres, val1*len*xres, val2*len*xres);      else if (type & BAR_T)	lcd_bar (type, row, p-buffer+1, len*yres, val1*len*yres, val2*xres);      else	lcd_bar (type, row, p-buffer+1, len*yres, val1*len*yres, val2*len*yres);            if (type & BAR_H) {	for (i=0; i<len && p-buffer<cols; i++)	  *p++='\t';      } else {	*p++='\t';      }          } else if (*s=='&') {      if (lcd_icon(*(++s)-'0', 0, row, p-buffer+1)<0)	*p++='*'; // error      else	*p++='\t'; // all ok          } else {      *p++=*s;    }      } while (*s++);       // pad with blanks  for (n=strlen(buffer); n<cols; n++) {    buffer[n]=' ';  }  buffer[n]='\0';    return buffer;}static int process_gpo (int n){  int token;  double val;  token=gpo[n];  val=query(token);  return (val > 0.0);}static int Turn (void){  static struct timeval old = {tv_sec:0, tv_usec:0};  static struct timeval new = {tv_sec:0, tv_usec:0};  struct timeval now;  int initialized;    if (turn<=0) return 0;    gettimeofday (&now, NULL);  // first time invocation?  initialized=(new.tv_sec>0);  if (now.tv_sec==new.tv_sec ? now.tv_usec>new.tv_usec : now.tv_sec>new.tv_sec) {    old=now;    new.tv_sec =old.tv_sec;    new.tv_usec=old.tv_usec+turn*1000;    while (new.tv_usec>=1000000) {      new.tv_usec-=1000000;      new.tv_sec++;    }    return initialized;  }  return 0;}void process_init (void){  int i;  load.overload=atof(cfg_get("overload","2.0"));  lcd_query (&rows, &cols, &xres, &yres, &supported_bars, &icons, &gpos);  if (rows>ROWS) {    error ("%d rows exceeds limit, reducing to %d rows", rows, ROWS);    rows=ROWS;  }  if (icons>ICONS) {    error ("%d icons exceeds limit, reducing to %d icons", icons, ICONS);    icons=ICONS;  }  if (gpos>GPOS) {    error ("%d gpos exceeds limit, reducing to %d gpos", gpos, GPOS);    gpos=GPOS;  }  debug ("Display: %d rows, %d columns, %dx%d pixels, %d icons, %d GPOs", rows, cols, xres, yres, icons, gpos);  if (cfg_number("Rows", 1, 1, 1000, &lines)<0) {    lines=1;    error ("ignoring bad 'Rows' value and using '%d'", lines);  }  if (lines>ROWS) {    error ("%d virtual rows exceeds limit, reducing to %d rows", lines, ROWS);    lines=ROWS;  }  if (lines>rows) {    if (cfg_number("Scroll", 1, 1, 1000, &scroll)<0) {      scroll=1;      error ("ignoring bad 'Scroll' value and using '%d'", scroll);    }    if (scroll>rows) {      error ("'Scroll' entry in %s is %d, > %d display rows.", cfg_source(), scroll, rows);      error ("This may lead to unexpected results!");    }    if (cfg_number("Turn", 1000, 1, 1000000, &turn)<0) {      turn=1000;      error ("ignoring bad 'Scroll' value and using '%d'", turn);    }    debug ("Virtual: %d rows, scroll %d lines every %d msec", lines, scroll, turn);  } else {    lines=rows;    scroll=0;    turn=0;  }  if (cfg_number("Tick.Text", 500, 1, 1000000, &tick_text)<0) {    tick_text=500;    error ("ignoring bad 'Tick.Text' value and using '%d'", tick_text);  }  if (cfg_number("Tick.Bar", 100, 1, 1000000, &tick_bar)<0) {    tick_bar=100;    error ("ignoring bad 'Tick.Bar' value and using '%d'", tick_bar);  }  if (cfg_number("Tick.Icon", 100, 1, 1000000, &tick_icon)<0) {    tick_icon=100;    error ("ignoring bad 'Tick.Icon' value and using '%d'", tick_icon);  }  if (cfg_number("Tick.GPO", 100, 1, 1000000, &tick_gpo)<0) {    tick_gpo=100;    error ("ignoring bad 'Tick.GPO' value and using '%d'", tick_gpo);  }  // global Tick is minimum of tick_text, _bar, _gpo  tick=tick_text;  if (tick>tick_bar) tick=tick_bar;  if (tick>tick_gpo) tick=tick_gpo;    // global Tack is minimum of tick, tick_gpo  tack=tick;  if (tack>tick_icon) tack=tick_icon;  debug ("========================");  debug ("Timings:");  debug ("%3d msec Text updates", tick_text);  debug ("%3d msec Bar  updates", tick_bar );  debug ("%3d msec Icon updates", tick_icon);  debug ("%3d msec GPO  updates", tick_gpo );  debug ("------------------------");  debug ("%3d msec data collection", tick);  debug ("%3d msec data processing", tack);  debug ("========================");  for (i=1; i<=lines; i++) {    char buffer[8], *p;    snprintf (buffer, sizeof(buffer), "Row%d", i);    p=cfg_get(buffer,"");    debug ("%s: %s", buffer, p);    row[i]=strdup(parse_row(p, supported_bars, token_usage));  }  for (i=1; i<=gpos; i++) {    char buffer[8], *p;    snprintf (buffer, sizeof(buffer), "GPO%d", i);    p=cfg_get(buffer,"");    debug ("%s: %s", buffer, p);    gpo[i]=parse_gpo(p, token_usage);  }}void process (void){  static int loop_tick=0;  static int loop_text=0;  static int loop_bar=0;  static int loop_icon=0;  static int loop_gpo=0;  static int offset=0;  int i, j, val;  char *txt;    // collect data every tick msec  if (loop_tick==0) {    collect_data();  }    // maybe scroll  if (Turn() && loop_text==0) {    offset+=scroll;    while (offset>=lines) {      offset-=lines;    }    lcd_clear(0); // soft clear  }    if (loop_text==0 || loop_bar==0) {    for (i=1; i<=rows; i++) {      j=i+offset;      while (j>lines) {	j-=lines;      }      txt=process_row (row[j], i, cols);      if (loop_text==0)	lcd_put (i, 1, txt);    }  }    // update GPO's  if (loop_gpo==0) {    for (i=1; i<=gpos; i++) {      val=process_gpo (i);      lcd_gpo (i, val);    }  }    // rotate icon animations  if (loop_icon==0) {    static int sequence=0;    for (i=1; i<=icons; i++) {      lcd_icon (i, sequence, 0, 0);    }    sequence++;  }    // flush in every case  // note that we flush too often, but usually  // nothing has changed  lcd_flush();      // increase loop counters  if ((loop_tick+=tack) >= tick     ) loop_tick=0;  if ((loop_text+=tack) >= tick_text) loop_text=0;  if ((loop_bar +=tack) >= tick_bar ) loop_bar =0;  if ((loop_icon+=tack) >= tick_icon) loop_icon=0;  if ((loop_gpo +=tack) >= tick_gpo ) loop_gpo =0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -