NXC ForceOff to turn off the NXT

Discussion specific to NXT-G, NXC, NBC, RobotC, Lejos, and more.
Post Reply
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

NXC ForceOff to turn off the NXT

Post by mattallen37 »

Is the ForceOff command the best way to power off an NXT while tasks are running? I made a program execute at startup by naming it "! Startup", and I made the NXT shut off by pressing the exit button. I just want to be sure that ForceOff is the best way to do this.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC ForceOff to turn off the NXT

Post by afanofosc »

I would use PowerDown() or SleepNow() from the IOCtrl module:

http://bricxcc.sourceforge.net/nbc/nxcd ... tions.html

I doubt there is any significant difference in what the firmware does when you turn off the NXT via the IOCtrl module vs turning it off via the UI module (which is where ForceOff lives).

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC ForceOff to turn off the NXT

Post by mattallen37 »

Okay, thank you.

Edit: is it fine that I see pixel lines appear and then disappear when turning off the NXT this way (any of the three ways)? How/why does the FW's user menu shut-off not do that?
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
afanofosc
Site Admin
Posts: 1256
Joined: 26 Sep 2010, 19:36
Location: Nashville, TN
Contact:

Re: NXC ForceOff to turn off the NXT

Post by afanofosc »

I don't know whether the abrupt shutoff is at all harmful. I'd be surprised if it was but I'm not a hardware guy. Do you see the lines when you use ForceOff?

In c_ui.c there is code like this:

Code: Select all

  // Check for "force" off
  if (IOMapUi.ForceOff != FALSE)
  {
    IOMapUi.ForceOff = FALSE;
    VarsUi.Function  = FUNC_NO_OFF;
    VarsUi.Parameter = MENU_INIT;
    VarsUi.State     = 0;
    IOMapUi.State    = DRAW_MENU;
  }
This causes the firmware to call cUiOff() in Functions.inl:

Code: Select all

UBYTE     cUiOff(UBYTE Action)          // Tell AVR to turn off ARM
{
  if (Action == MENU_INIT)
  {
    switch (VarsUi.State)
    {
      case 0 :                          // Stop VM if running
      {
        if (pMapCmd->ProgStatus == PROG_RUNNING)
        {
          pMapCmd->DeactivateFlag = TRUE;
        }
        VarsUi.State++;
      }
      break;

      case 1 :                          // When VM is stopped -> Display off and close all connections
      {
        if (pMapCmd->ProgStatus != PROG_RUNNING)
        {
          pMapDisplay->Flags     &= ~DISPLAY_ON;
          VarsUi.BTCommand        = (UBYTE)DISCONNECTALL;
          VarsUi.BTPar1           = (UBYTE)0;
          VarsUi.BTPar2           = (UBYTE)0;
          pMapComm->pFunc(VarsUi.BTCommand,VarsUi.BTPar1,VarsUi.BTPar2,0,NULL,&(VarsUi.BTResult));
          VarsUi.State++;
        }
      }
      break;

      case 2 :                          //  Send off command to AVR
      {
        if (VarsUi.BTResult != INPROGRESS)
        {
          pMapIoCtrl->PowerOn   = POWERDOWN;
          VarsUi.Timer          = 0;
          VarsUi.State++;
        }
      }
      break;

      case 3 :                          // Wait for power off
      {
        if (++VarsUi.Timer >= ARM_WAIT_FOR_POWER_OFF)
        {
          VarsUi.State++;
        }
      }
      break;

      case 4 :                          // Vitual off state (if still power) wait for on button
      {
        pMapIoCtrl->PowerOn     = 0;
        if (BUTTON_ENTER == cUiReadButtons())
        {
          VarsUi.State++;
        }
      }
      break;

      default :                         // Turn on again
      {
        IOMapUi.State           = INIT_DISPLAY;
        VarsUi.State            = 0;
      }
      break;

    }
  }

  return (VarsUi.State);
}
So you could do something to the display flags before calling PowerDown().

Code: Select all

  SetDisplayFlags(0); // should turn off the display, disable refresh, use normal memory
  Wait(MS_1); // give firmware a chance to process the previous IOMap change
  PowerDown(); // turn off
I am pretty sure that the display will be properly reset to default values when you turn the NXT back on.

John Hansen
Multi-platform LEGO MINDSTORMS programming
http://bricxcc.sourceforge.net/
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC ForceOff to turn off the NXT

Post by mattallen37 »

That makes no difference, even waiting 5ms.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
mightor
Site Admin
Posts: 1079
Joined: 25 Sep 2010, 15:02
Location: Rotterdam, Netherlands
Contact:

Re: NXC ForceOff to turn off the NXT

Post by mightor »

I am not sure why you are worried :) Considering the NXT doesn't get messed up if you yank the batteries out, I doubt the firmware will do anything worse than that.

- Xander
| My Blog: I'd Rather Be Building Robots (http://botbench.com)
| RobotC 3rd Party Driver Suite: (http://rdpartyrobotcdr.sourceforge.net)
| Some people, when confronted with a problem, think, "I know, I'll use threads,"
| and then two they hav erpoblesms. (@nedbat)
mattallen37
Posts: 1818
Joined: 02 Oct 2010, 02:19
Location: Michigan USA
Contact:

Re: NXC ForceOff to turn off the NXT

Post by mattallen37 »

At this point, it's not so much that I am worried, as I am curious how the FW user menu doesn't make the lines on the screen.
Matt
http://mattallen37.wordpress.com/

I'm all for gun control... that's why I use both hands when shooting ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests