示例#1
0
文件: main.c 项目: adlerweb/RGB-CTL
void i2c_process(void) {
        //###Process incoming I²C-Data###

        //Target Colors
        if(twibuffer[0]<=170) target[0] = twibuffer[0];
        if(twibuffer[1]<=170) target[1] = twibuffer[1];
        if(twibuffer[2]<=170) target[2] = twibuffer[2];

        //Fade type
        fade[0] = twibuffer[3];
        fade[1] = twibuffer[4];
        fade[2] = twibuffer[5];

        //###Write new values to twibuffer so we can read current status###
        twibuffer[6] = color[0];
        twibuffer[7] = color[1];
        twibuffer[8] = color[2];

        twibuffer[9] = LOW_BYTE(colort[0]);
        twibuffer[10] = HIGH_BYTE(colort[0]);
        twibuffer[11] = LOW_BYTE(colort[1]);
        twibuffer[12] = HIGH_BYTE(colort[1]);
        twibuffer[13] = LOW_BYTE(colort[2]);
        twibuffer[14] = HIGH_BYTE(colort[2]);
}
示例#2
0
文件: create.c 项目: CBCJVM/cbc
// script to rotate in place through deg degrees
// deg > 0 turn CCW; deg < 0 turn CW
void create_script_turn(int deg, int speed) { // degrees, vel in mm/sec
	CREATE_BUSY;
	create_write_byte(152); // start script
	create_write_byte(17);  // script length
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 0
	create_write_byte(137); // move 
	create_write_byte(HIGH_BYTE(speed));
	create_write_byte(LOW_BYTE(speed));
	if (deg > 0){ // CCW case 
		create_write_byte(0); 
	create_write_byte(1); }
	else { // CW case
		create_write_byte(255);
	create_write_byte(255); }
	create_write_byte(157); // wait for angle done
	create_write_byte(HIGH_BYTE(deg));
	create_write_byte(LOW_BYTE(deg));
	create_write_byte(137); // stop move 
	create_write_byte(0);   // no speed
	create_write_byte(0);
	create_write_byte(0);   // no angle
	create_write_byte(0);   
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 1
	// end of script
	create_write_byte(153); // run script
	CREATE_FREE;
}
示例#3
0
文件: create.c 项目: CBCJVM/cbc
// script to trace an arc of radius rad until deg is reach
// NOTE: if the turn is not in the direction of deg, the arc won't end
void create_script_arc(int rad, int deg, int speed) { // rad in mm, degrees, vel in mm/sec
	CREATE_BUSY;
	create_write_byte(152); // start script
	create_write_byte(17);  // script length
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 0
	create_write_byte(137); // move 
	create_write_byte(HIGH_BYTE(speed));
	create_write_byte(LOW_BYTE(speed));
	create_write_byte(HIGH_BYTE(rad)); 
	create_write_byte(HIGH_BYTE(rad)); 
	create_write_byte(157); // wait for angle done
	create_write_byte(HIGH_BYTE(deg));
	create_write_byte(LOW_BYTE(deg));
	create_write_byte(137); // stop move 
	create_write_byte(0);   // no speed
	create_write_byte(0);
	create_write_byte(0);   // no angle
	create_write_byte(0);   
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 1
	// end of script
	create_write_byte(153); // run script
	CREATE_FREE;
}
示例#4
0
文件: create.c 项目: CBCJVM/cbc
// script to move with individual motor control
// dist mm with r_speed mm/sec on right wheel and l_speed on left
void create_script_move_direct(int dist, int r_speed, int l_speed) { 
	CREATE_BUSY;
	create_write_byte(152); // start script
	create_write_byte(17);  // script length
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 0
	create_write_byte(145); // move 
	create_write_byte(HIGH_BYTE(r_speed));
	create_write_byte(LOW_BYTE(r_speed));
	create_write_byte(HIGH_BYTE(l_speed));
	create_write_byte(LOW_BYTE(l_speed));
	create_write_byte(156); // wait for distance done
	create_write_byte(HIGH_BYTE(dist));
	create_write_byte(LOW_BYTE(dist));
	create_write_byte(137); // stop move 
	create_write_byte(0);   // no speed
	create_write_byte(0);
	create_write_byte(0);   // no angle
	create_write_byte(0);   
	create_write_byte(147); // on pin 20
	create_write_byte(0);   //   output 1
	// end of script
	create_write_byte(153); // run script
	CREATE_FREE;
}
static void  lcm_update_black(unsigned int x, unsigned int y,unsigned int width, unsigned int height, unsigned short data)
{
    unsigned int x0 = x;
    unsigned int y0 = y;
    unsigned int x1 = x0 + width;
    unsigned int y1 = y0 + height + 2;
    unsigned int k, i;
	
	send_ctrl_cmd(0x2A);
	send_data_cmd(HIGH_BYTE(x0));
	send_data_cmd(LOW_BYTE(x0));
	send_data_cmd(HIGH_BYTE(x1));
	send_data_cmd(LOW_BYTE(x1));

	send_ctrl_cmd(0x2B);
	send_data_cmd(HIGH_BYTE(y0));
	send_data_cmd(LOW_BYTE(y0));
	send_data_cmd(HIGH_BYTE(y1));
	send_data_cmd(LOW_BYTE(y1));
	send_ctrl_cmd(0x2C);
	
	for (i = x0; i < x1; i++)
	{
		for (k = y0; k < y1; k++)
		{
			send_data_cmd(data);
		}
	}
}
// Attributes stored in RAM are always re-initialized upon start-up.
void emAfRf4ceMsoInitAttributes(void)
{
  uint8_t i, j;

  MEMSET(emAfRf4ceMsoRibAttributes,
         0x00,
         sizeof(EmAfRf4ceMsoRibAttributes)*EMBER_RF4CE_PAIRING_TABLE_SIZE);

  // Initialize the device type of all the peripheral ID entries to 0xFF, which
  // means "unused" in this context.
  for(i=0; i<EMBER_RF4CE_PAIRING_TABLE_SIZE; i++) {
    for(j=0; j<EMBER_AF_PLUGIN_RF4CE_MSO_PERIPHERAL_ID_ENTRIES; j++) {
      emAfRf4ceMsoRibAttributes[i].peripheralIds[j].deviceType = 0xFF;
    }

    // Initialize the validation configuration attribute fields to the default
    // values.
    emAfRf4ceMsoRibAttributes[i].validationConfiguration[0] =
        LOW_BYTE(EMBER_AF_PLUGIN_RF4CE_MSO_LINK_LOST_WAIT_TIME_MS);
    emAfRf4ceMsoRibAttributes[i].validationConfiguration[1] =
        HIGH_BYTE(EMBER_AF_PLUGIN_RF4CE_MSO_LINK_LOST_WAIT_TIME_MS);
    emAfRf4ceMsoRibAttributes[i].validationConfiguration[2] =
        LOW_BYTE(EMBER_AF_PLUGIN_RF4CE_MSO_AUTO_CHECK_VALIDATION_PERIOD_MS);
    emAfRf4ceMsoRibAttributes[i].validationConfiguration[3] =
        HIGH_BYTE(EMBER_AF_PLUGIN_RF4CE_MSO_AUTO_CHECK_VALIDATION_PERIOD_MS);
  }
}
示例#7
0
static void  lcm_update_black(unsigned int x, unsigned int y,unsigned int width, unsigned int height, unsigned short data)
{
    unsigned int x0 = x;
    unsigned int y0 = y;
    unsigned int x1 = x0 + width;
    unsigned int y1 = y0 + height + 2;
    unsigned int k, i;

	set_lcm_register(0x2A00, HIGH_BYTE(x0),  0);
	set_lcm_register(0x2A01, LOW_BYTE(x0),  0);
	set_lcm_register(0x2A02, HIGH_BYTE(x1),  0);
	set_lcm_register(0x2A03, LOW_BYTE(x1),  0);
	set_lcm_register(0x2B00, HIGH_BYTE(y0),  0);
	set_lcm_register(0x2B01, LOW_BYTE(y0),  0);
	set_lcm_register(0x2B02, HIGH_BYTE(y1),  0);  
	set_lcm_register(0x2B03, LOW_BYTE(y1),  0);

	send_ctrl_cmd(0x2C00);

	for (i = x0; i < x1; i++)
	{
		for (k = y0; k < y1; k++)
		{
			send_data_cmd(data);
			send_data_cmd(data);
		}
	}
	
}
示例#8
0
static void sw_clear_panel(unsigned int color)
{
    unsigned int x0 = 0;
    unsigned int y0 = 0;
    unsigned int x1 = x0 + FRAME_WIDTH - 1;
    unsigned int y1 = y0 + FRAME_HEIGHT - 1;

    unsigned int x, y;

    send_ctrl_cmd(0x2A); 
    send_data_cmd(HIGH_BYTE(x0));
  	send_data_cmd(LOW_BYTE(x0));
    send_data_cmd(HIGH_BYTE(x1));
  	send_data_cmd(LOW_BYTE(x1));

  	send_ctrl_cmd(0x2B); 
    send_data_cmd(HIGH_BYTE(y0));
  	send_data_cmd(LOW_BYTE(y0));
    send_data_cmd(HIGH_BYTE(y1));
  	send_data_cmd(LOW_BYTE(y1));

	send_ctrl_cmd(0x2C);    // send DDRAM set

    // 18-bit mode (256K color) coding
    for (y = y0; y <= y1; ++ y) {
        for (x = x0; x <= x1; ++ x) {
            lcm_util.send_data(color);
        }
    }
}
示例#9
0
void Roomba_Direct_Drive(int16_t right_velocity, int16_t left_velocity)
{
	uart_putchar(DIRECT_DRIVE);
	uart_putchar(HIGH_BYTE(right_velocity));
	uart_putchar(LOW_BYTE(right_velocity));
	uart_putchar(HIGH_BYTE(left_velocity));
	uart_putchar(LOW_BYTE(left_velocity));
}
示例#10
0
void Roomba_Drive(int16_t velocity, int16_t radius )
{
	uart_putchar(DRIVE);
	uart_putchar(HIGH_BYTE(velocity));
	uart_putchar(LOW_BYTE(velocity));
	uart_putchar(HIGH_BYTE(radius));
	uart_putchar(LOW_BYTE(radius));
}
示例#11
0
文件: create.c 项目: CBCJVM/cbc
// This command drives the robot along a curve with radius (in mm) radius; and at a speed (mm/sec) of speed
// a radius of 32767 will drive the robot straight
// a radius of 1 will spin the robot CCW
// a radius of -1 will spin the robot CW
// Negative radii will be right turns, positive radii left turns
void create_drive (int speed, int radius)
{
	CREATE_BUSY;
	create_write_byte(137);
	create_write_byte(HIGH_BYTE(speed));
	create_write_byte(LOW_BYTE(speed));
	create_write_byte(HIGH_BYTE(radius));
	create_write_byte(LOW_BYTE(radius));
	CREATE_FREE;
}
示例#12
0
文件: create.c 项目: CBCJVM/cbc
// special version of command spins robot CCW with the wheels turning at speed speed
void create_spin_CCW (int speed)
{
	CREATE_BUSY;
	create_write_byte(137);
	create_write_byte(HIGH_BYTE(speed));
	create_write_byte(LOW_BYTE(speed));
	create_write_byte(HIGH_BYTE(1));
	create_write_byte(LOW_BYTE(1));
	CREATE_FREE;
}
示例#13
0
文件: create.c 项目: CBCJVM/cbc
// this function drives the right wheel at r_speed and the left wheel at l_speed
// speeds for all of these functions are +/-500mm/sec.
void create_drive_direct(int r_speed, int l_speed)
{
	CREATE_BUSY;
	create_write_byte(145);
	create_write_byte(HIGH_BYTE(r_speed));
	create_write_byte(LOW_BYTE(r_speed));
	create_write_byte(HIGH_BYTE(l_speed));
	create_write_byte(LOW_BYTE(l_speed));
	CREATE_FREE;
}    
示例#14
0
文件: create.c 项目: CBCJVM/cbc
// special version of command above drives robot at speed speed.  Negative speed will drive robot backwards
void create_drive_straight (int speed)
{
	CREATE_BUSY;
	create_write_byte(137);
	create_write_byte(HIGH_BYTE(speed));
	create_write_byte(LOW_BYTE(speed));
	create_write_byte(HIGH_BYTE(32767));
	create_write_byte(LOW_BYTE(32767));
	CREATE_FREE;
}
示例#15
0
/**@brief Function for simulating a bike speed event. 
 * 
 * @param[in] p_context Timeout context.
 */
static void speed_pulse_event_simulate(void * p_context)
{  
    // Current speed event time is the previous event time added with the event interval. 
    m_speed_event_time += SPEED_EVENT_INTERVAL;
    
    // Update current speed event time.   
    m_tx_buffer[SPEED_EVENT_TIME_LSB_INDEX] = LOW_BYTE(m_speed_event_time);    
    m_tx_buffer[SPEED_EVENT_TIME_MSB_INDEX] = HIGH_BYTE(m_speed_event_time);            

    // Update current speed event count.    
    ++m_speed_revolution_count;
    m_tx_buffer[CUMULATIVE_SPEED_LSB_INDEX] = LOW_BYTE(m_speed_revolution_count);    
    m_tx_buffer[CUMULATIVE_SPEED_MSB_INDEX] = HIGH_BYTE(m_speed_revolution_count);                   
}
示例#16
0
/**@brief Function for simulating a bike cadence event. 
 * 
 * @param[in] p_context Timeout context.
 */
static void cadence_pulse_event_simulate(void * p_context)
{
    // Current cadence event time is the previous event time added with the event interval.     
    m_cadence_event_time += CADENCE_EVENT_INTERVAL;
    
    // Update current cadence event time.
    m_tx_buffer[CADENCE_EVENT_TIME_LSB_INDEX] = LOW_BYTE(m_cadence_event_time);    
    m_tx_buffer[CADENCE_EVENT_TIME_MSB_INDEX] = HIGH_BYTE(m_cadence_event_time);        
    
    // Update current cadence event count.
    ++m_cadence_revolution_count;
    m_tx_buffer[CUMULATIVE_CADENCE_LSB_INDEX] = LOW_BYTE(m_cadence_revolution_count);    
    m_tx_buffer[CUMULATIVE_CADENCE_MSB_INDEX] = HIGH_BYTE(m_cadence_revolution_count);           
}
示例#17
0
文件: create.c 项目: CBCJVM/cbc
int create_do_move(int dist, int speed) {
	if ((91-_create_script_indx)<8) {
		printf("max script exceeded\n");
	return(_create_script_indx); }  // not enough script space left 
	_create_script[_create_script_indx++]=137; // move command
	_create_script[_create_script_indx++]=HIGH_BYTE(speed);
	_create_script[_create_script_indx++]=LOW_BYTE(speed);
	_create_script[_create_script_indx++]=128; // no angle (go straight)
	_create_script[_create_script_indx++]=0;
	_create_script[_create_script_indx++]=156; // wait for distance done
	_create_script[_create_script_indx++]=HIGH_BYTE(dist); 
	_create_script[_create_script_indx++]=LOW_BYTE(dist);
	return(0);
}
EmberStatus ezspEndDeviceBindRequest(EmberNodeId localNodeId,
                                     EmberEUI64 localEui64,
                                     uint8_t endpoint,
                                     uint16_t profile,
                                     uint8_t inCount,
                                     uint8_t outCount,
                                     uint16_t *inClusters,
                                     uint16_t *outClusters,
                                     EmberApsOption options)
{
  uint8_t i;
  uint8_t *payload = zigDevRequestBuffer + ZDO_MESSAGE_OVERHEAD;
  uint8_t offset = ZDO_MESSAGE_OVERHEAD + 14;  // Add 2 bytes for our NWK Address 
                                             // Add 8 bytes for our EUI64
                                             // Add 1 byte for endpoint
                                             // Add 2 bytes for Profile Id
                                             // Add 1 byte for in Cluster Count
  uint8_t length = (offset + 
                  (inCount * 2) +  // Times 2 for 2 byte Clusters
                  1 +              // Out Cluster Count
                  (outCount * 2)); // Times 2 for 2 byte Clusters
  
  if (length > EZSP_MAX_FRAME_LENGTH)
    return EMBER_NO_BUFFERS;

  payload[0] = LOW_BYTE(localNodeId);
  payload[1] = HIGH_BYTE(localNodeId);
  MEMMOVE(payload + 2, localEui64, 8);
  payload[10] = endpoint;
  payload[11] = LOW_BYTE(profile);
  payload[12] = HIGH_BYTE(profile);
  payload[13] = inCount;

  for (i = 0; i < inCount; i++) {
    zigDevRequestBuffer[(i * 2) + offset] = LOW_BYTE(inClusters[i]);
    zigDevRequestBuffer[(i * 2) + offset + 1] = HIGH_BYTE(inClusters[i]);
  }
  offset += (inCount * 2);
  zigDevRequestBuffer[offset] = outCount;
  offset++;
  for (i = 0; i < outCount; i++) {
    zigDevRequestBuffer[(i * 2) + offset] = LOW_BYTE(outClusters[i]);
    zigDevRequestBuffer[(i * 2) + offset + 1] = HIGH_BYTE(outClusters[i]);
  }

  return sendZigDevRequestBuffer(EMBER_ZIGBEE_COORDINATOR_ADDRESS,
                                 END_DEVICE_BIND_REQUEST,
                                 options,
                                 length);
}
示例#19
0
文件: create.c 项目: CBCJVM/cbc
int create_do_move_direct(int dist, int r_speed, int l_speed) {  // individual motor control move
	if ((91-_create_script_indx)<8) {
		printf("max script exceeded\n");
	return(_create_script_indx); }  // not enough script space left 
	_create_script[_create_script_indx++]=145; // move command
	_create_script[_create_script_indx++]=HIGH_BYTE(r_speed);
	_create_script[_create_script_indx++]=LOW_BYTE(r_speed);
	_create_script[_create_script_indx++]=HIGH_BYTE(l_speed);
	_create_script[_create_script_indx++]=LOW_BYTE(l_speed);
	_create_script[_create_script_indx++]=156; // wait for distance done
	_create_script[_create_script_indx++]=HIGH_BYTE(dist); 
	_create_script[_create_script_indx++]=LOW_BYTE(dist);
	return(0);
}
示例#20
0
uint8_t receiveSingleFrame() { 
    
    uint8_t ret = LW232_OK;
    uint8_t idx = 0;
    if (CAN_OK == readMsgBufID(&lw232_CanId, &lw232_PacketLen, lw232_Buffer)) {
        if (lw232_CanId > 0x1FFFFFFF) {
            ret = LW232_ERR; // address if totally wrong
        }
        else if (checkPassFilter(lw232_CanId)) {// do we want to skip some addresses?
            if (isExtendedFrame()) {
                printChar(LW232_TR29);
                printFullByte(HIGH_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            else {
                printChar(LW232_TR11);
                printNibble(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            //write data len
            printNibble(lw232_PacketLen);
            //write data
            for (idx = 0; idx < lw232_PacketLen; idx++) {
                printFullByte(lw232_Buffer[idx]);
            }
            //write timestamp if needed
            if (lw232_TimeStamp != LW232_TIMESTAMP_OFF) {
                uint32_t time = 0; //millis();
                if (lw232_TimeStamp == LW232_TIMESTAMP_ON_NORMAL) { 
                    // standard LAWICEL protocol. two bytes.
                    time %= 60000;  
                } else {
                    // non standard protocol - 4 bytes timestamp
                    printFullByte(HIGH_BYTE(HIGH_WORD(time)));
                    printFullByte(LOW_BYTE(HIGH_WORD(time)));
                }
                printFullByte(HIGH_BYTE(LOW_WORD(time)));
                printFullByte(LOW_BYTE(LOW_WORD(time)));
            }
        }
    }
    else {
        ret = LW232_ERR;
    }
    return ret;
}
示例#21
0
U16	C_DM9000::DeviceWriteEeprom(
	U32		uWordAddress,
	U16		uValue)
{
	// assign the register offset
	DeviceWritePort(DM9_EPADDR,uWordAddress);

	// put data
	DeviceWritePort(DM9_EPLOW, LOW_BYTE(uValue));
	DeviceWritePort(DM9_EPHIGH,HIGH_BYTE(uValue));
		
	// issue EEPROM write enable<4> and write command<1>
	DeviceWritePort(DM9_EPCNTL,MAKE_MASK2(4,1));
	
	// wait until status bit<0> cleared
	DevicePolling(DM9_EPCNTL,MAKE_MASK(0),0x00);
	
	// stop command
	DeviceWritePort(DM9_EPCNTL,0);

	// extra delay
	NdisStallExecution(1000);
	
	return uValue;
}
示例#22
0
INT8U Can232::receiveSingleFrame() {
    INT8U ret = LW232_OK;
    INT8U idx = 0;
    if (CAN_OK == readMsgBufID(&lw232CanId, &lw232PacketLen, lw232Buffer)) {
        if (lw232CanId > 0x1FFFFFFF) {
            ret = LW232_ERR; // address if totally wrong
        }
        else if (checkPassFilter(lw232CanId)) {// do we want to skip some addresses?
            if (isExtendedFrame()) {
                Serial.print(LW232_TR29);
                HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(lw232CanId)));
                HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
            }
            else {
                Serial.print(LW232_TR11);
                HexHelper::printNibble(HIGH_BYTE(LOW_WORD(lw232CanId)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(lw232CanId)));
            }
            //write data len
            HexHelper::printNibble(lw232PacketLen);
            //write data
            for (idx = 0; idx < lw232PacketLen; idx++) {
                HexHelper::printFullByte(lw232Buffer[idx]);
            }
            //write timestamp if needed
            if (lw232TimeStamp != LW232_TIMESTAMP_OFF) {
                INT32U time = millis();
                if (lw232TimeStamp == LW232_TIMESTAMP_ON_NORMAL) { 
                    // standard LAWICEL protocol. two bytes.
                    time %= 60000;  
                } else {
                    // non standard protocol - 4 bytes timestamp
                    HexHelper::printFullByte(HIGH_BYTE(HIGH_WORD(time)));
                    HexHelper::printFullByte(LOW_BYTE(HIGH_WORD(time)));
                }
                HexHelper::printFullByte(HIGH_BYTE(LOW_WORD(time)));
                HexHelper::printFullByte(LOW_BYTE(LOW_WORD(time)));
            }
        }
    }
    else {
        ret = LW232_ERR;
    }
    return ret;
}
示例#23
0
/* This function could use a rewrite */
static void convdata(unsigned char *srcbuffer, unsigned char *dstbuffer, 
		int width, int mode)
/* This is a tricky (read: crap) function (read: hack) which is why I probably 
   spent more time commenting it than programming it. The thing to remember 
   here is that the scanner uses interpolated scanlines, so it's
   RRRRRRRGGGGGGBBBBBB not RGBRGBRGBRGBRGB. So, the calling function just 
   increments the destination pointer slightly to handle green, then a bit 
   more for blue. If you don't understand, tough. */
{
	int count;
	int i, j, k;

	for (count = 0; count < width; count++)
	{
		/* The scanner stores data in a bizzare butchered 10-bit 
		   format.  I'll try to explain it in 100 words or less:

		   Scanlines are made up of groups of 4 pixels. Each group of 
		   4 is stored inside 5 bytes. The first 4 bytes of the group 
		   contain the lowest 8 bits of one pixel each (in the right 
		   order). The 5th byte contains the most significant 2 bits 
		   of each pixel in the same order. */

		i = srcbuffer[count + (count >> 2)]; /* Low byte for pixel */
		j = srcbuffer[(((count / 4) + 1) * 5) - 1]; /* "5th" byte */
		j = j >> ((count % 4) * 2); /* Get upper 2 bits of intensity */
		j = j & 0x03; /* Can't hurt */
		/* And the final 10-bit pixel value is: */
		k = (j << 8) | i; 

		/* now we return this as a 16 bit value */
		k = k << 6;

		if (mode == 1) /* Scanner -> Grey */
		{
			dstbuffer[count * 2] = HIGH_BYTE(k);
			dstbuffer[(count * 2) + 1] = LOW_BYTE(k);
		}
		else if (mode == 2) /* Scanner -> RGB */
		{
			dstbuffer[count * 3 * 2] = HIGH_BYTE(k);
			dstbuffer[(count * 3 * 2) + 1] = LOW_BYTE(k);			
		}

	}
}
示例#24
0
文件: create.c 项目: CBCJVM/cbc
int create_do_arc(int rad, int deg, int speed) {
	// warning: CCW movement increases degree, CW decreases
	// opposite signs on rad and vel cause CW rotation
	// if direction is CW, this won't stop if deg > 0
	if ((91-_create_script_indx)<8) {
		printf("max script exceeded\n");
	return(_create_script_indx); }  // not enough script space left 
	_create_script[_create_script_indx++]=137; // move command
	_create_script[_create_script_indx++]=HIGH_BYTE(speed);
	_create_script[_create_script_indx++]=LOW_BYTE(speed);
	_create_script[_create_script_indx++]=HIGH_BYTE(rad);
	_create_script[_create_script_indx++]=LOW_BYTE(rad);
	_create_script[_create_script_indx++]=157; // wait for angle done
	_create_script[_create_script_indx++]=HIGH_BYTE(deg); 
	_create_script[_create_script_indx++]=LOW_BYTE(deg);
	return(0);
}
示例#25
0
文件: create.c 项目: CBCJVM/cbc
int create_do_turn(int deg, int speed) {  // speed > 0
	if ((91-_create_script_indx)<8) {
		printf("max script exceeded\n");
	return(_create_script_indx); }  // not enough script space left 
	_create_script[_create_script_indx++]=137; // move command
	_create_script[_create_script_indx++]=HIGH_BYTE(speed);
	_create_script[_create_script_indx++]=LOW_BYTE(speed);
	if (deg > 0){ // CCW case 
		_create_script[_create_script_indx++]=0; 
	_create_script[_create_script_indx++]=1; }
	else { // CW case
		_create_script[_create_script_indx++]=255;
	_create_script[_create_script_indx++]=255; }    
	_create_script[_create_script_indx++]=157; // wait for angle done
	_create_script[_create_script_indx++]=HIGH_BYTE(deg); 
	_create_script[_create_script_indx++]=LOW_BYTE(deg);
	return(0);
}
EmberStatus ezspMatchDescriptorsRequest(EmberNodeId target,
                                        uint16_t profile,
                                        uint8_t inCount,
                                        uint8_t outCount,
                                        uint16_t *inClusters,
                                        uint16_t *outClusters,
                                        EmberApsOption options)
{
  uint8_t i;
  uint8_t *payload = zigDevRequestBuffer + ZDO_MESSAGE_OVERHEAD;
  uint8_t offset = ZDO_MESSAGE_OVERHEAD + 5;   // Add 2 bytes for NWK Address 
                                             // Add 2 bytes for Profile Id
                                             // Add 1 byte for in Cluster Count
  uint8_t length = (offset + 
                  (inCount * 2) + // Times 2 for 2 byte Clusters
                  1 +             // Out Cluster Count
                  (outCount * 2)); // Times 2 for 2 byte Clusters
  
  if (length > EZSP_MAX_FRAME_LENGTH)
    return EMBER_NO_BUFFERS;

  payload[0] = LOW_BYTE(target);
  payload[1] = HIGH_BYTE(target);
  payload[2] = LOW_BYTE(profile);
  payload[3] = HIGH_BYTE(profile);
  payload[4] = inCount;

  for (i = 0; i < inCount; i++) {
    zigDevRequestBuffer[(i * 2) + offset] = LOW_BYTE(inClusters[i]);
    zigDevRequestBuffer[(i * 2) + offset + 1] = HIGH_BYTE(inClusters[i]);
  }
  offset += (inCount * 2);
  zigDevRequestBuffer[offset] = outCount;
  offset++;
  for (i = 0; i < outCount; i++) {
    zigDevRequestBuffer[(i * 2) + offset] = LOW_BYTE(outClusters[i]);
    zigDevRequestBuffer[(i * 2) + offset + 1] = HIGH_BYTE(outClusters[i]);
  }

  return sendZigDevRequestBuffer(target,
                                 MATCH_DESCRIPTORS_REQUEST,
                                 options,
                                 length);
}
示例#27
0
void init_can()
{
	// set up can for 250 kbit/s using 4 MHz external clock
	// set up receive_isr for interrupt on receive
	CANCTL1_CANE = 1;
	CANCTL0_INITRQ = 1;
	while(!CANCTL1_INITAK);
	
// can initialization mode writes
	CANCTL1_LOOPB = loopback_mode;
	CANCTL1_LISTEN = LISTEN_ONLY_MODE;
	
	CANBTR0_SJW = 0b01;
	// frequency = 1/(tseg1+tseg2+3)
	CANBTR1_TSEG_20 = 5;
	CANBTR1_TSEG_10 = 8;
	
	/*// 8 8bit masks
	CANIDAC_IDAM = 0b10;	
	// set a mask to let in all possibilities
	CANIDMR0 = 0xFF;*/
	
	// set the masks
	// 4 16 bit masks
	CANIDAC_IDAM = 0b01;
	CANIDMR0 = HIGH_BYTE(MASK_ISO_PDU2);
	CANIDMR1 = LOW_BYTE(MASK_ISO_PDU2);
	CANIDMR2 = HIGH_BYTE(MASK_ISO_PDU1);
	CANIDMR3 = LOW_BYTE(MASK_ISO_PDU1);
	CANIDMR4 = HIGH_BYTE(MASK_NMEA_PDU2);
	CANIDMR5 = LOW_BYTE(MASK_NMEA_PDU2);
	CANIDMR6 = HIGH_BYTE(MASK_NMEA_PDU1);
	CANIDMR7 = LOW_BYTE(MASK_NMEA_PDU1);
	CANIDAR0 = HIGH_BYTE(FILT_ISO_PDU2);
	CANIDAR1 = LOW_BYTE(FILT_ISO_PDU2);
	CANIDAR2 = HIGH_BYTE(FILT_ISO_PDU1);
	CANIDAR3 = LOW_BYTE(FILT_ISO_PDU1);
	CANIDAR4 = HIGH_BYTE(FILT_NMEA_PDU2);
	CANIDAR5 = LOW_BYTE(FILT_NMEA_PDU2);
	CANIDAR6 = HIGH_BYTE(FILT_NMEA_PDU1);
	CANIDAR7 = LOW_BYTE(FILT_NMEA_PDU1);
	
	CANCTL0_INITRQ = 0;
	while(CANCTL1_INITAK);
	
// not initialization mode writes
	CANRIER_RXFIE = 1;
	
	srand(2);		//TODO initialize this with random ad values 
	generate_new_source_address();
	address_claim_message();
	
}
示例#28
0
static void lcm_update(unsigned int x, unsigned int y, unsigned int width, unsigned int height)
{
    unsigned int x0 = x;
    unsigned int y0 = y;
    unsigned int x1 = x0 + width - 1;
    unsigned int y1 = y0 + height - 1;

	set_lcm_register(0x2A00, HIGH_BYTE(x0),  0);
	set_lcm_register(0x2A01, LOW_BYTE(x0),  0);
	set_lcm_register(0x2A02, HIGH_BYTE(x1),  0);
	set_lcm_register(0x2A03, LOW_BYTE(x1),  0);
	set_lcm_register(0x2B00, HIGH_BYTE(y0),  0);
	set_lcm_register(0x2B01, LOW_BYTE(y0),  0);
	set_lcm_register(0x2B02, HIGH_BYTE(y1),  0);  
	set_lcm_register(0x2B03, LOW_BYTE(y1),  0);

	send_ctrl_cmd(0x2c00);

}
示例#29
0
	/**
	 * Set USART baud-rate and operation mode.
	 * @param baudrate baud-rate that the USART will use
	 * @param mode     USART operation mode
	 */
	void usart1_setBaudrate(const uint32_t baudrate, enum uart_operationModes_t mode){
		switch (mode) {
			case UART_MODE_ASYNC_NORMAL: USART1_SET_MODE_ASYNC(); break;
			case UART_MODE_ASYNC_DOUBLE: USART1_SET_MODE_ASYNC(); break;
			case UART_MODE_SYNC_MASTER: USART1_SET_MODE_SYNC(); break;
		}

		const uint16_t prescale = uart_baud2ubrr(baudrate, mode);

		UBRR1L = LOW_BYTE(prescale);
		UBRR1H = HIGH_BYTE(prescale);
	}
示例#30
0
UINT32
bd_ans_hw_flags(BOARD_PRIVATE_STRUCT *bps, UINT16 revid)
{                                        
    UINT16 CompatibilityFlagsReg;
    UINT32 flags = 0;
    
    if (revid < I82559_REV_ID) {
        flags |= IANS_BD_FLAG4;
        
    } else {
        CompatibilityFlagsReg = READ_EEPROM(bps, EEPROM_COMPATIBILITY_FLAGS);
        
        if ((HIGH_BYTE(CompatibilityFlagsReg) & EEPROM_COMPATIBILITY_BIT_4) &&
            !(HIGH_BYTE(CompatibilityFlagsReg) & EEPROM_COMPATIBILITY_BIT_2)) {
            
            flags |= IANS_BD_FLAG4;
        }
    }
    
    return flags;
}