Sunday 19 October 2014

New dialler code

This is the schematic for the dialler to GMS module.

Below is a representation of a dialled number:

---------------_-_-_-_------------_-_-_-_-_-_----------

would be "35". The long pulse as the rotary is rotated anti-clockwise then the pulses for the number as the rotary returns. So when a long pulse is received, the previous set of pulses has finished and the count of these pulses is saved as the number.

The code is much simpler: (Note to self: this is in a file called push_button.c for some strange reason!)

void getNumber() {
   int16 x = 0;  // number lemgth
   int16 count = 0; // button press count
   int16 pulseCount = 0; // counts the pulses from the rotary
   int32 timer; // This is the timer
   BYTE status; // This if for detecting button state
   char phoneNum[15] = ""; // A character array for the phone number
   char num[4] = "ATD"; // start of the dial string
   strcat(phoneNum,num); // cp the start of the dial string to the phone num AT command


    // do this while the phone is still off the hook
    while (!input(PIN_A1)) {

      if (input (PIN_A0)) // dialer input high
      {
         delay_ms(10); // debounce
         pulseCount++; // This counts the number of clock cycles
         status=0;
         timer=0;
      }

      if (!input (PIN_A0) && status == 0 ) // dialer input low
      {
         delay_ms(10); // debounce switch
         if(pulseCount > 20 && count>0) { // add the count to the AT string
            count--; // decrement as the number is always one more
            if(count > 9)
               count=0;
            sprintf(num,"%ld",count); // makes int count into a string
            strcat(phoneNum,num); // adds num to the phoneNumber
            count=0; // reset the number count
            x++;
         } else {
            count++; // increment the number count
            status=1;
         }
         pulseCount=0;
      }


      // long delay before writing the AT command to GSM
      if( timer > 150000 && x > 0 ) {
         // add the final number
         count--;
         if(count > 9) // if the pulse count is 10 then this is actually a zero
            count=0;
         sprintf(num,"%ld",count); // makes int count into a string
         strcat(phoneNum,num); // adds num to the phoneNumber
         timer=0;
         x=0;     // reset number count
         count=0; // reset pulse count
         printf("%s;\r",phoneNum); // This is the AT command sent to the phone
         while(!input(PIN_A1)); // wait for on hook.
         return;

      }
      timer++;
   }

No comments:

Post a Comment