void volume(bool direction){ if(direction == UP){ push_button(MP3_T4); _delay_ms(PUSH_DURATION); release_button(MP3_T4); } else { push_button(MP3_T3); _delay_ms(PUSH_DURATION); release_button(MP3_T3); } _delay_ms(PUSH_DURATION);//Pause vor nächstem Tastendruck erzwingen }
void stove::Run(void) { int i,flag=0; char *str=new char[100]; char *str1=new char[100]; while (flag!=1) { while (!kbhit() && time>0) { time--; Sleep(100); sprintf(str1,"Осталось %d секунд",time); CharToOem(str1,str); printf("%s\n",str); } if (time==0) { strcpy(str,ready()); printf("%s\n",str); } if (time==-1) menu(); i=getch(); switch (i) { case 'b': strcpy(str,push_button()); break; case 'd': strcpy(str,take_door()); break; case 27: flag=1; break; } fflush(stdin); if (i=='b' || i=='d') printf("%s\n",str); } return; }
void Calculator::key_enter() { if (selected_button_idx == DEFAULT_SELECTED_BUTTON_IDX) { // execute buffered equation std::string expression_string = joinStrVec(buffered_equation) + joinStrVec(buffered_partial_op_string); double res = calculate<double>(expression_string); main_display->setResult(std::to_string(res)); main_display->redisplay(); } else { btn_t bt = buttons[selected_button_idx]->getAttribute().bt; unselect_button(); push_button(bt); } resize(); };
/** * Main apply handler. * * Checks for unpaid items before applying. * @param op ::object causing tmp to be applied. * @param tmp ::object being applied. * @param aflag Special (always apply/unapply) flags. Nothing is done * with them in this function - they are passed to apply_special(). * @retval 0 Player or monster can't apply objects of that type. * @retval 1 Has been applied, or there was an error applying the object. * @retval 2 Objects of that type can't be applied if not in * inventory. */ int manual_apply(object *op, object *tmp, int aflag) { if (tmp->head) { tmp = tmp->head; } if (op->type == PLAYER) { CONTR(op)->praying = 0; } if (QUERY_FLAG(tmp, FLAG_UNPAID) && !QUERY_FLAG(tmp, FLAG_APPLIED)) { if (op->type == PLAYER) { new_draw_info(NDI_UNIQUE, op, "You should pay for it first."); return 1; } /* Monsters just skip unpaid items */ else { return 0; } } /* Monsters must not apply random chests, nor magic_mouths with a counter */ if (op->type != PLAYER && tmp->type == TREASURE) { return 0; } /* Trigger the APPLY event */ if (!(aflag & AP_NO_EVENT) && trigger_event(EVENT_APPLY, op, tmp, NULL, NULL, aflag, 0, 0, SCRIPT_FIX_ACTIVATOR)) { return 1; } aflag &= ~AP_NO_EVENT; /* Control apply by controling a set exp object level or player exp level */ if (tmp->item_level) { int tmp_lev; if (tmp->item_skill) { tmp_lev = find_skill_exp_level(op, tmp->item_skill); } else { tmp_lev = op->level; } if (tmp->item_level > tmp_lev) { new_draw_info(NDI_UNIQUE, op, "The item level is too high to apply."); return 1; } } switch (tmp->type) { case HOLY_ALTAR: new_draw_info_format(NDI_UNIQUE, op, "You touch the %s.", tmp->name); if (change_skill(op, SK_PRAYING)) { pray_at_altar(op, tmp); } else { new_draw_info(NDI_UNIQUE, op, "Nothing happens. It seems you miss the right skill."); } return 1; break; case HANDLE: new_draw_info(NDI_UNIQUE, op, "You turn the handle."); play_sound_map(op->map, op->x, op->y, SOUND_TURN_HANDLE, SOUND_NORMAL); tmp->value = tmp->value ? 0 : 1; SET_ANIMATION(tmp, ((NUM_ANIMATIONS(tmp) / NUM_FACINGS(tmp)) * tmp->direction) + tmp->value); update_object(tmp, UP_OBJ_FACE); push_button(tmp); return 1; case TRIGGER: if (check_trigger(tmp, op)) { new_draw_info(NDI_UNIQUE, op, "You turn the handle."); play_sound_map(tmp->map, tmp->x, tmp->y, SOUND_TURN_HANDLE, SOUND_NORMAL); } else { new_draw_info(NDI_UNIQUE, op, "The handle doesn't move."); } return 1; case EXIT: if (op->type != PLAYER || !tmp->map) { return 0; } /* If no map path specified, we assume it is the map path of the exit. */ if (!EXIT_PATH(tmp)) { FREE_AND_ADD_REF_HASH(EXIT_PATH(tmp), tmp->map->path); } if (!EXIT_PATH(tmp) || !is_legal_2ways_exit(op, tmp) || (EXIT_Y(tmp) == -1 && EXIT_X(tmp) == -1)) { new_draw_info_format(NDI_UNIQUE, op, "The %s is closed.", query_name(tmp, NULL)); } else { /* Don't display messages for random maps. */ if (tmp->msg && strncmp(EXIT_PATH(tmp), "/!", 2) && strncmp(EXIT_PATH(tmp), "/random/", 8)) { new_draw_info(NDI_NAVY, op, tmp->msg); } enter_exit(op, tmp); } return 1; case SIGN: apply_sign(op, tmp); return 1; case BOOK: if (op->type == PLAYER) { apply_book(op, tmp); return 1; } return 0; case SKILLSCROLL: if (op->type == PLAYER) { apply_skillscroll(op, tmp); return 1; } return 0; case SPELLBOOK: if (op->type == PLAYER) { apply_spellbook(op, tmp); return 1; } return 0; case SCROLL: apply_scroll(op, tmp); return 1; case POTION: (void) apply_potion(op, tmp); return 1; case LIGHT_APPLY: apply_player_light(op, tmp); return 1; case LIGHT_REFILL: apply_player_light_refill(op, tmp); return 1; /* Eneq(@csd.uu.se): Handle apply on containers. */ case CLOSE_CON: if (op->type == PLAYER) { (void) esrv_apply_container(op, tmp->env); } return 1; case CONTAINER: if (op->type == PLAYER) { (void) esrv_apply_container(op, tmp); } return 1; case TREASURE: apply_treasure(op, tmp); return 1; case WEAPON: case ARMOUR: case BOOTS: case GLOVES: case AMULET: case GIRDLE: case BRACERS: case SHIELD: case HELMET: case RING: case CLOAK: case WAND: case ROD: case HORN: case SKILL: case BOW: case SKILL_ITEM: /* Not in inventory */ if (tmp->env != op) { return 2; } (void) apply_special(op, tmp, aflag); return 1; case DRINK: case FOOD: case FLESH: apply_food(op, tmp); return 1; case POISON: apply_poison(op, tmp); return 1; case SAVEBED: if (op->type == PLAYER) { apply_savebed(op); return 1; } return 0; case ARMOUR_IMPROVER: if (op->type == PLAYER) { apply_armour_improver(op, tmp); return 1; } return 0; case WEAPON_IMPROVER: apply_weapon_improver(op, tmp); return 1; case CLOCK: if (op->type == PLAYER) { timeofday_t tod; get_tod(&tod); new_draw_info_format(NDI_UNIQUE, op, "It is %d minute%s past %d o'clock %s", tod.minute + 1, ((tod.minute + 1 < 2) ? "" : "s"), ((tod.hour % (HOURS_PER_DAY / 2) == 0) ? (HOURS_PER_DAY / 2) : ((tod.hour) % (HOURS_PER_DAY / 2))), ((tod.hour >= (HOURS_PER_DAY / 2)) ? "pm" : "am")); return 1; } return 0; case POWER_CRYSTAL: apply_power_crystal(op, tmp); return 1; /* For lighting torches/lanterns/etc */ case LIGHTER: if (op->type == PLAYER) { apply_lighter(op, tmp); return 1; } return 0; /* So the below default case doesn't execute for these objects, * even if they have message. */ case DOOR: return 0; /* Nothing from the above... but show a message if it has one. */ default: if (tmp->msg) { new_draw_info(NDI_UNIQUE, op, tmp->msg); return 1; } return 0; } }
// TODO: refine void Calculator::exec(int key) { btn_t bt{btn_t::num_btn_types}; switch (key) { case KEY_BACKSPACE: case KEY_DC: bt = btn_t::btn_bck; push_button(bt); return; } std::string alpha = std::string(1, static_cast<char>(key)); if (getPartialOpString().size() > 0) { std::string pending = getPartialOpString(); try { std::regex e("^" + pending + alpha); pushBackPartialOpString(alpha); main_display->pushBackPartialOpString(alpha); pending += alpha; int match_count{0}; std::string candidate_label; btn_t candidate_bt; for (auto it = buttons.begin(); it != buttons.end(); it++) { std::smatch m; candidate_label = (*it)->getAttribute().label; if (std::regex_search(candidate_label, m, e)) { ++match_count; candidate_bt = (*it)->getAttribute().bt; } } if (match_count == 1 && candidate_label == pending) { clearPartialOpString(); main_display->clearPartialOpString(); push_button(candidate_bt); } return; } catch (const std::regex_error& err) { bool match_exists{false}; auto it = buttons.begin(); for (; it != buttons.end(); it++) { if (pending == (*it)->getAttribute().label) { match_exists = true; break; } } if (match_exists) { clearPartialOpString(); main_display->clearPartialOpString(); push_button((*it)->getAttribute().bt); } else { pushBackPartialOpString(alpha); main_display->pushBackPartialOpString(alpha); return; } }; } switch (key) { case '/': bt = btn_t::btn_div; break; case '*': bt = btn_t::btn_multi; break; case '-': bt = btn_t::btn_minus; break; case '+': bt = btn_t::btn_plus; break; case '9': bt = btn_t::btn_9; break; case '8': bt = btn_t::btn_8; break; case '7': bt = btn_t::btn_7; break; case '6': bt = btn_t::btn_6; break; case '5': bt = btn_t::btn_5; break; case '4': bt = btn_t::btn_4; break; case '3': bt = btn_t::btn_3; break; case '2': bt = btn_t::btn_2; break; case '1': bt = btn_t::btn_1; break; case '0': bt = btn_t::btn_0; break; case '(': bt = btn_t::btn_paren_open; break; case ')': bt = btn_t::btn_paren_close; break; case '{': bt = btn_t::btn_curl_open; break; case '}': bt = btn_t::btn_curl_close; break; case '[': bt = btn_t::btn_bracket_open; break; case ']': bt = btn_t::btn_bracket_close; break; case 'r': resize(); return; /* hidden command... */ case '?': showKeyHelp(); return; } if (bt != btn_t::num_btn_types) { push_button(bt); } else { pushBackPartialOpString(alpha); main_display->pushBackPartialOpString(alpha); } };
void play_pause(){ push_button(MP3_ONOFF); _delay_ms(PUSH_DURATION); release_button(MP3_ONOFF); _delay_ms(PUSH_DURATION);//Pause vor nächstem Tastendruck erzwingen }
void next_song(){ push_button(MP3_T1); _delay_ms(PUSH_DURATION); release_button(MP3_T1); _delay_ms(PUSH_DURATION);//Pause vor nächstem Tastendruck erzwingen }
void mp3Player_onoff(){ push_button(MP3_ONOFF); _delay_ms(PUSH_DURATION_LONG); release_button(MP3_ONOFF); _delay_ms(PUSH_DURATION_LONG+3000);//Pause vor nächstem Tastendruck erzwingen }
void mute_off(){ push_button(AMP_MUTE); }
void amp_on(){ push_button(AMP_STBY); _delay_ms(200); }