コード例 #1
0
ファイル: pattern_maze.cpp プロジェクト: moonfall/lush
bool Pattern_maze::display()
{
    int now = millis();
    int t = now - m_start_time;

    bool all_done = true;
    for (int y = 0; y < ROW_COUNT; ++y) {
	for (int x = 0; x < COLUMN_COUNT; ++x) {
	    bool done = false;
	    draw_pixel(x, y, m_fader.generate(get_led(x, y), t, &done));
	    if (!done) {
		all_done = false;
	    }
	}
    }

    if (all_done) {
	regenerate(); 
    }

    return true;
#if 0
    int now = millis();
    if (m_finished_ms) {
	if (now > m_finished_ms + RESET_MS) {
	    m_maze.reset();
	    m_update_ms = now;
	    m_finished_ms = 0;
	}
    } else if (now > m_update_ms + UPDATE_MS) {
	// Try to expand and record what happened.
	if (m_maze.expand()) {
	    m_update_ms = now;
	} else {
	    m_finished_ms = now;
	}
    }

    for (int y = 0; y < ROW_COUNT; ++y) {
	for (int x = 0; x < COLUMN_COUNT; ++x) {
	    int index = get_led(x, y);
	    int order = m_maze.get_order(index);
	    int hue = g_hue.get();
	    Colour c = COLOUR_BLACK;
	    if (order) {
		c = make_hue(hue + HUE_OFFSET * order);
	    }
#ifdef SHOW_POSSIBILITES
	    if (m_maze.in_wall_list(index)) {
		c = make_hue(hue + 50);
	    }
#endif
	    draw_pixel(index, c);
	}  
    }

    return true;
#endif
}
コード例 #2
0
ファイル: fireworks.cpp プロジェクト: neilagabriel/arduino
void fireworks()
{
    long startTime, duration;
    struct LED led;

    for (int c = 0; c <= NUM_LEDS; c++)
    {
        led = get_led(pattern1[c].x, 
                      pattern1[c].y,
                      pattern1[c].z);

        led_on(led);
        delay(250);
        led_off(led);
    }

    for (duration = 0, startTime = millis(); 
         duration < 1500; 
         duration = millis() - startTime)
    {
        char x = 2 + (rand() % 2);
        char y = 2 + (rand() % 2);
        char z = 2 + (rand() % 2);

        led = get_led(x, y, z);
        led_on(led);
        delay(15);
        led_off(led);
    }

    for (int c = 0; c <= NUM_LEDS; c++)
    {
        led = get_led(pattern2[c].x, 
                      pattern2[c].y,
                      pattern2[c].z);

        led_on(led);
        delay(250);
        led_off(led);
    }

    for (duration = 0, startTime = millis(); 
         duration < 1500; 
         duration = millis() - startTime)
    {
        char x = 2 + (rand() % 2);
        char y = rand() % 2;
        char z = 2 + (rand() % 2);

        led = get_led(x, y, z);
        led_on(led);
        delay(15);
        led_off(led);
    }
}
コード例 #3
0
ファイル: tb0219.c プロジェクト: 03199618/linux
static ssize_t tanbac_tb0219_read(struct file *file, char __user *buf, size_t len,
                                  loff_t *ppos)
{
	unsigned int minor;
	char value;

	minor = iminor(file_inode(file));
	switch (minor) {
	case 0:
		value = get_led();
		break;
	case 16 ... 23:
		value = get_gpio_input_pin(minor - 16);
		break;
	case 32 ... 39:
		value = get_gpio_output_pin(minor - 32);
		break;
	case 48 ... 55:
		value = get_dip_switch(minor - 48);
		break;
	default:
		return -EBADF;
	}

	if (len <= 0)
		return -EFAULT;

	if (put_user(value, buf))
		return -EFAULT;

	return 1;
}
コード例 #4
0
ファイル: chatpad.cpp プロジェクト: mrj10/xboxdrv
void
Chatpad::process(const ChatpadKeyMsg& msg)
{
  // save old state
  boost::array<bool, 256> old_state = m_state;
  
  // generate new state
  std::fill(m_state.begin(), m_state.end(), 0);

  m_state[CHATPAD_MOD_PEOPLE] = msg.modifier & CHATPAD_MOD_PEOPLE;
  m_state[CHATPAD_MOD_ORANGE] = msg.modifier & CHATPAD_MOD_ORANGE;
  m_state[CHATPAD_MOD_GREEN]  = msg.modifier & CHATPAD_MOD_GREEN;
  m_state[CHATPAD_MOD_SHIFT]  = msg.modifier & CHATPAD_MOD_SHIFT;

  if (msg.scancode1) m_state[msg.scancode1] = true;
  if (msg.scancode2) m_state[msg.scancode2] = true;

  // check for changes
  for(size_t i = 0; i < m_state.size(); ++i)
  {
    if (m_state[i] != old_state[i])
    {
      if (m_state[i])
      {
        if (i == CHATPAD_MOD_PEOPLE)
        {
          set_led(CHATPAD_LED_PEOPLE, !get_led(CHATPAD_LED_PEOPLE));
        }
        else if (i == CHATPAD_MOD_ORANGE)
        {
          set_led(CHATPAD_LED_ORANGE, !get_led(CHATPAD_LED_ORANGE));
        }
        else if (i == CHATPAD_MOD_GREEN)
        {
          set_led(CHATPAD_LED_GREEN, !get_led(CHATPAD_LED_GREEN));
        }
        else if (i == CHATPAD_MOD_SHIFT)
        {
          set_led(CHATPAD_LED_SHIFT, !get_led(CHATPAD_LED_SHIFT));
        }
      }

      m_uinput->send(EV_KEY, m_keymap[i], m_state[i]);
    }
  }
  m_uinput->sync();
}
コード例 #5
0
ファイル: pattern_maze.cpp プロジェクト: moonfall/lush
void Pattern_maze::randomize_image(bool initial)
{
    int start = millis();
    int x_offset = random(1, 10);
    int y_offset = random(10, 100);
    for (int y = 0; y < ROW_COUNT; ++y) {
	for (int x = 0; x < COLUMN_COUNT; ++x) {
	    int wheel = start + x * x_offset + y * y_offset;
	    int order = m_maze.get_order(get_led(x, y));
	    m_fader.set_colour(initial, get_led(x, y),
			       order ?
			       make_wheel(wheel, g_brightness.get()) :
			       COLOUR_BLACK);
	}
    }
    m_fader.set_colours(!initial, COLOUR_BLACK);
}
コード例 #6
0
ファイル: led.cpp プロジェクト: neilagabriel/arduino
void coordinate_on_multiple(struct COORDINATE coords[], int num_coords)
{
    struct COORDINATE c;
    struct LED l;

    for (int i = 0; i < num_coords; i++)
    {
        c = coords[i];
        l = get_led(c.x, c.y, c.z);

        led_on(l);
        delayMicroseconds(100);
        led_off(l);
    }
}
コード例 #7
0
ファイル: ipt_LED.c プロジェクト: robacklin/uclinux-linux
static unsigned int
ipt_led_target(struct sk_buff **pskb,
	       unsigned int hooknum,
	       const struct net_device *in,
	       const struct net_device *out,
	       const void *targinfo,
	       void *userinfo)
{
	const struct ipt_led_info *ledinfo = targinfo;
	u_int32_t led;

	led = get_led(pskb, ledinfo);
#ifdef CONFIG_LEDMAN
	if (led < LEDMAN_MAX)
		ledman_cmd(LEDMAN_CMD_SET, led);
#endif

	return IPT_CONTINUE;
}
コード例 #8
0
bool
Xbox360WirelessController::parse(uint8_t* data, int len, XboxGenericMsg* msg_out)
{
  if (len == 0)
  {
    return false;
  }
  else
  {
    if (len == 2 && data[0] == 0x08)
    { // Connection Status Message
      if (data[1] == 0x00) 
      {
        log_info("connection status: nothing");

        // reset the controller into neutral position on disconnect
        memset(msg_out, 0, sizeof(*msg_out));
        set_active(false);

        return true;
      }
      else if (data[1] == 0x80) 
      {
        log_info("connection status: controller connected");
        set_led(get_led());
        set_active(true);
      } 
      else if (data[1] == 0x40) 
      {
        log_info("Connection status: headset connected");
      }
      else if (data[1] == 0xc0) 
      {
        log_info("Connection status: controller and headset connected");
        set_led(get_led());
      }
      else
      {
        log_info("Connection status: unknown");
      }
    }
    else if (len == 29)
    {
      set_active(true);

      if (data[0] == 0x00 && data[1] == 0x0f && data[2] == 0x00 && data[3] == 0xf0)
      { // Initial Announc Message
        m_serial = (boost::format("%2x:%2x:%2x:%2x:%2x:%2x:%2x")
                  % int(data[7])
                  % int(data[8])
                  % int(data[9])
                  % int(data[10])
                  % int(data[11])
                  % int(data[12])
                  % int(data[13])).str();
        m_battery_status = data[17];
        log_info("Serial: " << m_serial);
        log_info("Battery Status: " << m_battery_status);
      }
      else if (data[0] == 0x00 && data[1] == 0x01 && data[2] == 0x00 && data[3] == 0xf0 && data[4] == 0x00 && data[5] == 0x13)
      { // Event message
        msg_out->type = XBOX_MSG_XBOX360;
        Xbox360Msg& msg = msg_out->xbox360;

        uint8_t* ptr = data+4;

        msg.type   = ptr[0];
        msg.length = ptr[1];

        msg.dpad_up    = unpack::bit(ptr+2, 0);
        msg.dpad_down  = unpack::bit(ptr+2, 1);
        msg.dpad_left  = unpack::bit(ptr+2, 2);
        msg.dpad_right = unpack::bit(ptr+2, 3);

        msg.start   = unpack::bit(ptr+2, 4);
        msg.back    = unpack::bit(ptr+2, 5);
        msg.thumb_l = unpack::bit(ptr+2, 6);
        msg.thumb_r = unpack::bit(ptr+2, 7);

        msg.lb     = unpack::bit(ptr+3, 0);
        msg.rb     = unpack::bit(ptr+3, 1);
        msg.guide  = unpack::bit(ptr+3, 2);
        msg.dummy1 = unpack::bit(ptr+3, 3);

        msg.a = unpack::bit(ptr+3, 4);
        msg.b = unpack::bit(ptr+3, 5);
        msg.x = unpack::bit(ptr+3, 6);
        msg.y = unpack::bit(ptr+3, 7);

        msg.lt = ptr[4];
        msg.rt = ptr[5];

        msg.x1 = unpack::int16le(ptr+6);
        msg.y1 = unpack::int16le(ptr+8);

        msg.x2 = unpack::int16le(ptr+10);
        msg.y2 = unpack::int16le(ptr+12);

        msg.dummy2 = unpack::int32le(ptr+14);
        msg.dummy3 = unpack::int16le(ptr+18);

        return true;
      }
      else if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0x13)
      { // Battery status
        m_battery_status = data[4];
        log_info("battery status: " << m_battery_status);
      }
      else if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0xf0)
      {
        // 0x00 0x00 0x00 0xf0 0x00 ... is send after each button
        // press, doesn't seem to contain any information
      }
      else
      {
        log_debug("unknown: " << raw2str(data, len));
      }
    }
    else
    {
      log_debug("unknown: " << raw2str(data, len));
    }
  }

  return false; 
}
コード例 #9
0
ファイル: led.cpp プロジェクト: neilagabriel/arduino
void coordinate_off(struct COORDINATE c)
{
    struct LED l = get_led(c.x, c.y, c.z);
    led_off(l);
}
コード例 #10
0
bool
Xbox360WirelessController::parse(const uint8_t* data, int len, ControllerMessage* msg_out)
{
  if (len == 0)
  {
    return false;
  }
  else
  {
    if (len == 2 && data[0] == 0x08)
    { // Connection Status Message
      if (data[1] == 0x00) 
      {
        log_info("connection status: nothing");

        // reset the controller into neutral position on disconnect
        msg_out->clear();
        set_active(false);

        return true;
      }
      else if (data[1] == 0x80) 
      {
        log_info("connection status: controller connected");
        set_led_real(get_led());
        set_active(true);
      } 
      else if (data[1] == 0x40) 
      {
        log_info("Connection status: headset connected");
      }
      else if (data[1] == 0xc0) 
      {
        log_info("Connection status: controller and headset connected");
        set_led_real(get_led());
      }
      else
      {
        log_info("Connection status: unknown");
      }
    }
    else if (len == 29)
    {
      set_active(true);

      if (data[0] == 0x00 && data[1] == 0x0f && data[2] == 0x00 && data[3] == 0xf0)
      { // Initial Announc Message
        m_serial = (boost::format("%2x:%2x:%2x:%2x:%2x:%2x:%2x")
                    % int(data[7])
                    % int(data[8])
                    % int(data[9])
                    % int(data[10])
                    % int(data[11])
                    % int(data[12])
                    % int(data[13])).str();
        m_battery_status = data[17];
        log_info("Serial: " << m_serial);
        log_info("Battery Status: " << m_battery_status);
      }
      else if (data[0] == 0x00 && data[1] == 0x01 && data[2] == 0x00 && data[3] == 0xf0 && data[4] == 0x00 && data[5] == 0x13)
      { // Event message
        const uint8_t* ptr = data + 4;

        msg_out->set_key(xbox.dpad_up,    unpack::bit(ptr+2, 0));
        msg_out->set_key(xbox.dpad_down,  unpack::bit(ptr+2, 1));
        msg_out->set_key(xbox.dpad_left,  unpack::bit(ptr+2, 2));
        msg_out->set_key(xbox.dpad_right, unpack::bit(ptr+2, 3));

        msg_out->set_key(xbox.btn_start,   unpack::bit(ptr+2, 4));
        msg_out->set_key(xbox.btn_back,    unpack::bit(ptr+2, 5));
        msg_out->set_key(xbox.btn_thumb_l, unpack::bit(ptr+2, 6));
        msg_out->set_key(xbox.btn_thumb_r, unpack::bit(ptr+2, 7));

        msg_out->set_key(xbox.btn_lb, unpack::bit(ptr+3, 0));
        msg_out->set_key(xbox.btn_rb, unpack::bit(ptr+3, 1));
        msg_out->set_key(xbox.btn_guide, unpack::bit(ptr+3, 2));
        //msg_out->dummy1 = unpack::bit(ptr+3, 3);

        msg_out->set_key(xbox.btn_a, unpack::bit(ptr+3, 4));
        msg_out->set_key(xbox.btn_b, unpack::bit(ptr+3, 5));
        msg_out->set_key(xbox.btn_x, unpack::bit(ptr+3, 6));
        msg_out->set_key(xbox.btn_y, unpack::bit(ptr+3, 7));

        msg_out->set_abs(xbox.abs_lt, ptr[4]);
        msg_out->set_abs(xbox.abs_rt, ptr[5]);

        msg_out->set_abs(xbox.abs_x1, unpack::int16le(ptr+6));
        msg_out->set_abs(xbox.abs_y1, unpack::s16_invert(unpack::int16le(ptr+8)));

        msg_out->set_abs(xbox.abs_x2, unpack::int16le(ptr+10));
        msg_out->set_abs(xbox.abs_y2, unpack::s16_invert(unpack::int16le(ptr+12)));

        return true;
      }
      else if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0x13)
      { // Battery status
        m_battery_status = data[4];
        log_info("battery status: " << m_battery_status);
      }
      else if (data[0] == 0x00 && data[1] == 0x00 && data[2] == 0x00 && data[3] == 0xf0)
      {
        // 0x00 0x00 0x00 0xf0 0x00 ... is send after each button
        // press, doesn't seem to contain any information
      }
      else
      {
        log_debug("unknown: " << raw2str(data, len));
      }
    }
    else
    {
      log_debug("unknown: " << raw2str(data, len));
    }
  }

  return false; 
}