コード例 #1
0
ファイル: receiveserial.c プロジェクト: skitt/sysd7
void main (void)
{
  int i;
  serialinit ();
  for (i = 0; i < 21000; i++)
    putchar (serialreceive ());
  serialclose ();
}
コード例 #2
0
ファイル: soundbounce.c プロジェクト: skitt/sysd7
void main()
{
  serialinit();
  serialtransmit('a');
  serialreceive();
  mon_putc('A');
  while(1)
    serialtransmit(serialreceive());
}
コード例 #3
0
ファイル: rxraw.c プロジェクト: skitt/sysd7
void main()
{
  int i;
  serialinit();
  for (i=0; i<24000;i++) {
    Incoming[i]=serialreceive();
  }
  for (i=0;i<24000;i++) {
    putchar(Incoming[i]);
  }

}
コード例 #4
0
ファイル: inttest2.c プロジェクト: skitt/sysd7
void main (void)
{
  int i;
  int s = 120;
  serialinit ();
  pkt.datatype = 2;
  pkt.data = "This is a longer version of the test string, to see how the serial copes with\n\rmore data\n\r";
  pkt.length = 0;
  while (pkt.data [pkt.length])
    pkt.length++;
  pkt.length++;
  for (i = 0; i < 1; i++)
    senddata (&pkt);
  serialclose ();
}
コード例 #5
0
ファイル: audio.c プロジェクト: skitt/sysd7
int state10(void)
{
  unsigned char RecBuf[2];
  char v=1;
  int otime,ctime;
  unsigned char Data_next;
  int Control=0;
  serialinit();
  initAudio();
  initCompr();
  
  /* Synch with PC... */
  serialtransmit('A');
  otime=10000000;
  starttimer(SAMPLE_DELAY);
  ctime=gettimer();
  while ( otime > ctime ) {
    otime=ctime;
    ctime=gettimer();
  }
  RecBuf[0] = (getsample());
  otime=1000;
  while (1) {
    /*starttimer(SAMPLE_DELAY);*/
    while ( otime > (otime= gettimer() > 0) );
    RecBuf[v] = (getsample());
    if (v) {
      Control = compress(RecBuf[0],RecBuf[1]);
    } else {
      Control = serialtransmit(Control);
      if (Control) {
	serialclose();
	return Control;
      }
    }
    v=1-v;
  }
}
コード例 #6
0
ファイル: main.c プロジェクト: tcauchois/Syzycubes
int main(void)
{
  //LEDs
  uint16_t hue = 0, brightness = BRI_LIMIT - 1, lastBrightness = brightness;
  //motion 
  int16_t oldaccel[3], rawoldaccel[3], accel[3] = {0}, rawaccel[3] = {0};
  int32_t dotp[3];
  double flt_div, flt_acos;
  int8_t int_acos;
  //microphone
  uint32_t histPower[HIST_SIZE] = {0}, histPowerIndex = 0;
  uint32_t currentPower, avgPower = 0;
  double scale;
  //idle
  uint16_t idleIters = 0, idleActivity = 0;
  uint8_t idleMinutes = 0;

  // Initialize io ports
  ioinit();

  // Initialize serial
  serialinit();
  stdout = &mystdout;

  // print banner/battery check
  banner();

  // Initialize the timer
  timerinit();

  // Initialize audio capture
  audioinit();

  // Initialize accelerometer
  accelinit();

  // Enable interrupts
  sei();

  while(1)
  {
    // Wait until audio sample is ready
    while(!curAudioPowerReady) {}
    curAudioPowerReady = 0;

    // Grab the current audio power
    currentPower = curAudioPower;

    //Read accelerometer, determine hue
    oldaccel[0] = accel[0]; oldaccel[1] = accel[1]; oldaccel[2] = accel[2];
    rawoldaccel[0] = rawaccel[0]; rawoldaccel[1] = rawaccel[1]; rawoldaccel[2] = rawaccel[2];
    adxl345_getxyz(&rawaccel[0], &rawaccel[1], &rawaccel[2]);
    //(lowpass filter the accelerometer data)
    accel[0] = (rawoldaccel[0] + rawaccel[0]) / 2;
    accel[1] = (rawoldaccel[1] + rawaccel[1]) / 2;
    accel[2] = (rawoldaccel[2] + rawaccel[2]) / 2;
    //theta = acos(a.b / |a||b|)
    dotp[0] = accel[0] * oldaccel[0] + accel[1] * oldaccel[1] + accel[2] * oldaccel[2];
    dotp[1] = accel[0] * accel[0] + accel[1] * accel[1] + accel[2] * accel[2];
    dotp[2] = oldaccel[0] * oldaccel[0] + oldaccel[1] * oldaccel[1] + oldaccel[2] * oldaccel[2];
    if(dotp[1] == 0) dotp[1] = 1;
    if(dotp[2] == 0) dotp[2] = 1;
    flt_div = dotp[0] / (sqrt(dotp[1]) * sqrt(dotp[2]));
    flt_acos = acos(flt_div);
    int_acos = (int8_t)(flt_acos * 180 / M_PI);

    //the amount of motion varies pretty widely; it seems like the best
    //aesthetic results are from motion-triggering
    if(int_acos > 15)
    {
      hue += 15;
      idleActivity++;
    }
    if(hue >= HUE_LIMIT) hue -= HUE_LIMIT;

    //determine intensity (sliding scale)
    avgPower -= histPower[histPowerIndex];
    histPower[histPowerIndex] = currentPower;
    avgPower += histPower[histPowerIndex];
    histPowerIndex++;
    if(histPowerIndex >= HIST_SIZE) histPowerIndex = 0;

    //scale should vary between 0.5ish and 1.5ish... clamp to [0,1]
    scale = (float)(currentPower * HIST_SIZE) / avgPower;
    scale -= 0.5;
    if(scale > 1.0) scale = 1.0;
    if(scale < 0.0) scale = 0.0;
    //perception mapping: y=x^4 to give it a concave shape
    scale = scale*scale*scale*scale;
    brightness = BRI_MIN + (BRI_MAX-BRI_MIN) * scale;
    if(brightness < lastBrightness)
      brightness = (brightness + lastBrightness) / 2;
    lastBrightness = brightness;

    //Update LED colors
    send_hsb(hue, SATURATION, brightness);

    //Handle console
    dispatch_console();

    // Idle check
    idleIters++;
    if(idleIters >= ITERS_PER_MINUTE) {
      if(idleActivity >= IDLE_ACTIVITY_THRESHOLD) {
        // Activity!!!  Reset idle minutes
        idleMinutes = 0;
      } else {
        // Not enough activity, mark minute as idle
        idleMinutes++;
      }

      // Shutdown if idle for too long
      if(idleMinutes >= IDLE_MINUTES_UNTIL_SHUTDOWN) {
        shutdown(0);
      }

      // Reset iteration counts
      idleIters = 0;
      idleActivity = 0;
    }

    // Idle backstop check
    if(get_ticks() >= MINUTES_UNTIL_SHUTDOWN * 60) {
      shutdown(0);
    }
  }
}