static void myputchr(printer *p_, char c)
{
     P *p = (P *) p_;
     if (p->bufw >= p->buf + BUFSZ)
	  myflush(p);
     *p->bufw++ = c;
}
static void send_reset() {
	mywrite(all_reset, ALL_RESET_SZ, 0);
	usleep(60000);
	myflush();
	usleep(70000);
	return;
}
/*
 * write the code to the buffer
 */
static void raw_mywrite(unsigned char *d, int n, int p) {
	
	if ((nwr + n + 2) >= WRBFSIZE) {
		extratime = myflush();
	}
	
	while (n--) {
		wrbuff[nwr++] = *(d++);
	}
	return;
}
Beispiel #4
0
void nickname(void)
{
    printf("\n");
    printf("*  * * *    *    **** **** *   *   * * **** ****\n");
    printf("* *  * *    *    *    *  *  * * * *  * *    *\n");
    printf("**   * *    *    **** ***   * * * *  * **** ****\n");
    printf("* *  * *    *    *    * *    *   *   * *    *\n");
    printf("*  * * **** **** **** *  *   *   *   * *    ****\n");
myflush ( stdin );
  mypause();
}
static void mycleanup(printer *p_)
{
     P *p = (P *) p_;
     myflush(p);
}
static void parse_event() {
	int i = 0;
	int tick = 0;
	int ctick = 0;
	int tempo = 500000;
	unsigned long ts, tu;
	struct timeval tp;
	
	gettimeofday(&tp, NULL);
	ts = tp.tv_sec;
	tu = tp.tv_usec;
	
	while(TRUE) {
		/* pause / stop check */
		if (cmd_stop) {
			break;
		}
		
		if (cmd_pause) {
			gettimeofday(&tp, NULL);
			ts = tp.tv_sec;
			tu = tp.tv_usec;
			usleep(50*1000);
			continue;
		}
		
		while(tick == midi->event[i].ctime) {
			/* delta wait */
			if (ctick != midi->event[i].ctime) {
				int delta, stime;
				
				delta = midi->event[i].ctime - ctick;
				stime = ticks2usec(delta, midi->division, tempo) - myflush();
				if (stime > 0) {
					long j;
					struct timespec ttmp, *req;
					
					req = &ttmp;
					req->tv_sec = (time_t)stime / 1000000;
					req->tv_nsec = (long)(stime % 1000000) * 1000;
					nanosleep(req, NULL);
					
					gettimeofday(&tp, NULL);
					j = (tp.tv_sec * 1000000 + tp.tv_usec) - (ts * 1000000 + tu);
					if (j != stime) {
						extratime += (j - stime);
					}
				} else {
					gettimeofday(&tp, NULL);
					extratime +=  -stime;
				}
				ts = tp.tv_sec;
				tu = tp.tv_usec;
				ctick = midi->event[i].ctime;
			}
			if (midi->event[i].type == 0) {
				/* ordinary data */
				mywrite(midi->event[i].data, midi->event[i].n, midi->event[i].port);
				i++;
			} else if (midi->event[i].type == 2) {
				/* tempo change */
				int *p;
				p = (int*)midi->event[i].data;
				tempo = (unsigned int)*p;
				i++;
			} else if (midi->event[i].type == 3) {
				/* system35 maker */
				int vn1 = midi->event[i+1].data[2];
				int vn2 = midi->event[i+2].data[2];
				int vn3 = midi->event[i+3].data[2];
				
				switch(vn1) {
				case 0:
					/* set label */
					i += 6;
					break;
				case 1:
					/* jump */
					mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					i = midi->sys35_label[vn2];
					ctick = tick = midi->event[i].ctime;
					break;
				case 2:
					/* set flag */
					flags->midi_flag[vn2] = vn3;
					i += 6;
					break;
				case 3:
					/* flag jump */
					if (flags->midi_flag[vn2] == 1) {
						i = midi->sys35_label[vn3];
						ctick = 
						tick = midi->event[i].ctime;
						mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					} else {
						i += 6;
					}
					break;
				case 4:
					/* set variable */
					flags->midi_variable[vn2] = vn3;
					i += 6;
					break;
				case 5:
					/* variable jump */
					if (--(flags->midi_variable[vn2]) == 0) {
						i = midi->sys35_label[vn3];
						ctick =
						tick  = midi->event[i].ctime;
						mywrite(all_noteoff, ALL_NOTEOFF_SZ, 0);
					} else {
						i += 6;
					}
					break;
				}
			} else {
				WARNING("Unknown type of event %x (NEVER!).\n", midi->event[i].type);
			}
			if (i >= midi->eventsize) return;
		}
		tick++;
	}
}
Beispiel #7
0
// Process a line.
static void ui_command(char *cmd) {


  char *tok;

  MyTime tm = MyTime();
  int n = 1, incHr = 1;

  int  phaseOff, d, u, tmp;

  myflush();
  myprintln();


  switch (cmd[0]) {

    case 'M':
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) {
        n = 10;
      } else {
        n = in_range(1, 200, atoi(tok));
      }
      moon_halfTable(n);
      break;

    case 'C':
      phase_calibrate();
      break;

    case '!':
      error_mess   =  NULL;
      PHASE_BROKEN = false;
      TILT_BROKEN =false;
      BREAK = false;
      servo_retry_count = 0;
      break;

    case 'H':
      phase_halt();

      RUNNING = false;
      break;

    case 'T':   // tilt override.
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      ui_tilt = in_range(-80, 80, atoi(tok));
      if (RUNNING) myprintf(F("*!* Halt system to take effect \n"));
      break;

    case 'D':
      {
        MyTime t1;
        if (t1.parseStr(&cmd[2])) {
          t1.writeRTC();
          delay(1500);
          MyTime t2 = MyTime();
          t2.print(F("\n check me : "));
          myprintln();
        } else {
          myprintf(F(" Error in date time input \n"));
        }
      }
      break;

    case 'P':   // phase
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      ui_phase = in_range(-180, 180, atoi(tok));
      if (RUNNING) myprintf(F("*!* Halt system to take effect \n"));
      else phase_set(ui_phase);
      break;

    case 'O':   // phase offset
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      phaseOff = in_range(-360, 360, atoi(tok));
      phase_setOffset(phaseOff);
      if (!RUNNING) phase_set(ui_phase);
      break;


    case 't':
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      d = in_range(SERVO_MIN, SERVO_MID, atoi(tok));
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      u = in_range(SERVO_MID, SERVO_MAX, atoi(tok));
      tilt_setLimits(d, u);
      break;
      
    case 'p':
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      tilt_parity = atoi(tok) ;
      break;

    case 'S':
      tok = strtok(cmd, " :");
      tok = strtok(NULL, " ");
      if (tok == NULL) goto INVALID;
      mytime_setSpeed(in_range(-100, 100, atoi(tok)));
      RUNNING=true;
      break;

    case 'W':
      eeprom_write();
      break;

    case 'R':
      BREAK = false;
      RUNNING = true;
      error_mess = NULL;
      mytime_setSpeed(0);
      break;

    case '?':
      ui_welcome();
      break;

    case 'L':
      {
        int Minute = tm.getMinute();
        int Second = tm.getSecond();
        int Year = tm.getYear();
        int Month = tm.getMonth();
        int Day = tm.getDay();
        int Hour = tm.getHour();

        tok = strtok(cmd, " :");
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        n = in_range(1, 200, atoi(tok));

        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        incHr = in_range(1, 366 * 24, atoi(tok));

        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Year = in_range(2016, 2200, atoi(tok));
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Month = in_range(1, 12, atoi(tok));
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Day = in_range(1, mytime_daysInMonth(Month, Year), atoi(tok));
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Hour = in_range(0, 23, atoi(tok));
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Minute = in_range(0, 59, atoi(tok));
        tok = strtok(NULL, " ");
        if (tok == NULL) goto OK2;
        Second = in_range(0, 59, atoi(tok));

OK2:
        MyTime tt = MyTime(Year, Month, Day, Hour, Minute, Second);
        moon_printTable(tt, n, incHr);
      }

      break;

  }

  ui_prompt();
  return;
INVALID:
  myprintf(F("\n Command error \n>"), cmd);
  ui_prompt();
  return;
}