void step() { // print pointer to current instruction if debug is on, THIS WILL CRASH WITH LOOPS // if(DEBUG) { // char* point = malloc(sizeof(program)); // for(int i = 0; i <= counter; ++i) strcat(point, "^"); // printf("%s\n%s\n", program, point); // free(point); // } if(FLAGS & F_LOOPINIT) { loopreg = program[counter++] - 48; loopcounter = counter--; TOGGLE(F_LOOPINIT); TOGGLE(F_LOOP); if(DEBUG) printf("start of loop at: %i\n", loopcounter); if(DEBUG) printf("loopreg: %i\n", loopreg); } if(FLAGS & F_LOOP) { if(program[counter] == 'l') { if(r[loopreg] == 0) { counter++; TOGGLE(F_LOOP); return; } else { counter = loopcounter; } } interp(program[counter]); } else { interp(program[counter]); } }
//# MENU cpld void cpld_menu(){ getInputWaitRelease(); SETUPgout(EN_1V8); ON(EN_1V8); delayNop(1000000); /* wait until cpld boot */ cpu_clock_set(204); lcdClear(); lcdPrintln("CPLD"); lcdNl(); lcdNl(); bytes=0; lcdPrint(IntToStr(bytes,5,F_LONG)); lcdPrint(" bytes..."); lcdNl(); #define WAIT_LOOP_DELAY (6000000) #define ALL_LEDS (PIN_LED1|PIN_LED2|PIN_LED3) int i; int error; FRESULT res; res=f_open(&file, "cpld.xsv", FA_OPEN_EXISTING|FA_READ); if(res!=FR_OK){ lcdPrintln("FOPEN ERROR"); lcdPrintln(f_get_rc_string(res)); lcdDisplay(); getInputWait(); return; }; refill_cpld_buffer_fs(); error = cpld_jtag_program(sizeof(cpld_xsvf_buffer), cpld_xsvf_buffer, refill_cpld_buffer_fs); if(error){ lcdPrintln("Programming failed!"); lcdPrintln(IntToStr(error,5,0)); lcdDisplay(); /* LED3 (Red) steady on error */ ON(LED3); while (1); }; lcdPrintln("Success."); lcdDisplay(); for (res=0;res<10;res++){ /* blink LED1, LED2, and LED3 on success */ TOGGLE(LED1); TOGGLE(LED2); TOGGLE(LED3); for (i = 0; i < WAIT_LOOP_DELAY; i++) /* Wait a bit. */ __asm__("nop"); }; /* XXX: Maybe power toggle needed to start CPLD? */ OFF(EN_1V8); };
void assert_die(void) { SETUPgout(LED4); while(1) { TOGGLE(LED4); delay(3000000); }; };
void process_flags(t_mod *m) { if (ft_strchr("sdipc", m->convers) && GET(m->flag, F_HASH)) TOGGLE(m->flag, F_HASH); if (GET(m->flag, F_ZERO) && m->prec && ft_strchr("dDioOuUixX", m->convers)) TOGGLE(m->flag, F_ZERO); if (GET(m->flag, F_ZERO) && GET(m->flag, F_MINUS)) TOGGLE(m->flag, F_ZERO); if (GET(m->flag, F_SPACE) && ft_strchr("oOuUxXD", m->convers)) TOGGLE(m->flag, F_SPACE); if (GET(m->flag, F_SPACE) && GET(m->flag, F_PLUS)) TOGGLE(m->flag, F_SPACE); if (GET(m->flag, F_PREC) && !m->length && ft_strchr("dDioOuUixX", m->convers)) SET(m->flag, F_ZERO); }
/** * The main periodic process implementation. * * This function is being called every time new sensor data arrives through the * interrupt system. */ void run_sensor_process(void) { u16 battery_voltage = adc_data.battery_voltage; u16 current = adc_data.current; u16 temp = adc_data.temp; TOGGLE(LED_RED); /* Calculate battery voltage */ sensors.battery_voltage = SENSOR_OFFSET_IIR(sensors.battery_voltage, battery_voltage, sensor_params.bv.offset, sensor_params.bv.iir); /* Calculate global current */ sensors.current = SENSOR_OFFSET_IIR(sensors.current, current, sensor_params.c.offset, sensor_params.c.iir); /* Calculate power stage temperature */ sensors.temp = SENSOR_OFFSET_IIR(sensors.temp, temp, sensor_params.t.offset, sensor_params.t.iir); if (sensor_trigger_debug_output == 10) { sensor_trigger_debug_output = 0; (void)gpc_register_touched(GPROT_ADC_BATTERY_VOLTAGE_REG_ADDR); (void)gpc_register_touched(GPROT_ADC_CURRENT_REG_ADDR); (void)gpc_register_touched(GPROT_ADC_TEMPERATURE_REG_ADDR); } else { sensor_trigger_debug_output++; } }
void interp(char c) { switch(c) { case 's': { TOGGLE(F_SET); break; } case 'p': { TOGGLE(F_PUT); break; } case 'o': { printf("%c", r[curreg]); break; } case 'i': { r[curreg]++; break; } case 'd': { r[curreg]--; break; } case 'l': { TOGGLE(F_LOOPINIT); break; } default: { if(FLAGS & F_SET) { curreg = program[counter] - 48; if(DEBUG) printf("current reg: %i\n", curreg); TOGGLE(F_SET); } if(FLAGS & F_PUT) { char buf[3] = "\0\0\0"; for(int i = 0; i < 3; ++i) { buf[i] = program[counter++]; if(program[counter] == 'p') // counter++; break; } r[curreg] = (uint8_t)atoi(buf); if(DEBUG) printf("reg: %i\n", r[curreg]); TOGGLE(F_PUT); } } } }
void error( void ) { char current,cycle; for (current=0,cycle=0;cycle<14;current=(current+1)%7,cycle++){ TOGGLE(PORTC,current); //toggle led) _delay_ms(100); //short delay } }
bool CodeDetector::DetectAndAdjustMusicOptions( GameController controller ) { const Style* pStyle = GAMESTATE->GetCurrentStyle(); PlayerNumber pn = pStyle->ControllerToPlayerNumber( controller ); for( int c=CODE_MIRROR; c<=CODE_CANCEL_ALL; c++ ) { Code code = (Code)c; PlayerOptions& po = GAMESTATE->m_pPlayerState[pn]->m_PlayerOptions; if( EnteredCode(controller,code) ) { switch( code ) { case CODE_MIRROR: po.ToggleOneTurn( PlayerOptions::TURN_MIRROR ); break; case CODE_LEFT: po.ToggleOneTurn( PlayerOptions::TURN_LEFT ); break; case CODE_RIGHT: po.ToggleOneTurn( PlayerOptions::TURN_RIGHT ); break; case CODE_SHUFFLE: po.ToggleOneTurn( PlayerOptions::TURN_SHUFFLE ); break; case CODE_SUPER_SHUFFLE: po.ToggleOneTurn( PlayerOptions::TURN_SUPER_SHUFFLE ); break; case CODE_NEXT_TRANSFORM: po.NextTransform(); break; case CODE_NEXT_SCROLL_SPEED: INCREMENT_SCROLL_SPEED( po.m_fScrollSpeed ); break; case CODE_PREVIOUS_SCROLL_SPEED: DECREMENT_SCROLL_SPEED( po.m_fScrollSpeed ); break; case CODE_NEXT_ACCEL: po.NextAccel(); break; case CODE_NEXT_EFFECT: po.NextEffect(); break; case CODE_NEXT_APPEARANCE: po.NextAppearance(); break; case CODE_NEXT_TURN: po.NextTurn(); break; case CODE_REVERSE: po.NextScroll(); break; case CODE_HOLDS: TOGGLE( po.m_bTransforms[PlayerOptions::TRANSFORM_NOHOLDS], true, false ); break; case CODE_MINES: TOGGLE( po.m_bTransforms[PlayerOptions::TRANSFORM_NOMINES], true, false ); break; case CODE_DARK: FLOAT_TOGGLE( po.m_fDark ); break; case CODE_CANCEL_ALL: po.Init(); po.FromString( PREFSMAN->m_sDefaultModifiers ); break; case CODE_HIDDEN: TOGGLE_HIDDEN; break; case CODE_RANDOMVANISH: TOGGLE_RANDOMVANISH; break; // po.SetOneAppearance(po.GetFirstAppearance()); break; default: ; } return true; // don't check any more } } return false; }
void tick_alive(void){ static int foo=0; if(GLOBAL(alivechk)==0) return; if(foo++>500/SYSTICKSPEED){ foo=0; TOGGLE(LED2); }; return; }
void usb_lp_can_rx0_irq_handler(void) { static int delay = 100; //ADC_ClearITPendingBit(CAN1, CAN_IT_FMP0); CAN_Receive(CAN1, CAN_FIFO0, &can_rx_msg); if(delay == 0) { delay = 100; TOGGLE(LED_RED); } else { delay--; } TOGGLE(LED_BLUE); #ifdef CAN__USE_EXT_ID //_can_run_rx_callback(can_rx_msg.ExtId, can_rx_msg.Data, can_rx_msg.DLC); #else //_can_run_rx_callback(can_rx_msg.StdId, can_rx_msg.Data, can_rx_msg.DLC); #endif }
/** * One shot callback from the soft Sys Tick timer */ void sys_tick_timer_callback_one_shot(int id) { static int state; if (state == 0) { sys_tick_timer_update(id, 100000); state++; } else { sys_tick_timer_unregister(id); state--; } TOGGLE(LED_RED); }
//# MENU Apack void ppack_menu() { lcdClear(); lcdPrintln("PPack port"); lcdPrintln(""); lcdPrintln("up=enable"); lcdDisplay(); dac_init(false); cpu_clock_set(204); // WARP SPEED! :-) hackrf_clock_init(); rf_path_pin_setup(); /* Configure external clock in */ scu_pinmux(SCU_PINMUX_GP_CLKIN, SCU_CLK_IN | SCU_CONF_FUNCTION1); sgpio_configure_pin_functions(); ON(EN_VDD); ON(EN_1V8); OFF(MIC_AMP_DIS); complex_s8_t * samples; while(1){ switch(getInputRaw()){ case BTN_UP: // ON(MIXER_EN); // hackrf does this cpu_clock_set(204); // WARP SPEED! :-) si5351_init(); portapack_init(); getInputWaitRelease(); break; case BTN_DOWN: lcdPrintln("file"); writeFile("samples.8", (char*)0x20000000,(uintptr_t)s8ram-0x20000000); break; case BTN_LEFT: lcdPrintln("reset"); s8ram=(complex_s8_t*)0x20000000; break; case BTN_RIGHT: break; case BTN_ENTER: return; }; TOGGLE(LED2); delayms(40); lcdPrint(IntToStr((uintptr_t)s8ram,8,F_HEX)); lcdPrint(" "); lcdPrintln(IntToStr(sctr,7,F_LONG)); lcdDisplay(); }; };
/* Toggleview callback. */ static void toggleview_change_cb( GtkWidget *widget, Toggleview *togview ) { Toggle *tog = TOGGLE( VOBJECT( togview )->iobject ); Classmodel *classmodel = CLASSMODEL( tog ); if( tog->value != GTK_TOGGLE_BUTTON( widget )->active ) { tog->value = GTK_TOGGLE_BUTTON( widget )->active; classmodel_update( classmodel ); symbol_recalculate_all(); } }
static void toggleview_refresh( vObject *vobject ) { Toggleview *togview = TOGGLEVIEW( vobject ); Toggle *tog = TOGGLE( VOBJECT( togview )->iobject ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( togview->toggle ), tog->value ); set_glabel( GTK_BIN( togview->toggle )->child, "%s", IOBJECT( tog )->caption ); VOBJECT_CLASS( parent_class )->refresh( vobject ); }
void led_blink_halt(void) { unsigned char i; while(1) { for(i=0; i<100 ;i++) { __asm__ __volatile__ ("wdr"); _delay_ms(5); } TOGGLE(LED_B); } }
void usb_lp_can_rx0_isr(void) { static int delay = 100; can_receive(CAN1, 0, false, &can_rx_msg.id, &can_rx_msg.ide, &can_rx_msg.rtr, &can_rx_msg.fmi, &can_rx_msg.dlc, can_rx_msg.data); can_fifo_release(CAN1, 0); if (can_rx_msg.data[0] & 1) { ON(LED_ORANGE); } else { OFF(LED_ORANGE); } if (can_rx_msg.data[0] & 2) { ON(LED_GREEN); } else { OFF(LED_GREEN); } if(delay == 0) { delay = 100; TOGGLE(LED_RED); }else{ delay--; } TOGGLE(LED_BLUE); //_can_run_rx_callback(can_rx_msg.id, can_rx_msg.data, can_rx_msg.dlc); }
void process_modifier(t_mod *m) { if (ft_strchr("DOCU", m->convers)) { UNSET(m->modif, MOD_ALL); SET(m->modif, MOD_L); m->convers = ft_tolower(m->convers); } if (m->convers == 's' && GET(m->modif, MOD_L)) { TOGGLE(m->modif, MOD_L); m->convers = 'S'; } }
int main(void) { system_init(); led_init(); int flag = 0; /* Enable GPIOB clock */ /*RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); /* Configure PB.09 pin as input floating */ /*GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Enable AFIO clock */ // RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); /* Connect EXTI9 Line to PB.09 pin */ // GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10); /* Configure EXTI9 line */ /* EXTI_InitStructure.EXTI_Line = EXTI_Line10; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); /* Enable and set EXTI9_5 Interrupt to the lowest priority */ /* NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);*/ while(1) { if(!(flag % 100000)) { TOGGLE(LED_RED); //DEBUG("HELLO WORLD\n"); flag++; }else { flag++; } } }
/** * Sys Tick soft timer test main function */ int main(void){ uint32_t timer; mcu_init(); led_init(); sys_tick_init(); (void)sys_tick_timer_register(sys_tick_timer_callback, 1000000); while (true) { timer = sys_tick_get_timer(); while (!sys_tick_check_timer(timer, 50000)) { __asm("nop"); } TOGGLE(LED_GREEN); } }
int can_transmit(uint32_t id, const uint8_t *buf, uint8_t len) { if(len > 8) { return -1; } #ifdef CAN__USE_EXT_ID can_tx_msg.ExtId = id; #else can_tx_msg.StdId = id; #endif can_tx_msg.DLC = len; memcpy(can_tx_msg.Data, buf, len); CAN_Transmit(CAN1, &can_tx_msg); TOGGLE(LED_ORANGE); return 0; }
void led_status() { if (((millis() - previous_millis_led) < LED_UPDATE_INTERVAL)) return; previous_millis_led=millis(); /* // Not sure what this did - AB if (degTargetHotend(active_extruder) > HEATER_0_MINTEMP) { if (((millis() - previous_millis_toggle) < LED_HOTEND_ACTIVE_FLASH)) return; previous_millis_toggle=millis(); TOGGLE(LED_PIN); } else { WRITE(LED_PIN, READ(HEATER_0_PIN)); // Just tell us if the extruder heater is on }*/ if(READ(HEATER_0_PIN)) WRITE(LED_PIN, 1); // Heater on else TOGGLE(LED_PIN); // Heater off }
/** * Timer 2 interrupt handler */ void tim2_isr(void) { if (timer_get_flag(TIM2, TIM_SR_CC1IF)) { timer_clear_flag(TIM2, TIM_SR_CC1IF); /* prepare for next comm */ comm_tim_data.last_capture_time = timer_get_counter(TIM2); //comm_tim_data.last_capture_time = timer_get_ic_value(TIM2, TIM_OC1); //comm_tim_data.last_capture_time = TIM2_CCR1; /* triggering commutation event */ if (comm_tim_trigger_comm || comm_tim_trigger_comm_once) { timer_generate_event(TIM1, TIM_EGR_COMG); //timer_generate_event(TIM1, TIM_EGR_COMG | TIM_EGR_UG); } /* (re)setting "semaphors" */ comm_tim_trigger_comm_once = false; comm_tim_trigger = true; /* Set next comm time */ timer_set_oc_value(TIM2, TIM_OC1, comm_tim_data.last_capture_time + (comm_tim_data.freq * 2)); //timer_set_oc_value(TIM2, TIM_OC1, // comm_tim_data.last_capture_time + // 65535); TOGGLE(DP_EXT_SCL); } if (timer_get_flag(TIM2, TIM_SR_UIF)) { timer_clear_flag(TIM2, TIM_SR_UIF); comm_tim_state.update_count++; } }
void spectrum_callback(uint8_t* buf, int bufLen) { TOGGLE(LED2); if (displayMode == MODE_SPECTRUM) lcdClear(); else if (displayMode == MODE_WATERFALL) lcdShift(0,1,0); for(int i = 0; i < 128; i++) // display 128 FFT magnitude points { // FFT unwrap: uint8_t v; if(i < 64) // negative frequencies v = buf[(bufLen/2)+64+i]; else // positive frequencies v = buf[i-64]; // fill display if (displayMode == MODE_SPECTRUM) { for(int j = 0; j < (v/2); j++) lcdBuffer[i+RESX*(RESY-j)] = 0x00; } else if (displayMode == MODE_WATERFALL) { lcdSetPixel(i,RESY-1,v); } } // text info lcdSetCrsr(0,0); lcdPrint("f="); lcdPrint(IntToStr(freq/1000000,4,F_LONG)); lcdPrintln("MHz "); lcdPrintln("-5MHz 0 +5MHz"); lcdDisplay(); }
/** * Timer 2 interrupt handler */ void tim2_irq_handler(void) { if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_CC1); /* prepare for next comm */ comm_tim_data.last_capture_time = TIM_GetCapture1(TIM2); /* triggering commutation event */ if (comm_tim_trigger_comm || comm_tim_trigger_comm_once) { TIM_GenerateEvent(TIM1, TIM_EventSource_COM); //TIM_GenerateEvent(TIM1, TIM_EventSource_COM | TIM_EventSource_Update); } /* (re)setting "semaphors" */ comm_tim_trigger_comm_once = false; comm_tim_trigger = true; /* Set next comm time */ TIM_SetCompare1(TIM2, comm_tim_data.last_capture_time + (comm_tim_data.freq * 2)); //TIM_SetCompare1(TIM2, // comm_tim_data.last_capture_time + // 65535); TOGGLE(DP_EXT_SCL); } if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM2, TIM_IT_Update); comm_tim_state.update_count++; } }
void next_sign() { TOGGLE(n->type, NEURONSIGN_MASK); }
void main_loop(void* pvParameters) { int loopcount = 0; #define SHOW_DEBUG() 0 //((my_state == RUNNING) && (loopcount == 0)) #define SPI_SCLK 4 #define SPI_MISO 27 #define SPI_MOSI 2 #define SPI_CS GPIO_NUM_16 #define SPI_CE GPIO_NUM_17 int power_left = 0; int power_right = 0; #if 0 int left_x_zero = 512; int left_y_zero = 512; #endif int right_x_zero = 512; int right_y_zero = 512; bool first_reading = true; auto last_packet = xTaskGetTickCount(); const int NOF_BATTERY_READINGS = 100; int32_t battery_readings[NOF_BATTERY_READINGS]; int battery_reading_index = 0; for (int i = 0; i < NOF_BATTERY_READINGS; ++i) battery_readings[i] = 0; int max_power = 255; int count = 0; bool led_state = false; auto last_led_flip = xTaskGetTickCount(); bool is_halted = false; RF24 radio(SPI_CE, SPI_CS); assert(radio_init(radio)); while (1) { ++loopcount; if (loopcount >= 100) loopcount = 0; // if there is data ready if (radio.available()) { last_packet = xTaskGetTickCount(); ForwardAirFrame frame; // Fetch the payload, and see if this was the last one. while (radio.available()) radio.read(&frame, sizeof(frame)); if (frame.magic != ForwardAirFrame::MAGIC_VALUE) { printf("Bad magic value; expected %x, got %x\n", ForwardAirFrame::MAGIC_VALUE, frame.magic); continue; } if (!check_crc(frame)) { printf("Bad CRC\n"); continue; } // Echo back tick value so we can compute round trip time radio.stopListening(); ReturnAirFrame ret_frame; ret_frame.magic = ReturnAirFrame::MAGIC_VALUE; ret_frame.ticks = frame.ticks; #if 0 battery_readings[battery_reading_index] = motor_get_battery(motor_device); ++battery_reading_index; if (battery_reading_index >= NOF_BATTERY_READINGS) battery_reading_index = 0; int n = 0; int32_t sum = 0; for (int i = 0; i < NOF_BATTERY_READINGS; ++i) if (battery_readings[i]) { sum += battery_readings[i]; ++n; } // Round to nearest 0.1 V to prevent flickering ret_frame.battery = n ? 100*((sum/n+50)/100) : 0; #endif set_crc(ret_frame); radio.write(&ret_frame, sizeof(ret_frame)); radio.startListening(); frame.right_x = 1023 - frame.right_x; // hack! #define PUSH(bit) (is_pushed(frame, bit) ? '1' : '0') #define TOGGLE(bit) (is_toggle_down(frame, bit) ? 'D' : (is_toggle_up(frame, bit) ? 'U' : '-')) const int rx = frame.right_x - right_x_zero; const int ry = frame.right_y - right_y_zero; // Map right pot (0-255) to pivot value (20-51) const int pivot = frame.right_pot*2; // Map left pot (0-255) to max_power (20-255) max_power = static_cast<int>(20 + (256-20)/256.0*frame.left_pot); compute_power(rx, ry, power_left, power_right, pivot, max_power); ++count; if (count > 10) { count = 0; printf("max %d\n", max_power); printf("L %4d/%4d R %4d/%4d (%d/%d) P %3d/%3d Push %c%c%c%c" " Toggle %c%c%c%c" " Power %d/%d\n", (int) frame.left_x, (int) frame.left_y, (int) frame.right_x, (int) frame.right_y, rx, ry, int(frame.left_pot), int(frame.right_pot), PUSH(0), PUSH(1), PUSH(2), PUSH(3), TOGGLE(0), TOGGLE(1), TOGGLE(2), TOGGLE(3), power_left, power_right); #if 0 if (is_toggle_up(frame, 3)) signal_control_lights(signal_device, true, true); else if (is_toggle_down(frame, 3)) signal_control_lights(signal_device, true, false); else signal_control_lights(signal_device, false, true); #endif } //!!set_motors(power_left, power_right); is_halted = false; #if 0 if (is_pushed(frame, 0)) signal_play_sound(signal_device, -1); #endif } else { // No data from radio const auto cur_time = xTaskGetTickCount(); if ((cur_time - last_packet > max_radio_idle_time) && !is_halted) { is_halted = true; printf("HALT: Last packet was seen at %d\n", last_packet); first_reading = true; set_motors(0, 0); } } // Change LED state every 3 seconds const auto cur_time = xTaskGetTickCount(); if (cur_time - last_led_flip > 3000/portTICK_PERIOD_MS) { last_led_flip = cur_time; led_state = !led_state; gpio_set_level(GPIO_INTERNAL_LED, led_state); } vTaskDelay(1/portTICK_PERIOD_MS); //xTaskNotifyWait(0, 0, NULL, 1); } }
/* Set up the system variables for a search or replace. If use_answer * is TRUE, only set backupstring to answer. Return -2 to run the * opposite program (search -> replace, replace -> search), return -1 if * the search should be canceled (due to Cancel, a blank search string, * Go to Line, or a failed regcomp()), return 0 on success, and return 1 * on rerun calling program. * * replacing is TRUE if we call from do_replace(), and FALSE if called * from do_search(). */ int search_init(bool replacing, bool use_answer) { int i = 0; char *buf; static char *backupstring = NULL; /* The search string we'll be using. */ /* If backupstring doesn't exist, initialize it to "". */ if (backupstring == NULL) backupstring = mallocstrcpy(NULL, ""); /* If use_answer is TRUE, set backupstring to answer and get out. */ if (use_answer) { backupstring = mallocstrcpy(backupstring, answer); return 0; } /* We display the search prompt below. If the user types a partial * search string and then Replace or a toggle, we will return to * do_search() or do_replace() and be called again. In that case, * we should put the same search string back up. */ focusing = TRUE; if (last_search[0] != '\0') { char *disp = display_string(last_search, 0, COLS / 3, FALSE); buf = charalloc(strlen(disp) + 7); /* We use (COLS / 3) here because we need to see more on the line. */ sprintf(buf, " [%s%s]", disp, (strlenpt(last_search) > COLS / 3) ? "..." : ""); free(disp); } else buf = mallocstrcpy(NULL, ""); /* This is now one simple call. It just does a lot. */ i = do_prompt(FALSE, #ifndef DISABLE_TABCOMP TRUE, #endif replacing ? MREPLACE : MWHEREIS, backupstring, #ifndef DISABLE_HISTORIES &search_history, #endif /* TRANSLATORS: This is the main search prompt. */ edit_refresh, "%s%s%s%s%s%s", _("Search"), #ifndef NANO_TINY /* TRANSLATORS: The next three strings are modifiers of the search prompt. */ ISSET(CASE_SENSITIVE) ? _(" [Case Sensitive]") : #endif "", #ifdef HAVE_REGEX_H ISSET(USE_REGEXP) ? _(" [Regexp]") : #endif "", #ifndef NANO_TINY ISSET(BACKWARDS_SEARCH) ? _(" [Backwards]") : #endif "", replacing ? #ifndef NANO_TINY /* TRANSLATORS: The next two strings are modifiers of the search prompt. */ openfile->mark_set ? _(" (to replace) in selection") : #endif _(" (to replace)") : "", buf); fflush(stderr); /* Release buf now that we don't need it anymore. */ free(buf); free(backupstring); backupstring = NULL; /* Cancel any search, or just return with no previous search. */ if (i == -1 || (i < 0 && *last_search == '\0') || (!replacing && i == 0 && *answer == '\0')) { statusbar(_("Cancelled")); return -1; } else { functionptrtype func = func_from_key(&i); if (i == -2 || i == 0 ) { #ifdef HAVE_REGEX_H /* Use last_search if answer is an empty string, or * answer if it isn't. */ if (ISSET(USE_REGEXP) && !regexp_init((i == -2) ? last_search : answer)) return -1; #endif ; #ifndef NANO_TINY } else if (func == case_sens_void) { TOGGLE(CASE_SENSITIVE); backupstring = mallocstrcpy(backupstring, answer); return 1; } else if (func == backwards_void) { TOGGLE(BACKWARDS_SEARCH); backupstring = mallocstrcpy(backupstring, answer); return 1; #endif #ifdef HAVE_REGEX_H } else if (func == regexp_void) { TOGGLE(USE_REGEXP); backupstring = mallocstrcpy(backupstring, answer); return 1; #endif } else if (func == do_replace || func == flip_replace_void) { backupstring = mallocstrcpy(backupstring, answer); return -2; /* Call the opposite search function. */ } else if (func == do_gotolinecolumn_void) { do_gotolinecolumn(openfile->current->lineno, openfile->placewewant + 1, TRUE, TRUE); /* Put answer up on the statusbar and * fall through. */ return 3; } else { return -1; } } return 0; }
void exti0_irq_handler(void) { TOGGLE(LED_BLUE); EXTI_ClearITPendingBit(EXTI_Line0); }
void sys_tick_handler(void) { incTimer(); static int ctr=0; if (++ctr%50==1) TOGGLE(LED2); };
void do_clan (CHAR_DATA *ch, char *argument, int cmd) { int zone; int leader_obj_vnum; int member_obj_vnum; int new_flags; int clan_flags; int num_clans = 0; int i; NAME_SWITCH_DATA *name_switch; NAME_SWITCH_DATA *nsp; OBJ_DATA *obj; CLAN_DATA *clan; CLAN_DATA *delete_clan; CHAR_DATA *edit_mob = NULL; CHAR_DATA *tch; char *p; char buf [MAX_STRING_LENGTH] = {'\0'}; char clan_name [MAX_STRING_LENGTH] = {'\0'}; char oldname [MAX_STRING_LENGTH] = {'\0'}; char newname [MAX_STRING_LENGTH] = {'\0'}; char literal [MAX_STRING_LENGTH] = {'\0'}; char name [MAX_STRING_LENGTH] = {'\0'}; char *the_clans [MAX_CLANS] = {'\0'}; if ( IS_NPC (ch) ) { send_to_char ("Sorry, but you can't do this while switched...\n", ch); return; } if ( !*argument ) { send_to_char ("Old clan name -> New clan name\n", ch); send_to_char ("============= =============\n", ch); if ( !clan_name_switch_list ) send_to_char ("No clans set to be renamed.\n", ch); else { for ( nsp = clan_name_switch_list; nsp; nsp = nsp->next ) { snprintf (buf, MAX_STRING_LENGTH, "%-15s %-15s\n", nsp->old_name, nsp->new_name); send_to_char (buf, ch); } } send_to_char ("\nClan Name Full Clan Name\n", ch); send_to_char ("=============== =================================\n", ch); for ( clan = clan_list; clan; clan = clan->next ) { snprintf (buf, MAX_STRING_LENGTH, "%-15s %s\n", clan->name, clan->literal); send_to_char (buf, ch); if ( clan->zone ) { snprintf (buf, MAX_STRING_LENGTH, " Enforcement Zone %d\n", clan->zone); send_to_char (buf, ch); } if ( clan->member_vnum ) { obj = vtoo (clan->member_vnum); snprintf (buf, MAX_STRING_LENGTH, " Member Object (%05d): %s\n", clan->member_vnum, obj ? obj->short_description : "UNDEFINED"); send_to_char (buf, ch); } if ( clan->leader_vnum ) { obj = vtoo (clan->leader_vnum); snprintf (buf, MAX_STRING_LENGTH, " Leader Object (%05d): %s\n", clan->leader_vnum, obj ? obj->short_description : "UNDEFINED"); send_to_char (buf, ch); } } return; } argument = one_argument (argument, buf); if ( !*buf || *buf == '?' ) { send_to_char ("Syntax for modifying PCs:\n\n", ch); send_to_char (" clan set <clan-name> [<clan-flags>]\n", ch); send_to_char (" clan remove <clan-name> (or all)\n", ch); send_to_char ("\nSyntax for modifying clan definitions:\n", ch); send_to_char (" clan rename <oldclanname> <newclanname>\n", ch); send_to_char (" clan unrename <oldclanname> <newclanname>\n", ch); send_to_char (" clan register <name> <enforcement zone> <long name> " "[<leader obj>] [<member obj>]\n", ch); send_to_char (" clan unregister <name>\n", ch); send_to_char (" clan list\n", ch); send_to_char ("\nThe obj vnums are optional. Specify zone 0 if no " "enforcement zone.\n\nExamples:\n", ch); send_to_char (" > clan set tashalwatch member leader\n", ch); send_to_char (" > clan remove tashalwatch\n", ch); send_to_char (" > clan register TashalWatch 10 'Tashal Watch'\n", ch); send_to_char (" > clan unregister tashalwatch\n", ch); send_to_char (" > clan rename 10 TashalWatch\n", ch); send_to_char (" > clan unrename 10 TashalWatch\n", ch); send_to_char (" > clan list\n", ch); return; } if ( !str_cmp (buf, "list") ) { for ( tch = character_list; tch; tch = tch->next ) { if ( tch->deleted ) continue; p = tch->clans; if ( !p || !*p ) continue; while ( get_next_clan (&p, clan_name, &clan_flags) ) { if ( num_clans > MAX_CLANS ) /* Too many in list */ break; for ( i = 0; i < num_clans; i++ ) if ( !str_cmp (clan_name, the_clans [i]) ) break; if ( i >= num_clans ) the_clans [num_clans++] = str_dup (clan_name); } } *b_buf = '\0'; for ( i = 0; i < num_clans; i++ ) { snprintf (b_buf + strlen(b_buf), MAX_STRING_LENGTH, "%-15s", the_clans [i]); if ( i % 5 == 4 ) strcat (b_buf, "\n"); else strcat (b_buf, " "); } page_string (ch->desc, b_buf); return; } if ( !str_cmp (buf, "set") || !str_cmp (buf, "remove") || !str_cmp (buf, "delete") ) { if ( (!ch->pc->edit_mob && !ch->pc->edit_player) || (!(edit_mob = vtom (ch->pc->edit_mob)) && !(edit_mob = ch->pc->edit_player)) ) { send_to_char ("Start by using the MOBILE command.\n", ch); return; } } if ( !str_cmp (buf, "set") ) { argument = one_argument (argument, clan_name); if ( !*clan_name ) { send_to_char ("Expected a clan name after 'add'.\n", ch); return; } new_flags = clan_flags_to_value (argument); if ( get_clan (edit_mob, clan_name, &clan_flags) ) remove_clan (edit_mob, clan_name); clan_flags = 0; while ( 1 ) { argument = one_argument (argument, buf); if ( !*buf ) break; if ( !str_cmp (buf, "member") ) TOGGLE (clan_flags, CLAN_MEMBER) /* {}'s define */ else if ( !str_cmp (buf, "leader") ) /* so no ; needed */ TOGGLE (clan_flags, CLAN_LEADER) else if ( !str_cmp (buf, "recruit") ) TOGGLE (clan_flags, CLAN_RECRUIT) else if ( !str_cmp (buf, "private") ) TOGGLE (clan_flags, CLAN_PRIVATE) else if ( !str_cmp (buf, "corporal") ) TOGGLE (clan_flags, CLAN_CORPORAL) else if ( !str_cmp (buf, "sergeant") ) TOGGLE (clan_flags, CLAN_SERGEANT) else if ( !str_cmp (buf, "lieutenant") ) TOGGLE (clan_flags, CLAN_LIEUTENANT) else if ( !str_cmp (buf, "captain") ) TOGGLE (clan_flags, CLAN_CAPTAIN) else if ( !str_cmp (buf, "general") ) TOGGLE (clan_flags, CLAN_GENERAL) else if ( !str_cmp (buf, "commander") ) TOGGLE (clan_flags, CLAN_COMMANDER) else if ( !str_cmp (buf, "apprentice") ) TOGGLE (clan_flags, CLAN_APPRENTICE) else if ( !str_cmp (buf, "journeyman") ) TOGGLE (clan_flags, CLAN_JOURNEYMAN) else if ( !str_cmp (buf, "master") ) TOGGLE (clan_flags, CLAN_MASTER) else { snprintf (literal, MAX_STRING_LENGTH, "Flag %s is unknown for clans.\n", buf); send_to_char (literal, ch); } } if ( !clan_flags ) clan_flags = CLAN_MEMBER; add_clan (edit_mob, clan_name, clan_flags); if ( edit_mob->mob ) { snprintf (buf, MAX_STRING_LENGTH, "%d mobile(s) in world redefined.\n", redefine_mobiles (edit_mob)); send_to_char (buf, ch); } return; /* Return from n/pc specific uses of clan */ }