// filename serial.c // slave file used to respond to poll from master // update percentage number in the bottom of the screen // draw random lines to screen everytime it receives a packet from the master // clear screen every 100th packet receive // by Sonny Cruz 2/24/03 // // program flow // loop #include #include #define MY_APP (MSG_USER + 1) #define CYBIKO_MASTER 0x0004A1E8 // global variables char buffer[8]; char str[30]; struct module_t mainModule; char dummy = 0; int counter = 0; struct cProgressBar cPB; void drawLine() { int startX, startY, endX, endY; color_t color; // get start position startX = (int) random(SCREEN_WIDTH); startY = (int) random(SCREEN_HEIGHT); // get end position endX = (int) random(SCREEN_WIDTH); endY = (int) random(SCREEN_HEIGHT); // get color color = (color_t) random(4); switch (color) { case 0 : color = CLR_WHITE; break; case 1 : color = CLR_LTGRAY; break; case 2 : color = CLR_DKGRAY; break; case 3 : color = CLR_BLACK; break; } // draw the line DisplayGraphics_set_color(mainModule.m_gfx, color); DisplayGraphics_draw_line(mainModule.m_gfx, startX, startY, endX, endY); DisplayGraphics_show(mainModule.m_gfx); } // start of main long main(int argc, char* argv[], bool start) { struct Message* ptrMessage; dummy = 0; init_module(&mainModule); // construct a progress bar cProgressBar_ctor(&cPB, 30, 0, 100, cool_normal_font, CLR_WHITE, CLR_BLACK, 20); // add progress bar to screen cWinApp_AddObj(mainModule.m_process, &cPB, (SCREEN_WIDTH/2)-15, SCREEN_HEIGHT-20); // set up font DisplayGraphics_set_font(mainModule.m_gfx, mini_normal_font); cWinApp_clear_screen(); while (TRUE) { ptrMessage = cWinApp_get_message(mainModule.m_process, 0, 1, MY_APP); if (ptrMessage) { switch(ptrMessage->msgid) { case MY_APP : Buffer_load(Message_get_buffer(ptrMessage), buffer, 0, 8); dummy++; buffer[3] = dummy; if (counter++ > 100){ counter = 0; cWinApp_clear_screen(); } cProgressBar_SetCurrentPos(&cPB, counter); drawLine(); send_remote_msg(CYBIKO_MASTER, "serial", MY_APP, 0L, 0L, buffer, 8); break; default : cWinApp_defproc(mainModule.m_process, ptrMessage); } // delete message after processing Message_delete(ptrMessage); } } cProgressBar_dtor(&cPB, LEAVE_MEMORY); return 0L; }