예제 #1
0
void Bk8000l_Control_ALARM(u8 param)
{
    char cmd[3] = "D";
    u8 n = 1;
    cmd[n++] = '0' + param;
    if(param > 4)
        return ;
    else
        bluetooth_send_command(cmd);
}
예제 #2
0
void Bk8000l_Change_Power(u8 param)
{
    char cmd[10] = "B";
    u8 n = 1;
    if(param > 4)
        return ;
    else{
        cmd[n++] = '0' + param%10;
        bluetooth_send_command(cmd);
    } 
}
예제 #3
0
void Bk8000l_Change_DisplayLimus(u8 param)
{
    char cmd[4] = "E";
    u8 n = 1;
    if(param > 15)
        return ;
    else{
        cmd[n++] = '0' + param/10;
        cmd[n++] = '0' + param%10;
        bluetooth_send_command(cmd);
    } 
}
예제 #4
0
void Bk8000l_Change_DisplayMode(u8 param)
{
    char cmd[10] = "A";
    u8 n = 1;
    if(param > 10)
        return ;
    else{
        cmd[n++] = '0' + param/10;
        cmd[n++] = '0' + param%10;
        bluetooth_send_command(cmd);
    } 
}
예제 #5
0
void picture_transfer_send(unsigned char *filename) {
	unsigned char *ready_msg = "S";

	unsigned char length_of_send_msg_length[2];
	memset(length_of_send_msg_length, '\0', sizeof(length_of_send_msg_length));
	unsigned char send_msg_length[10];
	memset(send_msg_length, '\0', sizeof(send_msg_length));

	char * imagedata = NULL;
	int imagelength;
	int offset;
	int result;

	sdcard_init();

	result = bitmap_import_image(filename, &imagedata, &imagelength, &offset);
	if (result != 0) {
		printf("Error with importing image\n");
		return;
	}

	//convert imagelength to string
	snprintf(send_msg_length, sizeof(send_msg_length), "%d", imagelength);

	//get length of send_msg_length
	snprintf(length_of_send_msg_length, sizeof(length_of_send_msg_length), "%d", strlen(send_msg_length));

	//send ready message to start communication
	bluetooth_send_command(ready_msg);
	printf("Ready message sent!\n");

	//send length of the string length of the final message
	picture_transfer_send_communication(length_of_send_msg_length, sizeof(length_of_send_msg_length), STRING_LENGTH);
	printf("Length of string length message sent!\n");

	//send length of the final message
	picture_transfer_send_communication(send_msg_length, sizeof(send_msg_length), MESSAGE_LENGTH);
	printf("String length message sent!\n");

	//send final message
	picture_transfer_send_communication(imagedata, imagelength, FINAL);
	printf("Final message sent!\n");

	free(imagedata);
}
예제 #6
0
static void picture_transfer_send_communication(unsigned char *msg, const int length, const int com_stage) {
	int send_check = 1;
	unsigned char *ready_msg = "R";
	unsigned char ready_check[1];
	memset(ready_check, '\0', PICTURE_CONNECTION_CHECK_LENGTH);

	while(send_check) {
		bluetooth_get_n_char(ready_check, PICTURE_CONNECTION_CHECK_LENGTH);

		//wait for "R" message from receiver
		if(strcmp(ready_check, ready_check) == 0) {
			if(com_stage == FINAL)
				bluetooth_send_data(msg, length);
			else
				bluetooth_send_command(msg);
			send_check = 0;
		}
	}
}
예제 #7
0
void Bk8000l_Sync_Color(u8 red_param, u8 green_param, u8 blue_param)
{
    char cmd[11] = "C";
    u8 n = 1;

    
    if(red_param > 255 || green_param > 255 || red_param > 255)
        return ;
    else
    {
        cmd[n++] = '0' + red_param/100;
        cmd[n++] = '0' + red_param/10 - red_param/100*10;
        cmd[n++] = '0' + red_param%10;
        cmd[n++] = '0' + green_param/100;
        cmd[n++] = '0' + green_param/10 - green_param/100*10;
        cmd[n++] = '0' + green_param%10;
        cmd[n++] = '0' + blue_param/100;
        cmd[n++] = '0' + blue_param/10 - blue_param/100*10;
        cmd[n++] = '0' + blue_param%10;
        bluetooth_send_command(cmd);
    }
}
예제 #8
0
void
action_commands_task (void *data)
{
    uint8_t rx[130] = {0};
    int i;
    i2c_ret_t ret;
    int to_read;
    
    bluetooth_t btconn = data;
    
    if (ch != CMD_NONE)
    {
    	// Motor commands.
        if (ch >= MC_VALUES_START && ch <= MC_VALUES_STOP)
        {
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            i2c_master_addr_write (i2c_motor, COMMS_COMMAND, 1, &ch, 1);
            
            // Ensure clock is left in a pullup state
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);

        }
        else if (ch >= MD_VALUES_START && ch <= MD_VALUES_STOP)
        {
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            i2c_master_addr_write (i2c_motor, COMMS_COMMAND, 1, &ch, 1);

            // Ensure clock is left in a pullup state
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
        }
        else if (ch >= CC_VALUES_START && ch <= CC_VALUES_STOP)
        {
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            i2c_master_addr_write (i2c_camera, COMMS_COMMAND, 1, &ch, 1);
            
            // Ensure clock is left in a pullup state
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
        }
        else if (ch == CD_PHOTO_READY)
        {
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            i2c_master_addr_read (i2c_camera, ch, 1, rx, 1);
            
            // Transmit if photo ready over bluetooth
            bluetooth_send_command (btconn, rx[0]);
        }
        else if (ch == CD_PHOTO_LINE)
        {
            to_read = image_bytes_left < 128 ? image_bytes_left : 128;
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            ret = i2c_master_addr_read (i2c_camera, ch, 1, rx, to_read);  
            image_bytes_left -= ret;
            if (image_bytes_left <= 0)
                image_bytes_left = IMAGE_SIZE;
            // Transmit back data over bluetooth
            for (i = 0; i < ret; i++){
                bluetooth_send_command (btconn, rx[i]);
            }
        }
        else if (ch == CD_FAULT)
        {
            // Send interrupt to slaves
            pio_config_set (i2c_bus_cfg.scl, PIO_OUTPUT_LOW);
            DELAY_US (3);
            // Set clock back ready for i2c
            pio_config_set (i2c_bus_cfg.scl, PIO_PULLUP);
            DELAY_US (20);
            i2c_master_addr_read (i2c_camera, ch, 1, rx, 1);
            
            // Transmit if photo ready over bluetooth
            bluetooth_send_command (btconn, rx[0]);
        }
            
        ch = CMD_NONE;
    }
}
예제 #9
0
static void picture_transfer_receive_communication(unsigned char *msg, const int msg_length, const int com_stage) {
	int recv_check = 1;
	const unsigned char *ready_check = "R";
	const unsigned char *send_check = "S";
	int i;

	while(recv_check) {
		bluetooth_get_n_char(msg, msg_length);

		switch(com_stage) {
			//wait for ready message
			case WAIT  :
				//compare message received to "R"
				if(strcmp(msg, send_check) == 0) {
					printf("Ready message received!\n\n");
					memset(msg, 0, msg_length);
					bluetooth_send_command(ready_check);
					recv_check = 0;
				}
				break;

			//get length of the string length of the final message
			case STRING_LENGTH  :
				recv_msg_length = atoi(msg);
				//check that recv_msg_length is an integer > 0
				if(recv_msg_length > 0) {
					printf("Length of string length message is %d!\n\n", recv_msg_length);
					memset(msg, 0, msg_length);
					bluetooth_send_command(ready_check);
					recv_check = 0;
				}
				break;

			//get length of the final message
			case MESSAGE_LENGTH  :
				actual_msg_length = atoi(msg);
				//check that recv_msg_length is an integer > 0
				if(actual_msg_length > 0) {
					printf("Length of actual message is %d!\n\n", actual_msg_length);
					memset(msg, 0, msg_length);
					bluetooth_send_command(ready_check);
					recv_check = 0;
				}
				break;

			//get final message
			case FINAL  :
				//check that message received is not NULL
				if(strcmp(msg, "") != 0) {
					printf("Final message received:\n");
					printf("%s\n", msg);
					recv_check = 0;
				}
				break;

			//print an error if com_stage doesn't pass properly
			default :
				printf("ERROR: com_stage not being passed properly!\n");
				recv_check = 0;
				break;
		}
	}
}