SHARE
TWEET

BlizzyB Firmware v2.4

weaknetlabs Sep 24th, 2014 (edited) 231 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Tone.h>
  2. #include <Keypad.h>
  3. // 2014 weaknetlabs@gmail.com BBv2.2 Hardware
  4. // fill stack with global variables:
  5. // firmware version 2.4
  6. //
  7. int bb[16][2] = { // MF 0,1,2,3,4,5,6,7,8,9,kp,st,2400+2600,kp2,st2,ss4 super
  8.   {1300,1500},{700,900},{700,1100},      // 0,1,2
  9.   {900,1100},{700,1300},{900,1300},      // 3,4,5
  10.   {1100,1300},{700,1500},{900,1500},     // 6,7,8
  11.   {1100,1500},{1100,1700},{1500,1700},   // 9,kp,st
  12.   {2600,2400},{1300,1700},{900,1700},    // 2400+2600,kp2,st2
  13.   {2400,2040},                           // ss4 Supervisory
  14. };
  15. int ss4[][4] = {
  16.   {0,1,0,1},{1,1,1,0},{1,1,0,1}, // 0,1,2
  17.   {1,1,0,0},{1,0,1,1},{1,0,1,0}, // 3,4,5
  18.   {1,0,0,1},{1,0,0,0},{0,1,1,1}, // 6,7,8
  19.   {0,1,1,0},{0,0,0,0},{0,1,0,0}, // 9,KP,OP11
  20.   {0,0,1,1},                     // OP12
  21. };
  22. uint8_t speedDial[][3] = { // Auto dial hold digits
  23.   {1,2,1},{1,0,1},{1,2,1}, // 0,1,2
  24.   {1,3,1},{1,4,1},{1,0,5}, // 3,4,5
  25.   {6,6,6},{1,0,7},{1,8,1}, // 6,7,8
  26.   {1,0,9}
  27. };
  28. uint8_t bbdur[2] = {60,100}; // 75 ms for MF tones, 120 for KP/ST
  29. int ss4Tone[2] = {2040,2400}; // tones for 0,1 respectively
  30. char keys[4][4] = {
  31.   {'1','2','3','a'},
  32.   {'4','5','6','b'},
  33.   {'7','8','9','c'},
  34.   {'#','0','*','d'}
  35. };
  36. byte rowPins[4] = {5,4,3,2}; //connect to the row pinouts of the keypad
  37. byte colPins[4] = {9,8,7,6}; //connect to the column pinouts of the keypad
  38. // global objects
  39. Tone freq[2]; // array of Tone objects, now we can play as freq[0].play(); etc
  40. Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,4,4);
  41. boolean rec = 0; // recording on/off
  42. boolean stored = 0; // stored digits?
  43. boolean autoDial = 0; // are we playing stored ANY didgits?
  44. boolean intern = false; // international trunk seizure
  45. boolean ss4Mode = false; // SS4 mode
  46. boolean pMode = false; // pulse mode
  47. // the storage of integers MUST be integers (int):
  48. int store[24] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
  49. // call set up function to set up pins:
  50. void setup(void){ // Start up instructions:
  51.   freq[0].begin(11); // Initialize our first tone generator
  52.   freq[1].begin(12); // Initialize our second tone generator
  53.   keypad.setHoldTime(1500); // hold for two seconds to change state to HOLD
  54.   pinMode(10, INPUT); // 2600 button
  55.   pinMode(13, OUTPUT); // LED for recording
  56.   keypad.addEventListener(procButton);
  57.   notify(); // boot successful
  58.   Serial.begin(9600);
  59. }
  60. // our main() function:
  61. void loop(void){ // Here we just get the button, pressed or held, and 2600 switch
  62.   char button = keypad.getKey(); // check for button press
  63.   if(digitalRead(10)==HIGH){ // play 2600Hz if top button pressed
  64.     super(); // supervisory signalling
  65.   }
  66.   return; // end main()
  67. }
  68. // Supervisory (TOP) button
  69. void super(void){
  70.   if(intern){ // international seizure of trunk
  71.     mf(12);
  72.     delay(1337);
  73.     sf(2400,750);
  74.   }else if(ss4Mode){ // SS4 Supervisory Signal
  75.     mf(15);
  76.     delay(150);
  77.     sf(2040,350);
  78.   }else{ // non international
  79.     sf(2600,750);
  80.   }
  81.   return;
  82. }
  83. // Process buttons:
  84. void procButton(KeypadEvent b){
  85.   b -= 48;
  86.   switch (keypad.getState()){
  87.     case RELEASED: // drop right away
  88.       return;
  89.     case PRESSED: // momentary
  90.       if(ss4Mode){ // Signal Switching 4
  91.         ss4Signal(b);
  92.         break;
  93.       }else if(pMode){
  94.         pulse(b); // pulse it
  95.         return;
  96.       }
  97.       if(b<10&&b>=0||b==-13||b==-6){ // MF tone
  98.         mf(b);
  99.       }else if(b==52){ // D
  100.         if (stored) playStored(); // don't copy function onto stack if not needed
  101.         return;
  102.       }else if(intern&&b==49||intern&&b==50||intern&&b==51){
  103.          mf(b);
  104.          return;
  105.       }
  106.       else if(b<=51&&b>=49){ // A,B,C redbox
  107.         redBox(b); // pass it to RedBox()
  108.         return;
  109.       }
  110.       break;
  111.     case HOLD: // HELD (special functions)
  112.       if(b<10&&b>=0||b==-13||b==-6){
  113.         dial(b);
  114.       }else if(b==51){ // C takes care of recording now
  115.         if(rec){ // we are done recording:
  116.           digitalWrite(13, LOW); // turn off LED
  117.           rec = 0;
  118.           stored=1; // we have digits stored
  119.           recNotify();
  120.         }else{ // we start recording
  121.           digitalWrite(13, HIGH); // light up LED
  122.           rec = 1;
  123.           for(int i=0;i<=23;i++){ // reset array
  124.             store[i] = -1;
  125.           }
  126.           recNotify();
  127.         } // END recording code
  128.       }else if(b==49){ // ('A' HELD) switching any mode "on" changes to mode, all "off" is domestic
  129.         if(intern){ // international to ss4 mode
  130.           intern = false;
  131.           ss4Mode = true;
  132.         }else if(ss4Mode){ // ss4 mode to pulse mode
  133.           ss4Mode = false;
  134.           pMode = true;
  135.         }else if(pMode){ // pulse mode to domestic
  136.           pMode = false;
  137.         }else{ // domestic to international mode
  138.           intern = true;
  139.         }
  140.         notifyMode();
  141.       }      
  142.       break;
  143.   }
  144.   return;
  145. }
  146. // pulse mode
  147. void pulse(int signal){
  148.   if(signal>9) { return; }
  149.   if(signal==-13||signal==-6){
  150.     return;
  151.   }else{
  152.     if(signal==0){ signal = 10; }
  153.     for(int i=0;i<signal;i++){
  154.       digitalWrite(13, HIGH); // pulsing LED
  155.       freq[0].play(2600,66);
  156.       delay(66);
  157.       digitalWrite(13, LOW);
  158.       delay(34);
  159.     }
  160.     delay(500); // no new digit accepted until after this time
  161.   }
  162.   return;
  163. }
  164. // play stored tones
  165. void playStored(void){
  166.   if(stored){
  167.     autoDial = 1;
  168.     for(int i=0;i<=23;i++){
  169.       if(store[i]==-1){
  170.         return;
  171.       }else{
  172.         mf(store[i]);  
  173.       }    
  174.     }  
  175.   }else{
  176.     return;
  177.   }
  178.   autoDial = 0; // turn off playing
  179.   return;
  180. }
  181. // Record Notification tone:
  182. void recNotify(void){
  183.   if(rec){
  184.     sf(1700,66);
  185.     delay(66);
  186.     sf(2200,500);
  187.     delay(500);
  188.   }else{
  189.     sf(2200,66);
  190.     delay(66);
  191.     sf(1700,500);
  192.     delay(500);  
  193.   }
  194.   return;
  195. }
  196. // Mode notification
  197. void notifyMode(){
  198.   int count = 1;
  199.   int dur = 70;
  200.   int frequency = 440;
  201.   if(intern){ count = 2; }
  202.   if(ss4Mode){ count = 3; }
  203.   if(pMode){ count = 4; }
  204.  Serial.println(count);
  205.   for(int i = 0;i<count;i++){
  206.     freq[0].play(frequency,dur);
  207.     delay(dur*2);
  208.   }
  209. }
  210.  
  211. // Notification Tone:
  212. void notify(void){
  213.   for(int i=0;i<=2;i++){
  214.     freq[0].play(2600,33);
  215.     delay(66);
  216.   }
  217.   delay(500);
  218.   return;
  219. }
  220. // SS4 signalling:
  221. void ss4Signal(int signal){
  222.   Serial.println(signal);
  223.   if(signal==49){ // A  
  224.     mf(15);
  225.     delay(150);
  226.     sf(2400,350);
  227.     return;
  228.   }
  229.   if(signal==50){// B
  230.     signal==11;
  231.   }
  232.   if(signal==51){ // C
  233.     signal==12;
  234.   }
  235.   if(signal==52){ // D
  236.     sf(2600,750);
  237.     return;
  238.   }
  239.  if(signal==-13){ signal = 10; }
  240.  if(signal==-6){ //
  241.   super();
  242.   return;
  243.  }
  244.  for(int i=0;i<=3;i++){
  245.    (ss4[signal][i]) ? freq[0].play(ss4Tone[1],35) : freq[0].play(ss4Tone[0],35);
  246.    delay(70);
  247.  }
  248.  return;
  249. }
  250. // play an MF tone:
  251. void mf(int digit){ // Store the digit IFF recording:
  252. Serial.println(digit);
  253.   if(rec && ((digit>=0&&digit<=9)||digit==-13||digit==-6)){
  254.     for(int i=0;i<=23;i++){ // ONLY record KP,ST,0-9
  255.       if(store[i]==-1){
  256.         store[i]=digit;
  257.         break;
  258.       }
  259.     }
  260.   }
  261.   int duration = bbdur[0];
  262.   if(intern){
  263.     if(digit==49){
  264.       digit=13;
  265.     }
  266.     if(digit==50){
  267.       digit=14;
  268.     }
  269.     if(digit==51){
  270.      sf(2600,1000);
  271.      return;
  272.     }
  273.   }
  274.   if(digit<0){
  275.     duration = bbdur[1];
  276.     if(digit==-13){ digit=10; }
  277.     if(digit==-6){ digit=11; }
  278.   }
  279.   if(digit==-1){ return; } // -1 in storage?
  280.   if(digit==12){ // 85ms for international trunk seizing
  281.     duration = 200;
  282.   }
  283.   if (ss4Mode) duration = 150;
  284.   freq[0].play(bb[digit][0],duration);
  285.   freq[1].play(bb[digit][1],duration);
  286.   (autoDial) ? delay(duration + 60) : delay(duration); // ? expression? statement?
  287.   if(rec){
  288.     delay(25);
  289.     sf(2600,33);
  290.   }// chirp to signify recording
  291.   return; // Now we can leave.
  292. }
  293. // play SF:
  294. void sf(int frequency,int duration){ // play single frequency
  295.   freq[0].play(frequency,duration);
  296.   return;
  297. }
  298. // play red box tones:
  299. void redBox(int coin){ // pass me a button
  300.   int iter;
  301.   int delayMs = 66;
  302.   int rb[2] = {1700,2200};
  303.   switch(coin){
  304.     case 49:
  305.       iter = 5;
  306.       delayMs = 33;
  307.       break;
  308.     case 50:
  309.       iter = 2;
  310.       break;
  311.     case 51:
  312.       iter = 1;
  313.       break;
  314.   }
  315.   for(int i=0;i<iter;i++){
  316.     freq[0].play(rb[0],delayMs);
  317.     freq[1].play(rb[1],delayMs);
  318.     delay(delayMs * 2); // pause for coin and between
  319.   }
  320. }
  321. // play speed dials
  322. void dial(int sd){ // speed dial
  323.   if(rec) return; // we are recording...
  324.   autoDial = 1; // turn on for pauses
  325.   sf(2600,750); // play 2600 1 sec
  326.   delay(2000); // pause
  327.   mf(-13); // KP
  328.   for(int i=0;i<=2;i++){
  329.       mf(speedDial[sd][i]);
  330.   }
  331.   mf(-6); // ST
  332.   autoDial = 0; // turn off pauses
  333.   return;
  334. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top