This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

rtos2

..continued..


/******************************************************************************/
/*        Task 2 'clock'                                                      */
/******************************************************************************/
void clock (void)  _task_ CLOCK  {
  while (1)  {                        /* clock is an endless loop             */
    if (++ctime.sec == 60)  {         /* calculate the second                 */
      ctime.sec = 0;
      if (++ctime.min == 60)  {       /* calculate the minute                 */
        ctime.min = 0;
        if (++ctime.hour == 24)  {    /* calculate the hour                   */
          ctime.hour = 0;
        }
      }
    }
    if (display_time)  {              /* if command_status == display_time    */
      os_send_signal (COMMAND);       /* signal to task command: time changed */
    }
    os_wait (K_IVL, 100, 0);          /* wait interval:  1 second             */
  }
}

/*void counttime (void) _task_ COUNTER_TM {
   while (1) {
   timer_like--;
   if (timer_like == 0) timed_out = 1;
   if (timed_out) {
	              timer_like = buf_timer_like;
	              os_send_signal (LIGHTS);
	              }
	          }

}
*/

struct time rtime;                    /* temporary storage for entry time     */

/******************************************************************************/
/*        readtime: convert line input to time values & store in rtime        */
/******************************************************************************/
bit readtime (char idata *buffer)  {
  unsigned char args;                          /* number of arguments         */

  rtime.sec = 0;                               /* preset second               */
  args = sscanf (buffer, "%bd:%bd:%bd",        /* scan input line for         */
                 &rtime.hour,                  /* hour, minute and second     */
                 &rtime.min,
                 &rtime.sec);

  if (rtime.hour > 23  ||  rtime.min > 59  ||  /* check for valid inputs      */
      rtime.sec > 59   ||  args < 2        ||  args == EOF)  {
    printf ("\n*** ERROR: FORMAT TANGGAL MASUKAN TAK SAH\n");
    return (0);
  }
  return (1);
}

#define ESC  0x1B                     /* ESCAPE character code                */

bit   escape;                         /* flag: mark ESCAPE character entered  */

/******************************************************************************/
/*        Task 6 'get_escape': check if ESC (escape character) was entered    */
/******************************************************************************/
void get_escape (void) _task_ GET_ESC  {
  while (1)  {                                 /* endless loop                */
    if (_getkey () == ESC)  escape = 1;        /* set flag if ESC entered     */
    if (escape)  {                             /* if escape flag send signal  */
      os_send_signal (COMMAND);                /* to task 'command'           */
    }
  }
}
..continued..