Page 186 - PDA Robotics Using Your Personal Digital Assistant to Control Your Robot
P. 186

PDA 08  5/27/03  8:47 AM  Page 162
                                                     PDA Robotics
                          The AppStart() function reads in any saved information and initializes
                          the infrared libray by calling the function StartApplication, which I
                          should have called InitializeInfrared().
                          // FUNCTION: AppStart
                          //
                          // DESCRIPTION:  Get the current application's preferences.
                          //
                          // RETURNED:
                          //     errNone - if nothing went wrong
                          static Err AppStart(void)
                          {
                            UInt16 prefsSize;

                            // Read the saved preferences / saved-state information.
                            prefsSize = sizeof(pdarobotPreferenceType);
                            if (PrefGetAppPreferences(
                               appFileCreator, appPrefID, &g_prefs, &prefsSize, true) !=
                               noPreferenceFound)
                            {
                               // FIXME: setup g_prefs with default values
                            }

                            if (!StartApplication())
                                 return 0;

                            return errNone;
                          }
                          The  AppStop()  function  saves  any  preferences  and  calls
                          StopApplication() which shuts down the infrared communication.

                          // FUNCTION: AppStop
                          //
                          // DESCRIPTION: Save the current state of the application.
                          static void AppStop(void)
                          {
                            // Write the saved preferences / saved-state information.  This
                            // data will be saved during a HotSync backup.
                            PrefSetAppPreferences(
                               appFileCreator, appPrefID, appPrefVersionNum,
                               &g_prefs, sizeof(pdarobotPreferenceType), true);
                            StopApplication();

                            // Close all the open forms.
                            FrmCloseAllForms();
                          }


                          162
   181   182   183   184   185   186   187   188   189   190   191