Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages | Examples

test_idle.c

Example of idle task.
/*
 * Copyright (C) 2003 BLADOX, s.r.o.  All rights reserved.
 * 
 * This file is part of an example program for Turbo. This example
 * program may be used, distributed and modified without limitation.
 *
 */

#include <config.h>
#include <turbo/turbo.h>

#include <stdlib.h>

u8 idle_on;
u8 idle_pass;

/* *INDENT-OFF* */

lc_char PROGMEM lc_Idle[]={
        LC_EN("Test Idle")
        LC_END
};

lc_char PROGMEM lc_Idle_Start[]={
        LC_EN("Start")
        LC_END
};

lc_char PROGMEM lc_Idle_Stop[]={
        LC_EN("Stop")
        LC_END
};

lc_char PROGMEM lc_Idle_State[]={
        LC_EN("State")
        LC_END
};

lc_char PROGMEM lc_Pass[]={
        LC_EN("Pass: ")
        LC_END
};

/* *INDENT-ON* */

SNodeP idle_n_start;
SNodeP idle_n_stop;

void test_idle_task ()
{
  idle_pass++;
}

u8 idle_ctx (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    if (idle_on)
      spider_append_r (ctx, &idle_n_stop);
    else
      spider_append_r (ctx, &idle_n_start);
  }
  else if (action == APP_LEAVE)
  {
    spider_clear_r (ctx);
  }

  return APP_OK;
}

u8 idle_toggle (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    idle_pass = 0;
    if (idle_on)
    {
      idle_on = 0;
      unreg_action (ACTION_IDLE_TASK);
    }
    else
    {
      idle_on = 1;
      reg_action (ACTION_IDLE_TASK);
    }
    return APP_BACK;
  }
  return APP_OK;
}

u8 idle_state (SCtx * ctx, u8 action)
{
  if (action == APP_ENTER)
  {
    u8 *r = buf_B ();
    u8 *t;

    t = r;
    t = sprints (t, locale (lc_Pass));
    t = sprinti (t, idle_pass);
    t = sprintc (t, '\0');

    if (display_text (r, NULL) == APP_END)
      return APP_END;
    return APP_BACK;
  }
  return APP_OK;
}

SNodeP idle_n = { lc_Idle, idle_ctx };
SNodeP idle_n_start = { lc_Idle_Start, idle_toggle };
SNodeP idle_n_stop = { lc_Idle_Stop, idle_toggle };
SNodeP idle_n_state = { lc_Idle_State, idle_state };

SEdgeP idle_edges_p[] = {
  {&idle_n, &idle_n_state}
  ,
  NULL
};

void action_menu (void *data)
{
  SCtx *c = spider_init ();

  c->n = &idle_n;
  c->eP = &idle_edges_p;
  spider (c);
}

void turbo_handler (u8 action, void *data)
{
  switch (action)
  {
    case ACTION_APP_INIT:
      reg_action (ACTION_IDLE_TASK);
      idle_on = 1;
      idle_pass = 0;
      break;
    case ACTION_INSERT_MENU:
      insert_menu (locale (lc_Idle));
      break;
    case ACTION_MENU_SELECTION:
      stk_thread (action_menu, data);
      break;
    case ACTION_IDLE_TASK:
      test_idle_task ();
      break;
    default:
      break;
  }
}


Copyright © 2004-2006 BLADOX
Turbo version 1.2