static void display_all(struct termios *mode, int fd, const char *device_name) { int i; tcflag_t *bitsp; unsigned long mask; enum mode_type prev_type = control; display_speed(mode, 1); #ifdef TIOCGWINSZ display_window_size(1, fd, device_name); #endif #ifdef HAVE_C_LINE wrapf("line = %d;", mode->c_line); #endif putchar('\n'); current_col = 0; for (i = 0; control_info[i].name != stty_min; ++i) { /* If swtch is the same as susp, don't print both. */ #if VSWTCH == VSUSP if (control_info[i].name == stty_swtch) continue; #endif /* If eof uses the same slot as min, only print whichever applies. */ #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0 && (control_info[i].name == stty_eof || control_info[i].name == stty_eol)) continue; #endif wrapf("%s = %s;", control_info[i].name, visible(mode->c_cc[control_info[i].offset])); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) #endif wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]); if (current_col != 0) putchar('\n'); current_col = 0; for (i = 0; i < NUM_mode_info; ++i) { if (mode_info[i].flags & OMIT) continue; if (mode_info[i].type != prev_type) { putchar('\n'); current_col = 0; prev_type = mode_info[i].type; } bitsp = mode_type_flag(mode_info[i].type, mode); mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; if ((*bitsp & mask) == mode_info[i].bits) wrapf("%s", mode_info[i].name); else if (mode_info[i].flags & REV) wrapf("-%s", mode_info[i].name); } putchar('\n'); current_col = 0; }
static void do_display(const struct termios *mode, const int all) { int i; tcflag_t *bitsp; unsigned long mask; int prev_type = control; display_speed(mode, 1); if (all) display_window_size(1); #ifdef HAVE_C_LINE wrapf("line = %d;\n", mode->c_line); #else wrapf("\n"); #endif for (i = 0; control_info[i].name != stty_min; ++i) { /* If swtch is the same as susp, don't print both */ #if VSWTCH == VSUSP if (control_info[i].name == stty_swtch) continue; #endif /* If eof uses the same slot as min, only print whichever applies */ #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0 && (control_info[i].name == stty_eof || control_info[i].name == stty_eol)) continue; #endif wrapf("%s = %s;", control_info[i].name, visible(mode->c_cc[control_info[i].offset])); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) #endif wrapf("min = %d; time = %d;", mode->c_cc[VMIN], mode->c_cc[VTIME]); if (current_col) wrapf("\n"); for (i = 0; i < NUM_mode_info; ++i) { if (mode_info[i].flags & OMIT) continue; if (mode_info[i].type != prev_type) { /* wrapf("\n"); */ if (current_col) wrapf("\n"); prev_type = mode_info[i].type; } bitsp = mode_type_flag(mode_info[i].type, mode); mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; if ((*bitsp & mask) == mode_info[i].bits) { if (all || (mode_info[i].flags & SANE_UNSET)) wrapf("%s", mode_info[i].name); } else { if ((all && mode_info[i].flags & REV) || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV))) wrapf("-%s", mode_info[i].name); } } if (current_col) wrapf("\n"); }
static void do_display(const struct termios *mode, int all) { int i; tcflag_t *bitsp; unsigned long mask; int prev_type = control; display_speed(mode, 1); if (all) display_window_size(1); #ifdef __linux__ wrapf("line = %u;\n", mode->c_line); #else newline(); #endif for (i = 0; i != CIDX_min; ++i) { char ch; /* If swtch is the same as susp, don't print both */ #if VSWTCH == VSUSP if (i == CIDX_swtch) continue; #endif /* If eof uses the same slot as min, only print whichever applies */ #if VEOF == VMIN if (!(mode->c_lflag & ICANON) && (i == CIDX_eof || i == CIDX_eol) ) { continue; } #endif ch = mode->c_cc[control_info[i].offset]; if (ch == _POSIX_VDISABLE) strcpy(G.buf, "<undef>"); else visible(ch, G.buf, 0); wrapf("%s = %s;", nth_string(control_name, i), G.buf); } #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0) #endif wrapf("min = %u; time = %u;", mode->c_cc[VMIN], mode->c_cc[VTIME]); newline(); for (i = 0; i < NUM_mode_info; ++i) { if (mode_info[i].flags & OMIT) continue; if (mode_info[i].type != prev_type) { newline(); prev_type = mode_info[i].type; } bitsp = get_ptr_to_tcflag(mode_info[i].type, mode); mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; if ((*bitsp & mask) == mode_info[i].bits) { if (all || (mode_info[i].flags & SANE_UNSET)) wrapf("-%s"+1, nth_string(mode_name, i)); } else { if ((all && mode_info[i].flags & REV) || (!all && (mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) ) { wrapf("-%s", nth_string(mode_name, i)); } } } newline(); }
int stty_main(int argc UNUSED_PARAM, char **argv) { struct termios mode; void (*output_func)(const struct termios *, int); const char *file_name = NULL; int display_all = 0; int stty_state; int k; INIT_G(); stty_state = STTY_noargs; output_func = do_display; /* First pass: only parse/verify command line params */ k = 0; while (argv[++k]) { const struct mode_info *mp; const struct control_info *cp; const char *arg = argv[k]; const char *argnext = argv[k+1]; int param; if (arg[0] == '-') { int i; mp = find_mode(arg+1); if (mp) { if (!(mp->flags & REV)) goto invalid_argument; stty_state &= ~STTY_noargs; continue; } /* It is an option - parse it */ i = 0; while (arg[++i]) { switch (arg[i]) { case 'a': stty_state |= STTY_verbose_output; output_func = do_display; display_all = 1; break; case 'g': stty_state |= STTY_recoverable_output; output_func = display_recoverable; break; case 'F': if (file_name) bb_error_msg_and_die("only one device may be specified"); file_name = &arg[i+1]; /* "-Fdevice" ? */ if (!file_name[0]) { /* nope, "-F device" */ int p = k+1; /* argv[p] is argnext */ file_name = argnext; if (!file_name) bb_error_msg_and_die(bb_msg_requires_arg, "-F"); /* remove -F param from arg[vc] */ while (argv[p]) { argv[p] = argv[p+1]; ++p; } } goto end_option; default: goto invalid_argument; } } end_option: continue; } mp = find_mode(arg); if (mp) { stty_state &= ~STTY_noargs; continue; } cp = find_control(arg); if (cp) { if (!argnext) bb_error_msg_and_die(bb_msg_requires_arg, arg); /* called for the side effect of xfunc death only */ set_control_char_or_die(cp, argnext, &mode); stty_state &= ~STTY_noargs; ++k; continue; } param = find_param(arg); if (param & param_need_arg) { if (!argnext) bb_error_msg_and_die(bb_msg_requires_arg, arg); ++k; } switch (param) { #ifdef __linux__ case param_line: # ifndef TIOCGWINSZ xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); break; # endif /* else fall-through */ #endif #ifdef TIOCGWINSZ case param_rows: case param_cols: case param_columns: xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes); break; case param_size: #endif case param_speed: break; case param_ispeed: /* called for the side effect of xfunc death only */ set_speed_or_die(input_speed, argnext, &mode); break; case param_ospeed: /* called for the side effect of xfunc death only */ set_speed_or_die(output_speed, argnext, &mode); break; default: if (recover_mode(arg, &mode) == 1) break; if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) break; invalid_argument: bb_error_msg_and_die("invalid argument '%s'", arg); } stty_state &= ~STTY_noargs; } /* Specifying both -a and -g is an error */ if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) == (STTY_verbose_output | STTY_recoverable_output) ) { bb_error_msg_and_die("-a and -g are mutually exclusive"); } /* Specifying -a or -g with non-options is an error */ if ((stty_state & (STTY_verbose_output | STTY_recoverable_output)) && !(stty_state & STTY_noargs) ) { bb_error_msg_and_die("modes may not be set when -a or -g is used"); } /* Now it is safe to start doing things */ if (file_name) { G.device_name = file_name; xmove_fd(xopen_nonblocking(G.device_name), STDIN_FILENO); ndelay_off(STDIN_FILENO); } /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure */ memset(&mode, 0, sizeof(mode)); if (tcgetattr(STDIN_FILENO, &mode)) perror_on_device_and_die("%s"); if (stty_state & (STTY_verbose_output | STTY_recoverable_output | STTY_noargs)) { G.max_col = get_terminal_width(STDOUT_FILENO); output_func(&mode, display_all); return EXIT_SUCCESS; } /* Second pass: perform actions */ k = 0; while (argv[++k]) { const struct mode_info *mp; const struct control_info *cp; const char *arg = argv[k]; const char *argnext = argv[k+1]; int param; if (arg[0] == '-') { mp = find_mode(arg+1); if (mp) { set_mode(mp, 1 /* reversed */, &mode); stty_state |= STTY_require_set_attr; } /* It is an option - already parsed. Skip it */ continue; } mp = find_mode(arg); if (mp) { set_mode(mp, 0 /* non-reversed */, &mode); stty_state |= STTY_require_set_attr; continue; } cp = find_control(arg); if (cp) { ++k; set_control_char_or_die(cp, argnext, &mode); stty_state |= STTY_require_set_attr; continue; } param = find_param(arg); if (param & param_need_arg) { ++k; } switch (param) { #ifdef __linux__ case param_line: mode.c_line = xatoul_sfx(argnext, stty_suffixes); stty_state |= STTY_require_set_attr; break; #endif #ifdef TIOCGWINSZ case param_cols: case param_columns: set_window_size(-1, xatoul_sfx(argnext, stty_suffixes)); break; case param_size: display_window_size(0); break; case param_rows: set_window_size(xatoul_sfx(argnext, stty_suffixes), -1); break; #endif case param_speed: display_speed(&mode, 0); break; case param_ispeed: set_speed_or_die(input_speed, argnext, &mode); stty_state |= (STTY_require_set_attr | STTY_speed_was_set); break; case param_ospeed: set_speed_or_die(output_speed, argnext, &mode); stty_state |= (STTY_require_set_attr | STTY_speed_was_set); break; default: if (recover_mode(arg, &mode) == 1) stty_state |= STTY_require_set_attr; else /* true: if (tty_value_to_baud(xatou(arg)) != (speed_t) -1) */{ set_speed_or_die(both_speeds, arg, &mode); stty_state |= (STTY_require_set_attr | STTY_speed_was_set); } /* else - impossible (caught in the first pass): bb_error_msg_and_die("invalid argument '%s'", arg); */ } } if (stty_state & STTY_require_set_attr) { struct termios new_mode; if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode)) perror_on_device_and_die("%s"); /* POSIX (according to Zlotnick's book) tcsetattr returns zero if it performs *any* of the requested operations. This means it can report 'success' when it has actually failed to perform some proper subset of the requested operations. To detect this partial failure, get the current terminal attributes and compare them to the requested ones */ /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure */ memset(&new_mode, 0, sizeof(new_mode)); if (tcgetattr(STDIN_FILENO, &new_mode)) perror_on_device_and_die("%s"); if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { /* * I think the below chunk is not necessary on Linux. * If you are deleting it, also delete STTY_speed_was_set bit - * it is only ever checked here. */ #if 0 /* was "if CIBAUD" */ /* SunOS 4.1.3 (at least) has the problem that after this sequence, tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2); sometimes (m1 != m2). The only difference is in the four bits of the c_cflag field corresponding to the baud rate. To save Sun users a little confusion, don't report an error if this happens. But suppress the error only if we haven't tried to set the baud rate explicitly -- otherwise we'd never give an error for a true failure to set the baud rate */ new_mode.c_cflag &= (~CIBAUD); if ((stty_state & STTY_speed_was_set) || memcmp(&mode, &new_mode, sizeof(mode)) != 0) #endif perror_on_device_and_die("%s: cannot perform all requested operations"); } } return EXIT_SUCCESS; }
/* This is called at the end of each screen frame. It flushes the audio buffer and keeps control of the emulation speed. */ int vsync_do_vsync(struct video_canvas_s *c, int been_skipped) { static unsigned long next_frame_start = 0; unsigned long network_hook_time = 0; /* * these are the counters to show how many frames are skipped * since the last vsync_display_speed */ static int frame_counter = 0; static int skipped_frames = 0; /* * This are the frames which are skipped in a row */ static int skipped_redraw = 0; /* Adjustment of frame output frequency. */ static unsigned long adjust_start; static int frames_adjust; static signed long avg_sdelay, prev_sdelay; double sound_delay; int skip_next_frame; signed long delay; long frame_ticks_remainder, frame_ticks_integer, compval; #if (defined(HAVE_OPENGL_SYNC)) && !defined(USE_SDLUI) float refresh_cmp; int refresh_div; #endif #ifdef HAVE_NETWORK /* check if someone wants to connect remotely to the monitor */ monitor_check_remote(); #endif vsync_frame_counter++; /* * process everything wich should be done before the synchronisation * e.g. OS/2: exit the programm if trigger_shutdown set */ vsyncarch_presync(); /* Run vsync jobs. */ if (network_connected()) { network_hook_time = vsyncarch_gettime(); } vsync_hook(); if (network_connected()) { network_hook_time = vsyncarch_gettime() - network_hook_time; if (network_hook_time > (unsigned long)frame_ticks) { next_frame_start += network_hook_time; now += network_hook_time; } } #ifdef DEBUG /* switch between recording and playback in history debug mode */ debug_check_autoplay_mode(); #endif /* * Update display every two second (pc system time) * This has some reasons: * - we have a better statistic in case of a fastly running emulator * - we don't slow down fast emulations by updating this value * too often (eg more then 10 times a second) * - I don't want to have a value jumping around for example * between 99% and 101% if the user chooses 100% (s.above) * - We need some statistict to get an avarage number for the * frame-rate without staticstics it would also jump around */ frame_counter++; if (!speed_eval_suspended && (signed long)(now - display_start) >= 2 * vsyncarch_freq) { display_speed(frame_counter - skipped_frames); display_start = now; frame_counter = 0; skipped_frames = 0; } if (been_skipped) { skipped_frames++; } /* Flush sound buffer, get delay in seconds. */ sound_delay = sound_flush(); /* Get current time, directly after getting the sound delay. */ now = vsyncarch_gettime(); /* Start afresh after pause in frame output. */ if (speed_eval_suspended) { speed_eval_suspended = 0; speed_eval_prev_clk = maincpu_clk; display_start = now; frame_counter = 0; skipped_frames = 0; next_frame_start = now; skipped_redraw = 0; } /* Start afresh after "out of sync" cases. */ if (sync_reset) { sync_reset = 0; adjust_start = now; frames_adjust = 0; avg_sdelay = 0; prev_sdelay = 0; frame_ticks = (frame_ticks_orig + frame_ticks) / 2; } /* This is the time between the start of the next frame and now. */ delay = (signed long)(now - next_frame_start); #if (defined(HAVE_OPENGL_SYNC)) && !defined(USE_SDLUI) refresh_cmp = (float)(c->refreshrate / refresh_frequency); refresh_div = (int)(refresh_cmp + 0.5f); refresh_cmp /= (float)refresh_div; if ((timer_speed == 100) && (!warp_mode_enabled) && vsyncarch_vbl_sync_enabled() && (refresh_cmp <= 1.02f) && (refresh_cmp > 0.98f) && (refresh_div == 1)) { vsyncarch_verticalblank(c, c->refreshrate, refresh_div); skip_next_frame = 0; skipped_redraw = 0; } else { #endif /* * We sleep until the start of the next frame, if: * - warp_mode is disabled * - a limiting speed is given * - we have not reached next_frame_start yet * * We could optimize by sleeping only if a frame is to be output. */ /*log_debug("vsync_do_vsync: sound_delay=%f frame_ticks=%d delay=%d", sound_delay, frame_ticks, delay);*/ if (!warp_mode_enabled && timer_speed && delay < 0) { vsyncarch_sleep(-delay); } #if (defined(HAVE_OPENGL_SYNC)) && !defined(USE_SDLUI) vsyncarch_prepare_vbl(); #endif /* * Check whether we should skip the next frame or not. * Allow delay of up to one frame before skipping frames. * Frames are skipped: * - only if maximum skipped frames are not reached * - if warp_mode enabled * - if speed is not limited or we are too slow and * refresh rate is automatic or fixed and needs correction * * Remark: The time_deviation should be the equivalent of two * frames and must be scaled to make sure, that we * don't start skipping frames before the CPU reaches 100%. * If we are becoming faster a small deviation because of * threading results in a frame rate correction suddenly. */ frame_ticks_remainder = frame_ticks % 100; frame_ticks_integer = frame_ticks / 100; compval = frame_ticks_integer * 3 * timer_speed + frame_ticks_remainder * 3 * timer_speed / 100; if (skipped_redraw < MAX_SKIPPED_FRAMES && (warp_mode_enabled || (skipped_redraw < refresh_rate - 1) || ((!timer_speed || delay > compval) && !refresh_rate ) ) ) { skip_next_frame = 1; skipped_redraw++; } else { skip_next_frame = 0; skipped_redraw = 0; } #if (defined(HAVE_OPENGL_SYNC)) && !defined(USE_SDLUI) } #endif /* * Check whether the hardware can keep up. * Allow up to 0,25 second error before forcing a correction. */ if ((signed long)(now - next_frame_start) >= vsyncarch_freq / 8) { #if !defined(__OS2__) && !defined(DEBUG) if (!warp_mode_enabled && relative_speed) { log_warning(LOG_DEFAULT, "Your machine is too slow for current settings!"); } #endif vsync_sync_reset(); next_frame_start = now; } /* Adjust frame output frequency to match sound speed. This only kicks in for cycle based sound and SOUND_ADJUST_EXACT. */ if (frames_adjust < INT_MAX) { frames_adjust++; } /* Adjust audio-video sync */ if (!network_connected() && (signed long)(now - adjust_start) >= vsyncarch_freq / 5) { signed long adjust; avg_sdelay /= frames_adjust; /* Account for both relative and absolute delay. */ adjust = (avg_sdelay - prev_sdelay + avg_sdelay / 8) / frames_adjust; /* Maximum adjustment step 1%. */ if (labs(adjust) > frame_ticks / 100) { adjust = adjust / labs(adjust) * frame_ticks / 100; } frame_ticks -= adjust; frames_adjust = 0; prev_sdelay = avg_sdelay; avg_sdelay = 0; adjust_start = now; } else { /* Actual sound delay is sound delay minus vsync delay. */ signed long sdelay = (signed long)(sound_delay * vsyncarch_freq); avg_sdelay += sdelay; } next_frame_start += frame_ticks; vsyncarch_postsync(); #if 0 FILE *fd = fopen("latencylog.txt", "a"); fprintf(fd, "%d %ld %ld %lf\n", vsync_frame_counter, frame_ticks, delay, sound_delay * 1000000); fclose(fd); #endif return skip_next_frame; }
/* This is called at the end of each screen frame. It flushes the audio buffer and keeps control of the emulation speed. */ int vsync_do_vsync(int been_skipped) { static unsigned short frame_counter = USHRT_MAX; static unsigned short num_skipped_frames; static int skip_counter; int skip_next_frame = 0; vsync_hook(); if (been_skipped) num_skipped_frames++; if (timer_speed != relative_speed) { frame_counter = USHRT_MAX; if (set_timer_speed(relative_speed) < 0) { log_error(LOG_DEFAULT, "Trouble setting timers... giving up."); /* FIXME: Hm, maybe we should be smarter. But this is should never happen.*/ exit(-1); } } if (warp_mode_enabled) { /* "Warp Mode". Just skip as many frames as possible and do not limit the maximum speed at all. */ if (skip_counter < MAX_SKIPPED_FRAMES) { skip_next_frame = 1; skip_counter++; } else skip_counter = elapsed_frames = 0; sound_flush(0); } else if (refresh_rate != 0) { update_elapsed_frames(0); /* Fixed refresh rate. */ if (timer_speed && skip_counter >= elapsed_frames) timer_sleep(); if (skip_counter < refresh_rate - 1) { skip_next_frame = 1; skip_counter++; } else skip_counter = elapsed_frames = 0; patch_timer(sound_flush(relative_speed)); } else { /* Dynamically adjusted refresh rate. */ update_elapsed_frames(0); if (skip_counter >= elapsed_frames) { elapsed_frames = -1; timer_sleep(); skip_counter = 0; } else if (skip_counter < MAX_SKIPPED_FRAMES) { skip_next_frame = 1; skip_counter++; } else skip_counter = elapsed_frames = 0; patch_timer(sound_flush(relative_speed)); } if (frame_counter >= refresh_frequency * 2) { display_speed(frame_counter + 1 - num_skipped_frames); num_skipped_frames = 0; frame_counter = 0; } else frame_counter++; kbdbuf_flush(); #ifdef HAS_JOYSTICK joystick_update(); #endif return skip_next_frame; }
int main() { uint8_t show_speed = 0; Initialization(); // Beeper PORTB |= 0x20; DDRB |= 0x20; // LED enable DDRE |= 0x40; // Pullups on phototransistors PORTE |= 0x30; // Timer 2 is used for beep and power-off timing ASSR = 0; TCCR2A = 3; // ~122Hz TIMSK2 = 1; power_off(); while (1) { set_sleep_mode(SLEEP_MODE_IDLE); sleep_mode(); // Auto power off if (power_off_time == 0) { power_off(); } switch (getkey()) { case KEY_DOWN: // Power off power_off(); break; case KEY_UP: // Clear last measurement reset(); clear_display(); break; case KEY_RIGHT: if (time_us) { if (show_speed) { // Display raw time in microseconds display_number(time_us, 6); show_speed = 0; } else { display_speed(); show_speed = 1; } } break; } if (speed_state == SPEED_FWD_DONE || speed_state == SPEED_REV_DONE) { // Display last speed // Time in microseconds time_us = beam_timer_value(); if (speed_state == SPEED_FWD_DONE) { forward = 1; beep(1400); } else { forward = 0; beep(600); } speed_state = SPEED_IDLE; reset_auto_power_off(); display_speed(); } } }
int main(void) { // TWI initialization // Bit Rate: 100,000 kHz TWBR=0x20; // Two Wire Bus Slave Address: 0x5 // General Call Recognition: On TWAR=0x0B; // Generate Acknowledge Pulse: On // TWI Interrupt: On TWCR=0x45; TWSR=0x00; // Timer/Counter 0 initialization // Clock source: System Clock // Clock value: 7,813 kHz TCCR0=0x01; TCNT0=0x00; // Timer(s)/Counter(s) Interrupt(s) initialization TIMSK=0x01; // Инициализация портов 0- установка бита порта на вход, 1- на выход. PORTB=0xff; DDRB=0xff; PORTD=0xff; DDRD=0x00; // Global enable interrupts asm volatile ("sei"); _delay_ms(100);//Общая задержка перед выполнением программы if((32|PIND)==PIND) {PD5p=1;} else {PD5p=0;}//Инициализация энкодера Если значения одинаковы значит на 5 ножке лог.1 иначе 0 if((64|PIND)==PIND) {PD6p=1;} else {PD6p=0;} //(энкодер подключен к 5 и 6 ножке порта D) while(1) { _delay_ms(4); // обработчик энкодера(энкодер подключен к 5 и 6 ножке порта D) // increment if (((PD6p==1)&&(PD5p==0)&&((32|PIND)!=PIND)&&((64|PIND)!=PIND))|((PD6p==0)&&(PD5p==0)&&((32|PIND)==PIND)&&((64|PIND)!=PIND))|((PD6p==0)&&(PD5p==1)&&((32|PIND)==PIND)&&((64|PIND)==PIND))|((PD6p==1)&&(PD5p==1)&&((32|PIND)!=PIND)&&((64|PIND)==PIND))) { if (speeder < MAX_SPEED) { speeder += SPEED_STEP; } else { speeder = MAX_SPEED + 1; }// для изменения положения нуля } // decrement if (((PD6p==0)&&(PD5p==0)&&((32|PIND)!=PIND)&&((64|PIND)==PIND))|((PD6p==1)&&(PD5p==0)&&((32|PIND)==PIND)&&((64|PIND)==PIND))|((PD6p==1)&&(PD5p==1)&&((32|PIND)==PIND)&&((64|PIND)!=PIND))|((PD6p==0)&&(PD5p==1)&&((32|PIND)!=PIND)&&((64|PIND)!=PIND))) { if (speeder > MAX_SPEED) { speeder = MAX_SPEED; } if (speeder > 3*SPEED_STEP) { speeder -= SPEED_STEP; } } if((PIND|32)==PIND) {PD5p=1;} else {PD5p=0;}//Запомнить состояние энкодера if((PIND|64)==PIND) {PD6p=1;} else {PD6p=0;} // Формирование отображаемого числа: display_speed(speeder); //Обработчик кнопок: if ((((PIND|2)==PIND)|((PIND|1)==PIND))&&(stop==0)&&((PD0p==0)|(PD1p==0))&&((Kn1==1)|(Kn2==1))) {stop=1; } // Обработка сигнала стоп - по нажатию любой кнопки, если двигатель крутится if (((PIND|1)==PIND)&&(stop==1)&&(PD0p==0)) {PORTB|=4; stop= 0; stopp=0; Kn1=1; _delay_ms(16); }// Крутим, предположительно, в лево if (((PIND|2)==PIND)&&(stop==1)&&(PD1p==0)) {PORTB&=~4; stop= 0; stopp=0; Kn2=1; _delay_ms(16); }// Крутим, предположительно, в право if ((PIND|1)==PIND) {PD0p=1;} else {PD0p=0;}//Запомнить состояние кнопок, крутим по условию отпускания кнопки if ((PIND|2)==PIND) {PD1p=1;} else {PD1p=0;} // PORTB= 0b01010100; //PORTB&=~0b01000100; Маска для сброса битов //PORTB|= 0b01000100; Маска для установки битов TWCR=StartTWI;// инициируем начало передачи данных } }
extern int main(int argc, char **argv) #endif { struct termios mode; enum output_type output_type; int optc; int require_set_attr; int speed_was_set; int verbose_output; int recoverable_output; int k; int noargs = 1; char * file_name = NULL; int fd; const char *device_name; output_type = changed; verbose_output = 0; recoverable_output = 0; /* Don't print error messages for unrecognized options. */ opterr = 0; while ((optc = getopt(argc, argv, "agF:")) != -1) { switch (optc) { case 'a': verbose_output = 1; output_type = all; break; case 'g': recoverable_output = 1; output_type = recoverable; break; case 'F': if (file_name) error_msg_and_die("only one device may be specified"); file_name = optarg; break; default: /* unrecognized option */ noargs = 0; break; } if (noargs == 0) break; } if (optind < argc) noargs = 0; /* Specifying both -a and -g gets an error. */ if (verbose_output && recoverable_output) error_msg_and_die ("verbose and stty-readable output styles are mutually exclusive"); /* Specifying any other arguments with -a or -g gets an error. */ if (!noargs && (verbose_output || recoverable_output)) error_msg_and_die ("modes may not be set when specifying an output style"); /* FIXME: it'd be better not to open the file until we've verified that all arguments are valid. Otherwise, we could end up doing only some of the requested operations and then failing, probably leaving things in an undesirable state. */ if (file_name) { int fdflags; device_name = file_name; fd = open(device_name, O_RDONLY | O_NONBLOCK); if (fd < 0) perror_msg_and_die("%s", device_name); if ((fdflags = fcntl(fd, F_GETFL)) == -1 || fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0) perror_msg_and_die("%s: couldn't reset non-blocking mode", device_name); } else { fd = 0; device_name = "standard input"; } /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure. */ memset(&mode, 0, sizeof(mode)); if (tcgetattr(fd, &mode)) perror_msg_and_die("%s", device_name); if (verbose_output || recoverable_output || noargs) { max_col = screen_columns(); current_col = 0; display_settings(output_type, &mode, fd, device_name); return EXIT_SUCCESS; } speed_was_set = 0; require_set_attr = 0; k = 0; while (++k < argc) { int match_found = 0; int reversed = 0; int i; if (argv[k][0] == '-') { char *find_dev_opt; ++argv[k]; /* Handle "-a", "-ag", "-aF/dev/foo", "-aF /dev/foo", etc. Find the options that have been parsed. This is really gross, but it's needed because stty SETTINGS look like options to getopt(), so we need to work around things in a really horrible way. If any new options are ever added to stty, the short option MUST NOT be a letter which is the first letter of one of the possible stty settings. */ find_dev_opt = strchr(argv[k], 'F'); /* find -*F* */ if(find_dev_opt) { if(find_dev_opt[1]==0) /* -*F /dev/foo */ k++; /* skip /dev/foo */ continue; /* else -*F/dev/foo - no skip */ } if(argv[k][0]=='a' || argv[k][0]=='g') continue; /* Is not options - is reverse params */ reversed = 1; } for (i = 0; i < NUM_mode_info; ++i) if (STREQ(argv[k], mode_info[i].name)) { match_found = set_mode(&mode_info[i], reversed, &mode); require_set_attr = 1; break; } if (match_found == 0 && reversed) error_msg_and_die("invalid argument `%s'", --argv[k]); if (match_found == 0) for (i = 0; i < NUM_control_info; ++i) if (STREQ(argv[k], control_info[i].name)) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); match_found = 1; ++k; set_control_char(&control_info[i], argv[k], &mode); require_set_attr = 1; break; } if (match_found == 0) { if (STREQ(argv[k], "ispeed")) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); ++k; set_speed(input_speed, argv[k], &mode); speed_was_set = 1; require_set_attr = 1; } else if (STREQ(argv[k], "ospeed")) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); ++k; set_speed(output_speed, argv[k], &mode); speed_was_set = 1; require_set_attr = 1; } #ifdef TIOCGWINSZ else if (STREQ(argv[k], "rows")) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); ++k; set_window_size((int) parse_number(argv[k], stty_suffixes), -1, fd, device_name); } else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); ++k; set_window_size(-1, (int) parse_number(argv[k], stty_suffixes), fd, device_name); } else if (STREQ(argv[k], "size")) { max_col = screen_columns(); current_col = 0; display_window_size(0, fd, device_name); } #endif #ifdef HAVE_C_LINE else if (STREQ(argv[k], "line")) { if (k == argc - 1) error_msg_and_die("missing argument to `%s'", argv[k]); ++k; mode.c_line = parse_number(argv[k], stty_suffixes); require_set_attr = 1; } #endif else if (STREQ(argv[k], "speed")) { max_col = screen_columns(); display_speed(&mode, 0); } else if (recover_mode(argv[k], &mode) == 1) require_set_attr = 1; else if (string_to_baud(argv[k]) != (speed_t) - 1) { set_speed(both_speeds, argv[k], &mode); speed_was_set = 1; require_set_attr = 1; } else error_msg_and_die("invalid argument `%s'", argv[k]); } } if (require_set_attr) { struct termios new_mode; if (tcsetattr(fd, TCSADRAIN, &mode)) perror_msg_and_die("%s", device_name); /* POSIX (according to Zlotnick's book) tcsetattr returns zero if it performs *any* of the requested operations. This means it can report `success' when it has actually failed to perform some proper subset of the requested operations. To detect this partial failure, get the current terminal attributes and compare them to the requested ones. */ /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure. */ memset(&new_mode, 0, sizeof(new_mode)); if (tcgetattr(fd, &new_mode)) perror_msg_and_die("%s", device_name); /* Normally, one shouldn't use memcmp to compare structures that may have `holes' containing uninitialized data, but we have been careful to initialize the storage of these two variables to all zeroes. One might think it more efficient simply to compare the modified fields, but that would require enumerating those fields -- and not all systems have the same fields in this structure. */ if (memcmp(&mode, &new_mode, sizeof(mode)) != 0) { #ifdef CIBAUD /* SunOS 4.1.3 (at least) has the problem that after this sequence, tcgetattr (&m1); tcsetattr (&m1); tcgetattr (&m2); sometimes (m1 != m2). The only difference is in the four bits of the c_cflag field corresponding to the baud rate. To save Sun users a little confusion, don't report an error if this happens. But suppress the error only if we haven't tried to set the baud rate explicitly -- otherwise we'd never give an error for a true failure to set the baud rate. */ new_mode.c_cflag &= (~CIBAUD); if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0) #endif error_msg_and_die ("%s: unable to perform all requested operations", device_name); } } return EXIT_SUCCESS; }
static void display_changed(struct termios *mode) { int i; int empty_line; tcflag_t *bitsp; unsigned long mask; enum mode_type prev_type = control; display_speed(mode, 1); #ifdef HAVE_C_LINE wrapf("line = %d;", mode->c_line); #endif putchar('\n'); current_col = 0; empty_line = 1; for (i = 0; control_info[i].name != stty_min; ++i) { if (mode->c_cc[control_info[i].offset] == control_info[i].saneval) continue; /* If swtch is the same as susp, don't print both. */ #if VSWTCH == VSUSP if (control_info[i].name == stty_swtch) continue; #endif /* If eof uses the same slot as min, only print whichever applies. */ #if VEOF == VMIN if ((mode->c_lflag & ICANON) == 0 && (control_info[i].name == stty_eof || control_info[i].name == stty_eol)) continue; #endif empty_line = 0; wrapf("%s = %s;", control_info[i].name, visible(mode->c_cc[control_info[i].offset])); } if ((mode->c_lflag & ICANON) == 0) { wrapf("min = %d; time = %d;\n", (int) mode->c_cc[VMIN], (int) mode->c_cc[VTIME]); } else if (empty_line == 0) putchar('\n'); current_col = 0; empty_line = 1; for (i = 0; i < NUM_mode_info; ++i) { if (mode_info[i].flags & OMIT) continue; if (mode_info[i].type != prev_type) { if (empty_line == 0) { putchar('\n'); current_col = 0; empty_line = 1; } prev_type = mode_info[i].type; } bitsp = mode_type_flag(mode_info[i].type, mode); mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; if ((*bitsp & mask) == mode_info[i].bits) { if (mode_info[i].flags & SANE_UNSET) { wrapf("%s", mode_info[i].name); empty_line = 0; } } else if ((mode_info[i].flags & (SANE_SET | REV)) == (SANE_SET | REV)) { wrapf("-%s", mode_info[i].name); empty_line = 0; } } if (empty_line == 0) putchar('\n'); current_col = 0; }