Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 21st, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. int getDominantDriveState(int period) {
  2.   int cdRgt_ttl = 0;  
  3.   int cdLft_ttl = 0;  
  4.   int cdStp_ttl = 0;  
  5.   int cdFwd_ttl = 0;  
  6.   int cdRev_ttl = 0;
  7.   int result;
  8.   int result_max;
  9.  
  10.   for (int i = 0; i < constrain(period,1,driveArrayLength) ; i++) {
  11.     switch (drive[i]) {
  12.     case cdRgt:
  13.       cdRgt_ttl++;
  14.     case cdLft:
  15.       cdLft_ttl++;
  16.     case cdRev:
  17.       cdRev_ttl++;
  18.     case cdFwd:
  19.       cdFwd_ttl++;
  20.     case cdStp:
  21.       cdStp_ttl++;
  22.     }
  23.   }
  24.   //count the results and see which state is dominant for the specified period
  25.   result_max = cdRgt_ttl;
  26.   result = cdRgt;
  27.  
  28.   if (cdLft_ttl > result_max) {
  29.     result = cdLft;
  30.   }
  31.   if (cdStp_ttl > result_max) {
  32.     result = cdStp;
  33.   }
  34.   if (cdFwd_ttl > result_max) {
  35.     result = cdFwd;
  36.   }
  37.   if (cdRev_ttl > result_max) {
  38.     result = cdRev;
  39.   }
  40.  
  41.   return result;
  42. }