コード例 #1
0
ファイル: can_values.c プロジェクト: sektor1986/SHP-8099
unsigned char PGN_push(struct J1939_message *msg)
{
	unsigned int i;
	unsigned int PGN = (((unsigned int)msg->PDUformat)<<8) | msg->PDUspecific;
	for (i=0; i<MAX_PGN; i++)
	{
		if (PGN == PGNs[i])
		{	
			if (PGN == 0xFEC1)               // Vehicle distance high resolution
			{
				if (msg->sourceAddr == 0xEE) //Принимать только от тахографа (адрес 0xEE)
				{
					J1939_memcpy((unsigned char*)&PGN_data[i],(unsigned char*)msg,sizeof(struct J1939_message));
					PGN_timer[i] = timer_Start();
					PGN_aval[i] = 1;
					return 0;
				}
			}
			else
			{
					J1939_memcpy((unsigned char*)&PGN_data[i],(unsigned char*)msg,sizeof(struct J1939_message));
					PGN_timer[i] = timer_Start();
					PGN_aval[i] = 1;
					return 0;				
			}
		}
	}
	return 1;
}
コード例 #2
0
ファイル: throughput.c プロジェクト: coyizumi/cs111
static void
throughput_sampler(void *v)
{
  struct pppThroughput *t = (struct pppThroughput *)v;
  unsigned long long old;
  int uptime, divisor;
  unsigned long long octets;

  timer_Stop(&t->Timer);

  uptime = throughput_uptime(t);
  divisor = uptime < t->SamplePeriod ? uptime + 1 : t->SamplePeriod;

  old = t->in.SampleOctets[t->nSample];
  t->in.SampleOctets[t->nSample] = t->OctetsIn;
  t->in.OctetsPerSecond = (t->in.SampleOctets[t->nSample] - old) / divisor;

  old = t->out.SampleOctets[t->nSample];
  t->out.SampleOctets[t->nSample] = t->OctetsOut;
  t->out.OctetsPerSecond = (t->out.SampleOctets[t->nSample] - old) / divisor;

  octets = t->in.OctetsPerSecond + t->out.OctetsPerSecond;
  if (t->BestOctetsPerSecond < octets) {
    t->BestOctetsPerSecond = octets;
    time(&t->BestOctetsPerSecondTime);
  }

  if (++t->nSample == t->SamplePeriod)
    t->nSample = 0;

  if (t->callback.fn != NULL && uptime >= t->SamplePeriod)
    (*t->callback.fn)(t->callback.data);

  timer_Start(&t->Timer);
}
コード例 #3
0
void
lqr_reStart(struct lcp *lcp)
{
  struct physical *p = link2physical(lcp->fsm.link);

  lqr_Setup(lcp);
  if (p->hdlc.lqm.timer.load)
    timer_Start(&p->hdlc.lqm.timer);
}
コード例 #4
0
ファイル: i4b.c プロジェクト: juanfra684/DragonFlyBSD
/*
 * i4b_Timeout() watches the DCD signal and mentions it if it's status
 * changes.
 */
static void
i4b_Timeout(void *data)
{
  struct physical *p = data;
  struct i4bdevice *dev = device2i4b(p->handler);
  int ombits, change;

  timer_Stop(&dev->Timer);
  dev->Timer.load = SECTICKS;		/* Once a second please */
  timer_Start(&dev->Timer);
  ombits = dev->mbits;

  if (p->fd >= 0) {
    if (ioctl(p->fd, TIOCMGET, &dev->mbits) < 0) {
      log_Printf(LogPHASE, "%s: ioctl error (%s)!\n", p->link.name,
                 strerror(errno));
      datalink_Down(p->dl, CLOSE_NORMAL);
      timer_Stop(&dev->Timer);
      return;
    }
  } else
    dev->mbits = 0;

  if (ombits == -1) {
    /* First time looking for carrier */
    if (Online(dev))
      log_Printf(LogPHASE, "%s: %s: CD detected\n", p->link.name, p->name.full);
    else if (++dev->carrier_seconds >= dev->dev.cd.delay) {
      log_Printf(LogPHASE, "%s: %s: No carrier"
                 " (increase ``set cd'' from %d ?)\n",
                 p->link.name, p->name.full, dev->dev.cd.delay);
      timer_Stop(&dev->Timer);
      /* i4b_AwaitCarrier() will notice */
    } else {
      /* Keep waiting */
      log_Printf(LogDEBUG, "%s: %s: Still no carrier (%d/%d)\n",
                 p->link.name, p->name.full, dev->carrier_seconds,
                 dev->dev.cd.delay);
      dev->mbits = -1;
    }
  } else {
    change = ombits ^ dev->mbits;
    if (change & TIOCM_CD) {
      if (dev->mbits & TIOCM_CD)
        log_Printf(LogDEBUG, "%s: offline -> online\n", p->link.name);
      else {
        log_Printf(LogDEBUG, "%s: online -> offline\n", p->link.name);
        log_Printf(LogPHASE, "%s: Carrier lost\n", p->link.name);
        datalink_Down(p->dl, CLOSE_NORMAL);
        timer_Stop(&dev->Timer);
      }
    } else
      log_Printf(LogDEBUG, "%s: Still %sline\n", p->link.name,
                 Online(dev) ? "on" : "off");
  }
}
コード例 #5
0
static void
chat_Pause(struct chat *c, u_long load)
{
  timer_Stop(&c->pause);
  c->pause.load += load;
  c->pause.func = chat_PauseTimer;
  c->pause.name = "chat pause";
  c->pause.arg = c;
  timer_Start(&c->pause);
}
コード例 #6
0
static void
cbcp_StartTimer(struct cbcp *cbcp, int timeout)
{
  timer_Stop(&cbcp->fsm.timer);
  cbcp->fsm.timer.func = cbcp_Timeout;
  cbcp->fsm.timer.name = "cbcp";
  cbcp->fsm.timer.load = timeout * SECTICKS;
  cbcp->fsm.timer.arg = cbcp;
  timer_Start(&cbcp->fsm.timer);
}
コード例 #7
0
ファイル: Ai_UnitAttack.c プロジェクト: sigt44/ventifact
/*
    Function: aiState_UnitAttackArea_Init

    Description -
    This prepares the ai state for main use. Making sure to obtain any information the ai goal
    needs to get started.


    1 argument:
    Ai_State *a - The ai state to initialise.
*/
void aiState_UnitAttackArea_Init(Ai_State *a)
{
    AiAttributes_UnitAttackArea *aE = a->extraStructure;
    Vent_Unit *unit = a->entity;
    int updateFrequency = 100 + 10*(rand() % 50);

    aE->moveState = aE->attackUnitState = NULL;

    aE->updateTimer = timer_Setup(&aE->game->gTimer, 0, updateFrequency, 0);

    /*Start the duration timer*/
    timer_Start(&aE->durationTimer);

    timer_Start(&aE->updateTimer);

    //printf("%s: Attacking Area(%d %d : %d) for %d length\n", unit->name, aE->areaLocation.x, aE->areaLocation.y, aE->attackRangeSqr, aE->durationTimer.end_Time);

    aiState_Init(a);

    return;
}
コード例 #8
0
static void
chat_SetTimeout(struct chat *c)
{
  timer_Stop(&c->timeout);
  if (c->TimeoutSec > 0) {
    c->timeout.load = SECTICKS * c->TimeoutSec;
    c->timeout.func = chat_TimeoutTimer;
    c->timeout.name = "chat timeout";
    c->timeout.arg = c;
    timer_Start(&c->timeout);
  }
}
コード例 #9
0
ファイル: auth.c プロジェクト: 2trill2spill/freebsd
void
auth_StartReq(struct authinfo *authp)
{
  timer_Stop(&authp->authtimer);
  authp->authtimer.func = AuthTimeout;
  authp->authtimer.name = "auth";
  authp->authtimer.load = authp->cfg.fsm.timeout * SECTICKS;
  authp->authtimer.arg = (void *)authp;
  authp->retry = authp->cfg.fsm.maxreq;
  authp->id = 1;
  (*authp->fn.req)(authp);
  timer_Start(&authp->authtimer);
}
コード例 #10
0
ファイル: i4b.c プロジェクト: juanfra684/DragonFlyBSD
static void
i4b_StartTimer(struct physical *p)
{
  struct i4bdevice *dev = device2i4b(p->handler);

  timer_Stop(&dev->Timer);
  dev->Timer.load = SECTICKS;
  dev->Timer.func = i4b_Timeout;
  dev->Timer.name = "i4b CD";
  dev->Timer.arg = p;
  log_Printf(LogDEBUG, "%s: Using i4b_Timeout [%p]\n",
             p->link.name, i4b_Timeout);
  timer_Start(&dev->Timer);
}
コード例 #11
0
ファイル: auth.c プロジェクト: 2trill2spill/freebsd
static void
AuthTimeout(void *vauthp)
{
  struct authinfo *authp = (struct authinfo *)vauthp;

  timer_Stop(&authp->authtimer);
  if (--authp->retry > 0) {
    authp->id++;
    (*authp->fn.req)(authp);
    timer_Start(&authp->authtimer);
  } else {
    log_Printf(LogPHASE, "Auth: No response from server\n");
    datalink_AuthNotOk(authp->physical->dl);
  }
}
コード例 #12
0
ファイル: qos_scheduler.c プロジェクト: 7LK/McWRT
Status_e SetSITimer(void)
{
	UINT16 timercontrol;
#ifndef HW_SI_TIMER
	timer_Data_t *timer_p;
	UINT32 no_of_ticks;

	if (SItimerID != 0xFFFFFFFF)
	{//A timer already exists. Disable the existing timer
		timer_Stop(SItimerID);
		timer_Return(SItimerID);
	}
	if ((timer_p = timer_Get(&SI_TimeoutHdlr)) != NULL)
	{
		SItimerID = timer_p->Id;
	}
	else
	{
		return FAIL;
	}
#ifndef NEW_SCHEDULER
	no_of_ticks = currentSI/10000;   /* how may 10 ms */
#else
	no_of_ticks = gGCD/10;   /* how may 10 ms */
#endif
	timer_Start(timer_p->Id, no_of_ticks, no_of_ticks);
#else //HW_SI_TIMER
	WL_READ_REGS16(TIMER_CONTROL, timercontrol);
	//stop the timer
	WL_WRITE_REGS16(TIMER_CONTROL, (timercontrol & (~TIMER1_ACTIVATE)));
	//load the new counter val
#ifndef NEW_SCHEDULER
	WL_WRITE_REGS16(TIMER1_LEN, currentSI/1000);/** Set to the time you want in ms **/
#else
	WL_WRITE_REGS16(TIMER1_LEN, (gGCD/1000)-1);/** Set to the time you want in ms adjust for 1ms delay in timer expiry**/
#endif

	//W81_WRITE_REGS16(TIMER1_LEN, 5000);/** Set to the time you want in ms **/
	//restart the timer. Make it a periodic timer
	WL_WRITE_REGS16(TIMER_CONTROL, (timercontrol | TIMER1_AUTORST | TIMER1_ACTIVATE | TIMER1_LD_VAL));
	//W81_WRITE_REGS16(TIMER_CONTROL, (timercontrol | TIMER1_ACTIVATE | TIMER1_LD_VAL));
#endif //HW_SI_TIMER

	//  timer_Start(timer_p->Id, 10, 10);//HARDCODE
	return SUCCESS;
}
コード例 #13
0
ファイル: radius.c プロジェクト: coyizumi/cs111
/*
 * We've either timed out or select()ed on the read descriptor
 */
static void
radius_Continue(struct radius *r, int sel)
{
  struct timeval tv;
  int got;

  timer_Stop(&r->cx.timer);
  if ((got = rad_continue_send_request(r->cx.rad, sel, &r->cx.fd, &tv)) == 0) {
    log_Printf(log_IsKept(LogRADIUS) ? LogRADIUS : LogPHASE,
	       "Radius: Request re-sent\n");
    r->cx.timer.load = tv.tv_usec / TICKUNIT + tv.tv_sec * SECTICKS;
    timer_Start(&r->cx.timer);
    return;
  }

  radius_Process(r, got);
}
コード例 #14
0
ファイル: throughput.c プロジェクト: coyizumi/cs111
void
throughput_restart(struct pppThroughput *t, const char *name, int rolling)
{
  timer_Stop(&t->Timer);
  t->rolling = rolling ? 1 : 0;
  if (t->rolling) {
    t->Timer.load = SECTICKS;
    t->Timer.func = throughput_sampler;
    t->Timer.name = name;
    t->Timer.arg = t;
    timer_Start(&t->Timer);
  } else {
    t->Timer.load = 0;
    t->Timer.func = NULL;
    t->Timer.name = NULL;
    t->Timer.arg = NULL;
  }
}
コード例 #15
0
ファイル: datalink.c プロジェクト: AhmadTux/DragonFlyBSD
static int
datalink_StartDialTimer(struct datalink *dl, int Timeout)
{
  int result = Timeout;

  timer_Stop(&dl->dial.timer);
  if (Timeout < 0)
    result = (random() % DIAL_TIMEOUT) + 1;
  dl->dial.timer.load = result ? result * SECTICKS : 1;
  dl->dial.timer.func = datalink_OpenTimeout;
  dl->dial.timer.name = "dial";
  dl->dial.timer.arg = dl;
  timer_Start(&dl->dial.timer);
  if (dl->state == DATALINK_OPENING)
    log_Printf(LogPHASE, "%s: Enter pause (%d) for redialing.\n",
               dl->name, result);
  return result;
}
コード例 #16
0
ファイル: Controls.c プロジェクト: sigt44/ventifact
/*
	Function: control_IsActivatedType

	Description -
	Returns 1 if the event is activated (All key presses required have
	been found and the repeating time is ready), otherwise returns 0.

	2 arguments:
	Control_Event *c - the event to be checked if activated.
	int eventType - The general event type the control keys must be in. (C_ANY_TYPE) (C_BUTTON_DOWN) (C_BUTTON_UP) (C_BUTTON_STATES)
	if (C_BUTTON_NORMAL) then use the event given to the keys when they were first added.
*/
unsigned int control_IsActivatedType(Control_Event *c, int eventType)
{
    if(control_CheckTimers(c) == 1)
    {
        return 0;
    }

	/*Check if the correct keys have been pressed*/
    if(control_CheckLink(c) == 0 && control_KeyCheck(c->eventKeys, eventType) == 1)
    {
        timer_Start(&c->repeater); /*Timer has been on long enough, restart it*/

        control_StopLinked(c);

        return 1;
    }

    return 0;
}
コード例 #17
0
ファイル: lqr.c プロジェクト: 2asoft/freebsd
static void
SendLqrReport(void *v)
{
  struct lcp *lcp = (struct lcp *)v;
  struct physical *p = link2physical(lcp->fsm.link);

  timer_Stop(&p->hdlc.lqm.timer);

  if (p->hdlc.lqm.method & LQM_LQR) {
    if (p->hdlc.lqm.lqr.resent > 5) {
      /* XXX: Should implement LQM strategy */
      log_Printf(LogPHASE, "%s: ** Too many LQR packets lost **\n",
                lcp->fsm.link->name);
      log_Printf(LogLQM, "%s: Too many LQR packets lost\n",
                lcp->fsm.link->name);
      p->hdlc.lqm.method = 0;
      datalink_Down(p->dl, CLOSE_NORMAL);
    } else {
      SendLqrData(lcp);
      p->hdlc.lqm.lqr.resent++;
    }
  } else if (p->hdlc.lqm.method & LQM_ECHO) {
    if ((p->hdlc.lqm.echo.seq_sent > 5 &&
         p->hdlc.lqm.echo.seq_sent - 5 > p->hdlc.lqm.echo.seq_recv) ||
        (p->hdlc.lqm.echo.seq_sent <= 5 &&
         p->hdlc.lqm.echo.seq_sent > p->hdlc.lqm.echo.seq_recv + 5)) {
      log_Printf(LogPHASE, "%s: ** Too many LCP ECHO packets lost **\n",
                lcp->fsm.link->name);
      log_Printf(LogLQM, "%s: Too many LCP ECHO packets lost\n",
                lcp->fsm.link->name);
      p->hdlc.lqm.method = 0;
      datalink_Down(p->dl, CLOSE_NORMAL);
    } else
      SendEchoReq(lcp);
  }
  if (p->hdlc.lqm.method && p->hdlc.lqm.timer.load)
    timer_Start(&p->hdlc.lqm.timer);
}
コード例 #18
0
ファイル: jswrap_rtos.c プロジェクト: CWBudde/Espruino
/*JSON{
  "type"     : "method",
  "class"    : "Timer",
  "name"     : "start",
  "params"   : [["duration","int","duration of timmer in micro secs"]],
  "generate" : "jswrap_Timer_start"
}
Starts a timer
*/
void jswrap_Timer_start(JsVar *parent, int duration){
  JsVar *idx = jsvObjectGetChild(parent,"index",1);
  timer_Start(jsvGetInteger(idx),duration);
}
コード例 #19
0
ファイル: Ai_UnitAttack.c プロジェクト: sigt44/ventifact
/*
    Function: aiState_UnitAttackArea_Main

    Description -
    Make sure the unit is in the area to attack.
    Search for any enemy units in that area and attack them.

    1 argument:
    Ai_State *a - The ai state to update.
*/
void aiState_UnitAttackArea_Main(Ai_State *a)
{
    AiAttributes_UnitAttackArea *aE = a->extraStructure;
    Vent_Unit *unit = a->entity;

    int xDis = 0;
    int yDis = 0;
    int unitAttackArea = 0;
    int callUpdate = 0;

    const int maxOutsideRange = 150*150;

    Vent_Unit *targetUnit = NULL;
    Vent_Target target;

    timer_Calc(&aE->updateTimer);
    if(timer_Get_Remain(&aE->updateTimer) <= 0)
    {
        callUpdate = 1;
        timer_Start(&aE->updateTimer);

        xDis = aE->areaLocation.x - unit->iPosition.x;
        yDis = aE->areaLocation.y - unit->iPosition.y;

        unitAttackArea = mth_DistanceSqr(xDis, yDis) - aE->attackRangeSqr;
    }

    if(aE->moveState != NULL)
    {
        /*Move the unit towards the area to attack*/
        if(aiState_Update(aE->moveState) == AI_COMPLETE_WAIT)
        {
            /*If the state has been completed then deleted it and set it to NULL*/
            aE->moveState = aiState_Delete(aE->moveState);
        }
    }
    else if(callUpdate == 1 && unitAttackArea > 0 && aE->attackUnitState == NULL)
    {
        /*If the unit is outside of the attack area*/
        /*Move the unit close to the area to attack*/
        aE->moveState = aiState_UnitTravelPoint_Setup(aiState_Create(),
                                    a->group, /*Matching group and priority*/
                                    a->priority,
                                    AI_COMPLETE_WAIT,
                                    unit,
                                    aE->areaLocation.x, /*Move to the area to attack*/
                                    aE->areaLocation.y,
                                    aE->attackRangeSqr - (aE->attackRangeSqr/5), /*Slightly further in than the maximum range*/
                                    aE->game->level);
    }

    if(aE->attackUnitState != NULL)
    {
        /*Keep attacking the unit*/
        aiState_Update(aE->attackUnitState);

        if(aE->attackUnitState->complete == AI_COMPLETE_WAIT || unitAttackArea > maxOutsideRange)
        {
            /*If the unit is too far outside of its area or the attack state is complete*/
            aE->attackUnitState = aiState_Delete(aE->attackUnitState);

            timer_Start(&aE->durationTimer);
        }
    }
    else if(callUpdate == 1 && aE->moveState == NULL && aE->attackUnitState == NULL)
    {
        /*Search for an enemy unit within range of the area the unit is suppose to attack*/
        target = vAi_GetUnit_ClosestType(aE->game->side[unit->team].enemy->units,
                                                    aE->areaLocation.x,
                                                    aE->areaLocation.y,
                                                    aE->attackRangeSqr + maxOutsideRange,
                                                    aE->game->side[unit->team].enemy->team,
                                                    -1);

        targetUnit = target.entity;

        /*If there is a unit to attack*/
        if(targetUnit != NULL)
        {
            aE->attackUnitState = aiState_UnitAttackUnit_Setup(aiState_Create(),
                                        a->group,
                                        a->priority,
                                        AI_COMPLETE_WAIT,
                                        unit,
                                        aE->game,
                                        targetUnit
                                        );
        }
        else
        {
            /*There are no units to attack, start the countdown until state complete*/
            if(aE->durationTimer.end_Time != 0)
            {
                timer_Calc(&aE->durationTimer);

                if(timer_Get_Remain(&aE->durationTimer) <= 0)
                {
                    //printf("%s: No units to attack at (%d %d : %d)\n", unit->name, aE->areaLocation.x, aE->areaLocation.y, aE->attackRangeSqr);
                    a->update = a->exit;
                }
            }
        }

    }

    return;
}
コード例 #20
0
ファイル: Ai_UnitAttack.c プロジェクト: sigt44/ventifact
/*
    Function: aiState_UnitAttack_Main

    Description -
    This function contains the logic for the ai goal to be achieved.
    Fire weapon at the closest unit that is in range.

    1 argument:
    Ai_State *a - The ai state to update.
*/
void aiState_UnitAttack_Main(Ai_State *a)
{
    AiAttributes_UnitAttack *aE = a->extraStructure;
    Vent_Unit *unit = a->entity;

    Vent_Unit *attackUnit = NULL;
    Vent_Building *attackBuilding = NULL;
    Vent_Tile *attackTile = NULL;

    int x = 0;

    float xDis = 0;
    float yDis = 0;

    timer_Calc(&aE->updateTimer);

    /*If its time to check for a new unit/building*/
    if(timer_Get_Remain(&aE->updateTimer) < 0)
    {
        for(x = 0; x < UNIT_MAX_TARGETS; x++)
        {
            if(unit->targetEnemy[x].entity != NULL)
            {
                aE->currentTarget = &unit->targetEnemy[x];
                aE->trackTarget = unit->targetEnemy[x].entity;
                break;
            }
        }

        if(aE->currentTarget != NULL && aE->currentTarget->entity != NULL)
        {
            /*printf("%s: Targeting %s\n", unit->name, entityNames[aE->currentTarget->type]);*/

            switch(aE->currentTarget->type)
            {
                default:

                printf("%s Warning unknown attack target type %d\n", unit->name, aE->currentTarget->type);

                break;

                break;

                case ENTITY_BUILDING:
                attackBuilding = aE->currentTarget->entity;

                aE->attackTarget.x = attackBuilding->middlePosition.x;
                aE->attackTarget.y = attackBuilding->middlePosition.y;

                break;

                case ENTITY_UNIT:
                attackUnit = aE->currentTarget->entity;

                aE->attackTarget.x = attackUnit->middlePosition.x;
                aE->attackTarget.y = attackUnit->middlePosition.y;

                break;

                case ENTITY_TILE:

                attackTile = aE->currentTarget->entity;

                aE->attackTarget.x = attackTile->base.position.x + attackTile->base.width/2;
                aE->attackTarget.y = attackTile->base.position.y + attackTile->base.height/2;

                break;
            }
        }

        timer_Start(&aE->updateTimer);
    }

    /*If the unit cannot fire its weapon*/
    if(vWeapon_CanFire(&unit->weapon) != WEAPON_CANFIRE)
    {
        return; /*exit early*/
    }

    /*If there is a target to fire at*/
    if(aE->currentTarget == NULL || aE->currentTarget->entity == NULL)
    {
        /*printf("%s: Target last seen at (%d %d) destroyed.\n", unit->name, (int)aE->attackTarget.x, (int)aE->attackTarget.y);*/
        return;
    }
    else if(aE->trackTarget != aE->currentTarget->entity) /*The target has changed, exit early*/
    {
        aE->currentTarget = NULL;
        aE->trackTarget = NULL;
    }
    else
    {
        if(aE->currentTarget->type == ENTITY_UNIT)
        {
            attackUnit = aE->currentTarget->entity;

            aE->attackTarget.x = attackUnit->middlePosition.x;
            aE->attackTarget.y = attackUnit->middlePosition.y;
        }

        /*Locate x distance and y distance to enemy entity*/
        xDis = (float)(aE->attackTarget.x - unit->middlePosition.x);
        yDis = (float)(aE->attackTarget.y - unit->middlePosition.y);

        /*Attack enemy unit/building*/
        vWeapon_Fire(&unit->weapon, aE->game, unit->iPosition.x, unit->iPosition.y, vWeapon_Direction(unit->weapon.accurate, -1, xDis, -yDis));
    }

    return;
}
コード例 #21
0
ファイル: GameMenu.c プロジェクト: sigt44/ventifact
void Menu_Game_Init(void *info)
{
    Base_State *gState = info;

    struct menu_Game *menu = (struct menu_Game *)mem_Malloc( sizeof(struct menu_Game), __LINE__, __FILE__);

    int x = 0;

    const int tButtons = 5;
    char **test = NULL;
    Ui_Button *button[5];
    Sprite *bSprite[5];

    Ui_ButtonScroll *mainScroll = NULL;
    Ui_ButtonScroll *unitScroll = NULL;
    SDL_Surface *background = NULL;

    menu->player = gState->info;

    menu->nameList = NULL;
    menu->campaignNameList = NULL;

    if(menu->player->campaign != NULL)
    {
        menu->selectedCampaign = menu->player->campaign->name;
    }
    else
        menu->selectedCampaign = "None";

    vLevel_SetupHeader(&menu->levelHeader, "None", 0, 0);

    gState->info = menu;

    /*Setup timer*/
    menu->timer = timer_Setup(NULL, 0, 0, 1);

    /*Setup menu spine*/
    background = surf_Copy(ve_Surfaces.mainMenu);

    pixelMan_PushLine(gKer_DrawManager(), 0, 475, 101, 475, background->h - 101, 2, colourBlack, background);


    uiSpine_Setup(&menu->spine, VL_HUD + 1, (ker_Screen_Width()/2) - (background->w/2), (ker_Screen_Height()/2) - (background->h/2), frame_CreateBasic(0, background, A_FREE), &ve_Menu.pointer, 0, NULL, UI_SPINE_ALLFLAGS);

    uiSpine_AddTextBox(&menu->spine,
                       uiTextBox_CreateBase(225, 120, VL_HUD + 1, 0, NULL, font_Get(2, 16), tColourBlack, &menu->timer),
                       "TextBox:Campaign");

    uiTextBox_AddText(uiSpine_GetEntity(&menu->spine,"TextBox:Campaign"),
                     0, 0, "Campaign: %s", dataStruct_Create(1, &menu->selectedCampaign));

    /*Create buttons*/
    button[0] = veMenu_ButtonSide(0, 0, "PLAY", &menu->spine.sTimer, &MM_StartGame, &MM_ButtonHover, dataStruct_Create(1, gState));

    button[1] = veMenu_ButtonSide(0, 0, "CAMPAIGN", &menu->spine.sTimer, &MM_SelectCampaign, &MM_ButtonHover, dataStruct_Create(1, gState));

    button[2] = veMenu_ButtonSide(0, 0, "UPGRADE", &menu->spine.sTimer, &MM_Upgrade, &MM_ButtonHover, dataStruct_Create(1, gState));

    button[3] = veMenu_ButtonSide(0, 0, "SAVE", &menu->spine.sTimer, &MM_SaveGame, &MM_ButtonHover, dataStruct_Create(1, menu));

    button[4] = veMenu_ButtonSide(0, 0, "BACK", &menu->spine.sTimer, &MM_Quit, &MM_ButtonHover, dataStruct_Create(1, gState));

    uiSpine_AddButton(&menu->spine, button[0], "Button:Play");
    uiSpine_AddButton(&menu->spine, button[1], "Button:Campaign");
    uiSpine_AddButton(&menu->spine, button[2], "Button:Upgrade");
    uiSpine_AddButton(&menu->spine, button[3], "Button:Save");
    uiSpine_AddButton(&menu->spine, button[4], "Button:Back");

    uiSpine_AlignEntities(&menu->spine, ve_Menu.buttonPosition.x, ve_Menu.buttonPosition.y, ve_Menu.buttonSpaceing, SCR_V, 5,
                          "Button:Play",
                          "Button:Campaign",
                          "Button:Upgrade",
                          "Button:Save",
                          "Button:Back");

    /*Create the list of levels to be selected and displayed*/
    uiSpine_AddScroll(&menu->spine, MM_CreateLevelScroll(gState), "Scroll:Levels");

    /*Add in the play unit scroll*/
    unitScroll = uiButtonScroll_Create(515, 305,
                                   SCR_H, ve_Menu.buttonSpaceing, 1, 1, 0,
                                   veMenu_ButtonSprite(550, 360, sprite_Copy(&ve_Sprites.scroll[D_RIGHT], 1), &menu->spine.sTimer, &BFA_ScrollSelectForwards, &MABFH_ButtonHover, NULL),
                                   veMenu_ButtonSprite(515, 360, sprite_Copy(&ve_Sprites.scroll[D_LEFT], 1), &menu->spine.sTimer, &BFA_ScrollSelectBackwards, &MABFH_ButtonHover, NULL),
                                   4,
                                   GM_CreateUnitButton(UNIT_TANK, &menu->player->startingUnit, VL_HUD + 1, &menu->timer),
                                   GM_CreateUnitButton(UNIT_INFANTRY, &menu->player->startingUnit, VL_HUD + 1, &menu->timer),
                                   GM_CreateUnitButton(UNIT_AIR, &menu->player->startingUnit, VL_HUD + 1, &menu->timer),
                                   GM_CreateUnitButton(UNIT_TOWER, &menu->player->startingUnit, VL_HUD + 1, &menu->timer)
                                   );

    uiButtonScroll_SetHoverState(unitScroll, &MABFH_HoverLine);

    uiSpine_AddScroll(&menu->spine, unitScroll, "Scroll:Unit");

    uiSpine_AddTextBox(&menu->spine,
                       uiTextBox_CreateBase(505, 280, VL_HUD + 1, 0, NULL, font_Get(2, 16), tColourBlack, &menu->timer),
                       "TextBox:UnitSelect");

    uiTextBox_AddText(uiSpine_GetEntity(&menu->spine,"TextBox:UnitSelect"),
                     0, 0, "Unit selected:", NULL);

    /*Setup the button chooser in the spine so that the menu can be traversed with buttons*/
    veMenu_SetSpineControl(&menu->spine);
    uiSpine_MapEntity(&menu->spine);


    /*Setup campaign select sub-menu*/
    MM_CampaignMenuSetup(gState);

    timer_Start(&menu->timer);

    baseState_SetOnActivate(gState, &Menu_Game_Activate);

    menu->prevTime = (float)timer_Get_Passed(&menu->timer, 0);

    return;
}
コード例 #22
0
ファイル: power_driver.c プロジェクト: Btar/HEXIWEAR
/**
 * put MCU to VLPS mode,
 * enable/disable possible interrupts
 * @return status flag
 */
static power_status_t power_PutMCUToSleep()
{
    bool
        sensorTimerState = false;

    /** check for active communication */

    /** I2C */

    i2c_status_t
      currentStatus;

    uint32_t
      rxBytesRemaining = 0,
      txBytesRemaining = 0;

    for ( uint8_t i2cIdx = 0; i2cIdx < 2; i2cIdx++ )
    {
        currentStatus = kStatus_I2C_Success;
        currentStatus |= I2C_DRV_MasterGetSendStatus   ( i2cIdx, &txBytesRemaining );
        currentStatus |= I2C_DRV_MasterGetReceiveStatus( i2cIdx, &rxBytesRemaining );
        if  (
                    ( kStatus_I2C_Success == currentStatus )
                &&  ( 0 != ( txBytesRemaining + rxBytesRemaining ) )
            )
        {
            return POWER_STATUS_INIT_ERROR;
        }
    }

    /** UART */

    // ...

    switch ( currentPowerMode )
    {
        case POWER_CURRENT_MODE_NORMAL:
        case POWER_CURRENT_MODE_SLEEP_SHALLOW:
        {
            // shouldn't happen
            catch( CATCH_POWER );
        }

        case POWER_CURRENT_MODE_SLEEP_TOTAL:
        {
            // check sensor timer's state to remember for later
            sensorTimerState = timer_IsActive( HEXIWEAR_TIMER_SENSOR );
            if ( true == sensorTimerState )
            {
            	timer_Stop( HEXIWEAR_TIMER_SENSOR );
            }
            break;
        }

        case POWER_CURRENT_MODE_SLEEP_SENSOR_TAG:
        {
            // do nothing
            break;
        }
    }

	/**
	 * set the wake-up source to none,
	 * as it will be set by invoking the wake-up function in the appropriate interrupt handler
	 */

    if ( POWER_CURRENT_MODE_NORMAL != currentPowerMode )
    {
        // disable interrupts
        // asm(" CPSID i");

		/** put MCU to sleep (VLPS) */
		POWER_SYS_SetMode( 1, kPowerManagerPolicyAgreement );
		CLOCK_SYS_UpdateConfiguration( 0, kClockManagerPolicyForcible );

		OSA_TimeDelay(10);
		// GPIO_DRV_TogglePinOutput( KW40_WU );

		// enable interrupts
		// asm(" CPSIE i ");

//		rtc_datetime_t
//			tmpTime;
//		RTC_GetCurrentTime( &tmpTime );
//		RTC_TriggerAlarm( &tmpTime, 1 );
    }

    /**
     * MCU is now woken up,
     * undo all the power-save changes from the above
     */

    switch ( currentPowerMode )
    {
        case POWER_CURRENT_MODE_NORMAL:
        {
            RTC_EnableAlarm();
            RTC_UpdateAlarm();
            power_TurnScreenON();

            // if the timer was enabled before entering the sleep mode, enable it
            if ( true == sensorTimerState )
            {
                timer_Start( HEXIWEAR_TIMER_SENSOR );
            }

            break;
        }

        case POWER_CURRENT_MODE_SLEEP_SHALLOW:
        {
            // shouldn't happen
            catch( CATCH_POWER );
            break;
        }

        case POWER_CURRENT_MODE_SLEEP_TOTAL:
        {
            break;
        }

        case POWER_CURRENT_MODE_SLEEP_SENSOR_TAG:
        {
            break;
        }
    }

    return POWER_STATUS_SUCCESS;
}
コード例 #23
0
ファイル: j1939.c プロジェクト: sektor1986/SHP-8099
void J1939_init(const unsigned char startAddress,const unsigned char *name)
{
	unsigned char i=0;

	TXstart=TXend=RXstart=RXend=0;
	TXsize=RXsize=0;

	ComandedAddress = startAddress;
	J1939_Address = startAddress;
	for (i;i<8;i++)	Name[i] = name[i];

	can_Init();		// 250 Kbit/s

   	for (i=0; i<BUFFER_TX_COUNT;i++)
	{
		can_SetBuffer(START_BUFFER_TX+i,0,0xFFFFFE);
		clear_CPU_operation_detection();
	}
	for (i=0; i<BUFFER_COUNT; i++)
	{
		can_SetBuffer(START_BUFFER+i,1,((unsigned long int)startAddress)<<8);
		can_EnableIRQ(START_BUFFER+i);
		clear_CPU_operation_detection();
	}
	for (i=0; i<BUFFER_GLOBAL_COUNT; i++)
	{
		can_SetBuffer(START_BUFFER_GLOBAL+i,1,0x0000F000);
		can_EnableIRQ(START_BUFFER_GLOBAL+i);
		clear_CPU_operation_detection();
	}

	can_SetMask0(0xFF00FF);
	can_SetMask1(0xFF0FFF);
	//can_Mode(0);

	J1939_Flags.CannotClaimAddress = 0;
	J1939_Flags.WaitingForAddressClaimContention = 0;
	J1939_Flags.ReceivedMessagesDropped = 0;

	J1939_Flags.AddressRequest = 0;

	J1939_Flags.Connected = 0;
	J1939_Flags.BAM = 0;
	J1939_Flags.WaitingForConnection = 0;
	J1939_Flags.ConnectFalied = 0;
	J1939_Flags.TransmisionError = 0;
	J1939_Flags.TransmisionComplete = 0;
	J1939_Flags.RemoteAddress = J1939_NULL_ADDRESS;

	J1939_timer = timer_Start();
	can_DisableAllIRQ();
    J1939_ClaimAddress(J1939_CLAIM_ADDRESS_TX);

	while (J1939_Flags.WaitingForAddressClaimContention)
	{
		clear_CPU_operation_detection();
		J1939_poll(5);
//		clear_CPU_operation_detection();
	}
	can_EnableAllIRQ();
	
	return;
}