Exemple #1
0
void banner()
{
  //console banner
  printf_P(PSTR("Syzygryd Memorial Cube Firmware.  Hello!\n"));

  //give the user a visual indication of battery health...
  uint8_t bat = get_battery_percent();
  if(bat == 0) {
    lowbat();
  } else {
    // Show the battery level
    send_rgb(100 - bat, bat, 0);
    _delay_ms(1000);
    send_rgb(0, 0, 0);
  }
}
Exemple #2
0
void main(void)
{
	struct device *gpio_dev;
	int ret;
	int idx = 0;
	int leds = 0;

	gpio_dev = device_get_binding(GPIO_DRV_NAME);
	if (!gpio_dev) {
		printk("Cannot find %s!\n", GPIO_DRV_NAME);
		return;
	}

	/* Setup GPIO output */
	ret = gpio_pin_configure(gpio_dev, GPIO_DATA_PIN, (GPIO_DIR_OUT));
	if (ret) {
		printk("Error configuring " GPIO_NAME "%d!\n", GPIO_DATA_PIN);
	}

	ret = gpio_pin_configure(gpio_dev, GPIO_CLK_PIN, (GPIO_DIR_OUT));
	if (ret) {
		printk("Error configuring " GPIO_NAME "%d!\n", GPIO_CLK_PIN);
	}

	while (1) {
		send_rgb(gpio_dev, APA102C_START_FRAME);

		for (leds = 0; leds < NUM_LEDS; leds++) {
			send_rgb(gpio_dev, rgb[(idx + leds) % NUM_RGB]);
		}

		/* If there are more LEDs linked together,
		 * then what NUM_LEDS is, the NUM_LEDS+1
		 * LED is going to be full bright.
		 */
		send_rgb(gpio_dev, APA102C_END_FRAME);

		idx++;
		if (idx >= NUM_RGB) {
			idx = 0;
		}

		k_sleep(SLEEPTIME);
	}
}
Exemple #3
0
char ledCmdRgb(char *arg)
{
  unsigned long r,g,b;
  r = strtoul(arg, &arg, 16);
  g = strtoul(arg, &arg, 16);
  b = strtoul(arg, &arg, 16);

  printf_P(PSTR("Setting LEDs (0x%lx, 0x%lx, 0x%lx)\n"), r, g, b);
  send_rgb((uint16_t)r, (uint16_t)g, (uint16_t)b);
  return 0;
}
Exemple #4
0
//blink LEDs and turn off (in case of low battery)
void lowbat()
{
  send_rgb(100, 0, 0);
  _delay_ms(200);
  send_rgb(0, 0, 0);
  _delay_ms(200);
  send_rgb(100, 0, 0);
  _delay_ms(200);
  send_rgb(0, 0, 0);
  _delay_ms(200);
  send_rgb(100, 0, 0);
  _delay_ms(200);
  send_rgb(0, 0, 0);
  shutdown(1);
}
Exemple #5
0
void shutdown(int forever)
{
  // Turn off the LEDs
  send_rgb(0,0,0);

  // Reset the ADXL threshold level
  adxl345_write(THRESH_ACT, 50); // Threshold to detect activity

  // If we don't want to turn back on turn off the accelerometer
  if(forever)
    adxl345_write(POWER_CTL, 0);

  // Loop until we die
  while(1)
  {
    // Read the ADXL interrupts to clear out PWR_EN_ADXL
    adxl345_read(INT_SOURCE);

    // Lower the power latch (PWR_EN_CPU)
    PORTC &= ~(_BV(PORTC4));

    _delay_ms(5000);
  }
}