Exemplo n.º 1
0
/****************************************
* main
*
* sets up the communication between the  main mbed
* continuously checks for a command from the main mbed
* if new command received, then executes the appropriate function
*
****************************************/
int main()
{
    pc.baud(9600);
    clear_strip();
    
    //tlc.setLED(0, 0, 65535, 65535);
//    tlc.setLED(1, 0, 65535, 65535);
//    tlc.write();
//    wait(3);
//    clear_strip();
    create_pattern(P_FADE, 65535, 0, 65535, 25, 2000);
    
    while(1)
    {
        rxLen = rf_receive(rxBuffer, 128);
        if(rxLen > 0)
        { 
            if(rxBuffer[0] == ID) 
            {
                char* rxBuffer1 = &rxBuffer[1];
                pc.printf("Received string %s \r\n",rxBuffer);
                parser(rxBuffer1);
            }
        }
    }
}
Exemplo n.º 2
0
static cairo_test_status_t
source (cairo_t *cr, int width, int height)
{
    cairo_pattern_t *pattern;
    cairo_matrix_t   mat;

    cairo_translate (cr, PAD, PAD);

    pattern = create_pattern (cr);

    cairo_matrix_init_identity (&mat);
    cairo_matrix_scale (&mat, 2, 1.5);
    cairo_matrix_rotate (&mat, 1);
    cairo_matrix_translate (&mat, -PAT_WIDTH/4.0, -PAT_WIDTH/2.0);
    cairo_pattern_set_matrix (pattern, &mat);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);

    cairo_set_source (cr, pattern);
    cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
    cairo_paint (cr);

    cairo_pattern_destroy (pattern);

    return CAIRO_TEST_SUCCESS;
}
Exemplo n.º 3
0
int main(int argc, char* argv[])
{
	//load russian hyphenation patterns
	struct pattern_list_t* plist = create_pattern_list();
	size_t i = 0;
	while (patterns[i])
	{
		struct pattern_t* p = create_pattern(patterns[i], isdigit_func, ismarker_func, char2digit_func);
		add_patern(plist, p);
		++i;
	}
	sort_pattern_list(plist);
	
	//hyphenate test words
	size_t word_index = 0;
	while (test_words[word_index])
	{
		struct word_hyphenation_t* wh = hyphenate_word(test_words[word_index], plist, marker);
		i = 0;
		while (test_words[word_index][i])
		{
			if (wh->mask[i]) printf("-");
			printf("%c", test_words[word_index][i]);
			++i;
		}
		printf("\n");
		destroy_word_hyphenation(wh);
		
		++word_index;
	}

	//cleanup
	destroy_pattern_list(plist);
	return 0;
}
Exemplo n.º 4
0
/*
 * mode_check_pattern -- 'check_pattern' mode function
 */
static int
mode_check_pattern(const char *path_license, const char *path_to_check)
{
	char pattern[LICENSE_MAX_LEN];

	if (create_pattern(path_license, pattern) == -1)
		return -1;

	return verify_license(path_to_check, pattern, NULL);
}
Exemplo n.º 5
0
/*
 * mode_create_pattern_file -- 'create' mode function
 */
static int
mode_create_pattern_file(const char *path_license, const char *path_pattern)
{
	char pattern[LICENSE_MAX_LEN];

	if (create_pattern(path_license, pattern) == -1)
		return -1;

	return write_pattern(path_pattern, pattern);
}
Exemplo n.º 6
0
Action::Status CopyPatternAction::run() {
	owner->start(this);
	
	DBG_M_ACTIONS << " processing " << *this << "\n";
	status = Running;
    Value val;
    val = owner->getValue(property);
    std::vector<std::string>matches;
    rexp_info *info = create_pattern(pattern.c_str());
    find_matches(info, matches, val.asString().c_str());
    if (matches.size()) {
        owner->setValue(dest, matches[0]);
    }
    release_pattern(info);
	status = Complete;
	owner->stop(this);
	return status;
}
Exemplo n.º 7
0
Action::Status CopyAllPatternAction::run() {
	owner->start(this);
	
	DBG_M_ACTIONS << " processing " << *this << "\n";
	status = Running;
    Value val;
    val = owner->getValue(property);
    std::vector<std::string>matches;
    rexp_info *info = create_pattern(pattern.c_str());
    each_match(info, val.asString().c_str(), 0, matched, &matches);
    if (matches.size()) {
        std::string res;
        for (unsigned int i=0; i<matches.size(); ++i)
            res += matches[i];
        owner->setValue(dest, res);
    }
    release_pattern(info);
	status = Complete;
	owner->stop(this);
	return status;
}
static void
repeat_x (ccss_cairo_image_t const	*image,
	  cairo_t			*cr,
	  int32_t		         width,
	  int32_t		         height,
	  double			 tile_width,
	  double			 tile_height)
{
	cairo_pattern_t	*pattern;

	/* Create pattern for (width + tile_width, tile_height)
	 * so we can account for `background-position'. */
	pattern = create_pattern (image,
				  width + tile_width,
				  tile_height);
	g_return_if_fail (pattern);

	cairo_pattern_set_extend (pattern, CAIRO_EXTEND_NONE);
	cairo_set_source (cr, pattern);
	cairo_pattern_destroy (pattern), pattern = NULL;
	cairo_fill_preserve (cr);
}
Exemplo n.º 9
0
//Parses the received string and creates a pattern based on the parameters
void parser(char s[])
{
    char *p;
    int i = 0;
    int red = -1, green = -1, blue = -1;
    pattern_enum_t type = P_FLASH;
    int timestamp = -1;
    unsigned int delay = 0, period = 0;


    //Processing the received character array
    p = strtok (s, ",");
    while(p != NULL)
    {
        switch(i){
        case 0: {
            sscanf(p, "%d", &type);
            pc.printf("%d\r\n", type);
            if(strcmp(p, "flash") == 0)
            {
                type = P_FLASH;
                delay = 25;
            }
            else if(strcmp(p, "flash_slow") == 0)
            {
                type = P_FLASH;
                delay = 100;
            }
            else if(strcmp(p, "wave") == 0)
            {
                type = P_WAVE;
                delay = 25;
            }
            else if(strcmp(p, "wave_slow") == 0)
            {
                type = P_WAVE;
                delay = 100;
            }
            else if(strcmp(p, "fade") == 0)
            {
                type = P_FADE;
                delay = 25;
            }
            else if(strcmp(p, "on") == 0)
            {
                type = P_ON;
                delay = 25;
            }
            else{
                pc.printf("Pattern does not exist in the dictionary\r\n");
                return;
            }
            break;}
        case 1:{
            sscanf(p, "%d", &red);
            pc.printf("%d\r\n", red);
            break;}
        case 2:{
            sscanf(p, "%d", &green);
            pc.printf("%d\r\n", green);
            break;}
        case 3:{
            sscanf(p, "%d", &blue);
            pc.printf("%d\r\n", blue);
            break;}
        case 4:{
            break;}
        case 5:{
            break;}
        case 6:{
            sscanf(p, "%d", &timestamp);
            pc.printf("%d\r\n", timestamp);
            break;}
        case 7:{
            sscanf(p, "%d", &period);
            pc.printf("%d\r\n", period);
            break;}
        default:{
            pc.printf("Invalid string received\r\n");
            return;}
        }
        i++;
        p = strtok(NULL, ",");
        }//End of while

    //Converting int to uint8_t for r, g, b 

    uint32_t redUint, greenUint, blueUint;

    redUint = red;
    greenUint = green;
    blueUint = blue;

    create_pattern(type, redUint, greenUint, blueUint, delay, period);        
}
Exemplo n.º 10
0
//Parses the received string and creates a pattern based on the parameters
void parser(char s[])
{
    char *p, *q;
    char st[200];
    int i = 0;
    int patternShape = -1;
    int red = -1, green = -1, blue = -1;
    unsigned int delay = 0, period = 0;
    pattern_enum_t type = P_FLASH;
    direction_enum_t patternDirection = DIR_NONE;
    int timestamp = -1;


    //Processing the received character array
    p = strtok (s, ",");
    while(p != NULL)
    {
        switch(i){
        case 0: {
            pc.printf("%s\r\n", p);
            if(strcmp(p, "flash") == 0)
            {
                type = P_FLASH;
                delay = 25;
                select_all_pixels();
            }
            else if(strcmp(p, "flash_slow") == 0)
            {
                type = P_FLASH;
                delay = 100;
                select_all_pixels();
            }
            else if(strcmp(p, "wave") == 0)
            {
                type = P_WAVE;
                delay = 25;
                select_all_pixels();
            }
            else if(strcmp(p, "wave_slow") == 0)
            {
                type = P_WAVE;
                delay = 100;
                select_all_pixels();
            }
            else if(strcmp(p, "wave_fb") == 0)
            {
                type = P_WAVE_FB;
                delay = 25;
                select_all_pixels();
            }
            else if(strcmp(p, "wave_rf") == 0)
            {
                type = P_RISEFALL;
                delay = 25;
                select_all_pixels();
            }
            else if(strcmp(p, "flow") == 0)
            {
                type = P_WAVE_FLOW;
                delay = 25;
                select_all_pixels();
            }
            else{
                pc.printf("Pattern does not exist in the dictionary\r\n");
                return;
            }
            break;}
        case 1:{
            sscanf(p, "%d", &red);
            break;}
        case 2:{
            sscanf(p, "%d", &green);
            break;}
        case 3:{
            sscanf(p, "%d", &blue);
            break;}
        case 4:{
            if (strcmp(p, "up") == 0)
                patternDirection = DIR_UP;
            else if(strcmp(p, "down") == 0)
                patternDirection = DIR_DOWN;
            else if(strcmp(p, "left") == 0)
                patternDirection = DIR_LEFT;
            else if(strcmp(p, "right") == 0)
                patternDirection = DIR_RIGHT;
            else if(strcmp(p, "none") == 0)
                patternDirection = DIR_NONE;
            else{
                pc.printf("Invalid direction entered \r\n");
                return;
            }
            break;}
        case 5:{
            sscanf(p, "%d", &patternShape);
            break;}
        case 6:{
            sscanf(p, "%d", &timestamp);
            break;}
        case 7:{
            sscanf(p, "%u", &period);
            break;}
        case 8:{
            sscanf(p, "[%199[^]]]", st);
            
            clear_all_pixels();
            q = strtok(st, ";");
            while(q != NULL)
            {
                int val = std::atoi(q);
                pc.printf("%d\r\n", val);
                pixel_grid[val/PIXELCOLS][val%PIXELCOLS].selected = 1;
                q = strtok(NULL, ";");
            }
            break;}
        default:{
            pc.printf("Invalid string received\r\n");
            return;}
        }
        i++;
        p = strtok(NULL, ",");
        }//End of while

    

    //Converting int to uint8_t for r, g, b 

    uint8_t redUint, greenUint, blueUint;

    redUint = red;
    greenUint = green;
    blueUint = blue;

//    select_pattern(patternShape);

    //Create Pattern based on the values recevied from the server
    create_pattern(type, patternDirection, redUint, greenUint, blueUint, delay, period);
    }
Exemplo n.º 11
0
/****************************************
* main
*
* sets up the communication between the  main mbed
* inits the leds to check if the leds are working properly
* continuously checks for a command from the main mbed
* if new command received, then executes the appropriate function
*
****************************************/
int main()
{
    uint8_t R,G,B;
    pc.baud(9600);
    strip.begin();
    init_grid();

    /*Shutting down the leds*/
    clear_strip();    
    getColor(&R,&G,&B,"G");
    wait_ms(10);
    //clear_strip();
//    show_pixel(&pixel_grid[0][0], R, G, B, 500);
//    wait_ms(1000);

    pixel_grid[0][0].selected = 1;
    pixel_grid[1][1].selected = 1;
    pixel_grid[2][2].selected = 1;
    pixel_grid[2][0].selected = 1;
    pixel_grid[0][2].selected = 1;

    //pixel_grid[0][0].selected = 1;
//    pixel_grid[1][1].selected = 1;
//    pixel_grid[2][2].selected = 1;
//    pixel_grid[3][3].selected = 1;
//    pixel_grid[4][2].selected = 1;
//    pixel_grid[5][1].selected = 1;
//    pixel_grid[6][0].selected = 1;

//    select_all_pixels();
    
    create_pattern(P_WAVE_FLOW, DIR_RIGHT, R, G, B, 50, 5000);
    
//    pixel_grid[10][0].selected = 1;
//    pixel_grid[10][1].selected = 1;
//    pixel_grid[10][2].selected = 1;
//    pixel_grid[10][3].selected = 1;
//    pixel_grid[9][1].selected = 1;
//    pixel_grid[9][2].selected = 1;
//    pixel_grid[9][3].selected = 1;
//    pixel_grid[8][2].selected = 1;
//    pixel_grid[8][3].selected = 1;
//    pixel_grid[7][3].selected = 1;
    
//
//    create_pattern(P_CUSTOM, DIR_UP, 150, 80, 200, 50, 1000);
//    
    //pixel_grid[0][0].selected = 1;
//    pixel_grid[1][1].selected = 1;
//    pixel_grid[2][2].selected = 1;
//    pixel_grid[2][0].selected = 1;
//    pixel_grid[0][2].selected = 1;
//    
//    getColor(&R,&G,&B,"G");
//    
//    create_pattern(P_CUSTOM, DIR_UP, R, G, B, 25, 1000);
//    
//    pixel_grid[2][0].selected = 1;
//    pixel_grid[2][1].selected = 1;
//    pixel_grid[2][2].selected = 1;
//    pixel_grid[2][3].selected = 1;
//    
//    getColor(&R,&G,&B,"B");
//    
//    create_pattern(P_CUSTOM, DIR_UP, R, G, B, 50, 1000);
    
//    wait(0.1);
    
    clear_strip();
        
    while(1)
    {
        //wait for messages
        rxLen = rf_receive(rxBuffer, 128);
        if(rxLen > 0)
        {
            if(rxBuffer[0] == ID) 
            {
                char* rxBuffer1 = &rxBuffer[1];
                pc.printf("Received string %s \r\n",rxBuffer);
                parser(rxBuffer1);
            }
        }
    }
}