14.17. Photon: Plots and Deadbands - query_refresh, reset_deadbands, db_prep_query

These three functions are called into action when a query is to be sent. The first, query_refresh, calls the .change_int method and reset_deadbands functions to prepare for the query, then sends the query with send_query.

   /*--------------------------------------------------------------------
    * Function:    query_refresh
    * Returns:     t or nil
    * Description: Sets the interpolator, resets the deadband, and sends a
    *              query.  Used by callbacks on the four interpolator buttons,
    *              the Update display button, and a timer on the Record button.
    *------------------------------------------------------------------*/
   function query_refresh(button, title_string)
   {
     if (title_string)
       hw.change_int(button, title_string);
     
     reset_deadbands();
     send_query(hw.int_set, hw.Text, hw.PtHist, hw.YHistEnt,
                hw.StartEnt, hw.DurEnt, hw.XHistEnt, hw.IntEnt,
                hw.GapEnt, button);
   }
   

The reset_deadbands function is needed whenever a non-deadband button is pressed. Any of the non-deadband buttons sends a new query, and since the data from only one deadband query can be displayed in the text widget at a time, we have chosen to always start with a full data set (no deadband), and delete all past deadband traces to avoid confusion in the display. This is done using the CwGraphClearTrace convenience function of the CwGraph widget.

   /*--------------------------------------------------------------------
    * Function:    reset_deadbands
    * Returns:     an integer
    * Description: Clears all traces and sets the Full data set (no deadband)
    *              option.  Called when non-deadband buttons are activated.
    *------------------------------------------------------------------*/
   function reset_deadbands()
   {
     hw.DBBut.flags = cons(Pt_SET, nil);
     hw.DBPBut.flags = cons(Pt_SET, nil);
     
     if(!undefined_p(GraphWidget))
       {
         CwGraphClearTrace (GraphWidget, 0);
         CwGraphClearTrace (GraphWidget, 1);
         CwGraphClearTrace (GraphWidget, 2);
       }
     hw.DBNoneBut.flags = Pt_SET; 
   }
   

We also need to erase the trace of deadband query when its corresponding button is untoggled. That's what the db_prep_query function does. And when the button is toggled on, it sends a query using the send_query function.

   /*--------------------------------------------------------------------
    * Function:    db_prep_query
    * Returns:     t or nil
    * Description: Sends a query when a Deadband button is toggled on, and
    *              erases the corresponding graph trace when a Deadband button
    *              is untoggled.
    *------------------------------------------------------------------*/
   function db_prep_query(button)
   {
     if ((button.flags & Pt_SET) != 0)
       send_query(hw.int_set, hw.Text, hw.PtHist, hw.YHistEnt,
                  hw.StartEnt, hw.DurEnt, hw.XHistEnt, hw.IntEnt,
                  hw.GapEnt, button);
     else
       {
         if(!undefined_p(GraphWidget))
           {
             if(button == hw.DBNoneBut)
               CwGraphClearTrace (GraphWidget, 0);
             else if(button == hw.DBBut)
               CwGraphClearTrace (GraphWidget, 1);
             else if(button == hw.DBPBut)
               CwGraphClearTrace (GraphWidget, 2);
           }
       }        
   }