int main(void) { int key; adc_setup(); draw_text(); char temp[5]; while (1) { for (i = 0; i < 4; i++) { if (adc_isdone(adcchannels[i]) == 1) adc_sample(adcchannels[i], 128); tsample = adc_getsample(adcchannels[i]); if (! tsample == 0) { sprintf(temp, "%d", adcchannels[i]); term_puts(1, i + 4, temp); sprintf(temp, "%d", adcsmoothing[i]); term_puts(5, i + 4, temp); sprintf(temp, "%d", tsample); term_puts(11, i + 4, temp); } } key = term_getchar(NOWAIT); if (key != -1) { if (handle_kbd((int)key)) break; } } term_clrscr(); term_moveto(1, 1); return 0; }
/* the magic starts here */ int main(void) { char msg[20]; int key; int index, enabled = 1, i, j; if (strcmp("EK-LM3S8962", pd_board()) != 0 || strcmp("EK-LM3S6965", pd_board() != 0)) { printf("%s is not supported with this example\n"); return -1; } get_started(); while (1) { term_clrscr(); term_moveto(1, 1); printf("Welcome to picoc Morse Playing on %s", pd_board()); printf("\nEnter phrase (empty phrase to exit): "); gets(msg); if (strlen(msg) == 0) break; while (term_getchar(0) != -1); while (enabled) { for (i = 0; msg[i]; i++) { index = morse_index(msg[i]); printf ("%c", msg[i]); printf (": "); if (msg[i] != ' ') { for (j = 0; morse[index][j]; j++) { printf ("%c", morse[index][j]); play(morse[index][j]); } printf ("\n"); } else { play(' '); play(' '); } play(' '); key = term_getchar(0); if (key != -1) { if (handle_kbd((int)key)) { enabled = 0; exit(1); } } } if (!enabled) break; printf("\n\n"); play(' '); play(' '); play(' '); } } return 0; }
/*** Handle events coming from main window: ***/ void dispatch_events() { extern ULONG sigmainwnd, swinsig; extern UBYTE record; BYTE scrolldisp=0, state=0, cnt=0, mark=0, quit = 0; while( quit == 0 ) { /* Active collect, when pressing arrow gadgets */ sigrcvd = (state==0 ? Wait(sigbits) : sigmainwnd); /* if(sigrcvd & SIGBREAKF_CTRL_C) break; else */ if(sigrcvd & sigport) { handle_port(); continue; } else if(sigrcvd & swinsig) { handle_search(); continue; } /* Collect messages posted to the window port */ while( ( msg = (struct IntuiMessage *) GetMsg(Wnd->UserPort) ) ) { /* Copy the entire message into the buffer */ CopyMemQuick(msg, &msgbuf, sizeof(msgbuf)); ReplyMsg( (struct Message *) msg ); switch( msgbuf.Class ) { case IDCMP_CLOSEWINDOW: handle_menu(112); break; case IDCMP_RAWKEY: handle_kbd(edit); if(record) { if(record == 1) reg_act_com(MAC_ACT_SHORTCUT, msgbuf.Code, msgbuf.Qualifier); else record &= 0x7f; } break; case IDCMP_INTUITICKS: /* An error message which needs to be removed? */ if(err_time == 0) err_time = msgbuf.Seconds; if(err_time && msgbuf.Seconds-err_time>4) StopError(Wnd); break; case IDCMP_MOUSEBUTTONS: /* Click somewhere in the text */ switch( msgbuf.Code ) { case SELECTDOWN: /* Click over the project bar ? */ if(msgbuf.MouseY < gui.top) { edit = select_panel(edit, msgbuf.MouseX); break; } click(edit, msgbuf.MouseX, msgbuf.MouseY, FALSE); /* Shift-click to use columnar selection */ if( ( move_selection = SwitchSelect(edit, msgbuf.Qualifier & SHIFTKEYS ? 1:0, 1) ) ) mark=TRUE; break; case SELECTUP: if(mark) unclick(edit); mark=FALSE; scrolldisp=0; break; } break; case IDCMP_NEWSIZE: new_size(EDIT_ALL); break; case IDCMP_GADGETDOWN: /* Left scroll bar */ if(msgbuf.IAddress == (APTR) &Prop->down) state=1; if(msgbuf.IAddress == (APTR) &Prop->up) state=2; break; case IDCMP_GADGETUP: /* Arrows or prop gadget */ state=0; if(msgbuf.IAddress == (APTR) Prop) scroll_disp(edit, FALSE), scrolldisp=0; break; case IDCMP_MOUSEMOVE: if(mark) scrolldisp=2; else if(Prop->scroller.Flags & GFLG_SELECTED) scrolldisp=1; break; case IDCMP_MENUPICK: { struct MenuItem * Item; ULONG MenuId; /* Multi-selection of menu entries */ while(msgbuf.Code != MENUNULL) if( (Item = ItemAddress( Menu, msgbuf.Code )) ) { /* stegerg: get NextSelect here in case menu action causes screen to be closed/reopened in which case item becomes invalid. Also assuming here that user in such case will not use multiselection, ie. that nextselect will be MENUNULL. If that's not the case it would mean more trouble and to protect against that one would need to check if during handle_menu() the screen has been closed/reopened and in that case break out of the menu multiselection loop here. */ UWORD nextselect = Item->NextSelect; MenuId = (ULONG)GTMENUITEM_USERDATA( Item ); handle_menu( MenuId ); if(record) reg_act_com(MAC_ACT_COM_MENU, MenuId, msgbuf.Qualifier); else record &= 0x7f; msgbuf.Code = nextselect; } } } } /* Reduces the number of IDCMP mousemove messages to process */ if(scrolldisp==1) scroll_disp(edit, FALSE), scrolldisp=0; if(scrolldisp==2) { scrolldisp=0; goto moveit; } /* User may want to auto-scroll the display using arrow gadgets */ if(state && (mark || (((struct Gadget *)Prop)[state].Flags & GFLG_SELECTED))) { /* Slow down animation: */ WaitTOF(); cnt++; if(cnt>1) { cnt=0; if(autoscroll(edit,state==1 ? 1:-1)==0) state=0; else if(mark) { LONG x , y; moveit: /* Adjust mouse position */ x = (msgbuf.MouseX-gui.left) / XSIZE; y = (msgbuf.MouseY-gui.top) / YSIZE; if(x < 0) x = 0; if(x >= gui.nbcol) x = gui.nbcol-1; if(y < 0) y = -1; if(y > gui.nbline) y = gui.nbline; edit->nbrwc = (x += edit->left_pos); y += (LONG)edit->top_line; if( x != edit->ccp.xc || y != edit->ccp.yc ) /* Move the selected stream */ if( !(state = move_selection(edit,x,y)) ) set_cursor_line(edit, y, edit->top_line), inv_curs(edit,TRUE); } } } /* endif: arrow gadget pressed or autoscroll */ } }
/*********************************************************************************** Переривання від System peripherals ***********************************************************************************/ void Sys_IrqHandler(void) { if (AT91C_BASE_PITC->PITC_PISR & AT91C_PITC_PITS) { AT91C_BASE_PITC->PITC_PIVR; //Робота з клавіатурою handle_kbd(); unsigned int threshold_timeout_LCD = ((unsigned int)eeprom_bs_settings_tbl.chSleepTmVal)*60*100; if (hldScanCode.UNFKeyField.arUl[0] || hldScanCode.UNFKeyField.arUl[1]) { timeout_LCD = 0; } else { if (timeout_LCD < threshold_timeout_LCD) timeout_LCD++; } if ((state_command_power_LCD & ((unsigned int)(1 << 31))) == 0) { //LCD vymknutyj if (timeout_LCD == 0) state_command_power_LCD |= (1 << 0); //Komanda na vvimknennja LCD } else { //LCD vimknutyj if ( (timeout_LCD >= threshold_timeout_LCD) && (timeout_LCD > 0) ) { state_command_power_LCD |= (1 << 1); //Komanda na vymknennja LCD } } /***********************************************************/ //Лічильник ресурсу + періодичні операції раз у секунду /***********************************************************/ static unsigned int number_ticks_for_OF_bit_reset; if (etap_reset_of_bit == ETAP_CLEAR_OF_ST_START_WAITING_5S) { etap_reset_of_bit = ETAP_CLEAR_OF_ST_WAITING_5S; number_ticks_for_OF_bit_reset = 0; } else if (etap_reset_of_bit == ETAP_CLEAR_OF_ST_WAITING_5S) { number_ticks_for_OF_bit_reset++; if (number_ticks_for_OF_bit_reset > 500) etap_reset_of_bit = ETAP_CLEAR_OF_WRITE_OF_0; } if (++tick_for_1s >= 100) { //Запусаємо раз у секунду самоконтроль важливих змінних periodical_tasks_TEST_SETTINGS_PRT = periodical_tasks_TEST_SETTINGS_BS = periodical_tasks_TEST_USTUVANNJA = periodical_tasks_TEST_TRG_FUNC = periodical_tasks_TEST_INFO_REJESTRATOR_AR = periodical_tasks_TEST_INFO_REJESTRATOR_DR = periodical_tasks_TEST_INFO_REJESTRATOR_PR_ERR = true; /*Зафікосваний період в 1(с) = 100 х 10(мс)*/ tick_for_1s = 0; //Vystavljaemo praporec pro peremaljovuvannja paneli statusu redraw_status_bar = 1; //Komanda chytannja danykh z RTC _SET_BIT(control_spi1_taskes, TASK_START_READ_RTC_BIT); //Ресурс resurs_global = resurs_temp; resurs_temp = 0; if (restart_resurs_count != 0) { restart_resurs_count = 0; resurs_global_min = 0xffffffff; resurs_global_max = 0; } if (resurs_global < resurs_global_min) resurs_global_min = resurs_global; if (resurs_global > resurs_global_max) resurs_global_max = resurs_global; if ( ((Clock_FrameWin != WM_UNATTACHED) && (current_ekran.edition == 0)) || (TM_FrameWin != WM_UNATTACHED) || (Diagnostics_FrameWin != WM_UNATTACHED) || (Resurs_FrameWin != WM_UNATTACHED) ) { command_menu |= (1 << REFRESH_ACTIVE_PANELS); } //Вызов ф-ции обновления значений на панэли измерений if (!gui_update && ((state_command_power_LCD & ( (unsigned int) ((1 << 31) | (1 << 1)) )) == (unsigned int) (1 << 31) ) ) { gui_tmr_routines(); } } if (++tick_for_2s >= 200) { /*Зафікосваний період в 2(с) = 200 х 10(мс)*/ tick_for_2s = 0; } if (++tick_for_3s >= 300) { /*Зафікосваний період в 3(с) = 300 х 10(мс)*/ tick_for_3s = 0; } Ici10msRing(); //Зафіксовано період в 10мс period_10ms = true; } }