예제 #1
0
파일: textbox.c 프로젝트: bbw2008good/RTGUI
void rtgui_textbox_set_value(struct rtgui_textbox* box, const char* text)
{
	if (box->text != RT_NULL)
	{
		if (box->line_length > rt_strlen(text) + 1)
		{
			rt_memcpy(box->text, text, rt_strlen(text) + 1);
			/* set current position */
			box->position = 0;
			return;
		}
		else
		{
			/* free the old text */
			rtgui_free(box->text);
			box->text = RT_NULL;
		}
	}

	box->line_length = RTGUI_TEXTBOX_LINE_MAX > rt_strlen(text) + 1 ?
		RTGUI_TEXTBOX_LINE_MAX : rt_strlen(text) + 1;

	/* allocate line buffer */
	box->text = rtgui_malloc(box->line_length);
	rt_memset(box->text, 0, box->line_length);

	/* copy text */
	rt_memcpy(box->text, text, rt_strlen(text) + 1);

	/* set current position */
	box->position = 0;
}
예제 #2
0
int rthw_wifi_ap_start(char *ssid, char *password, int channel)
{
    int mode = 0, timeout = 20;
    rtw_security_t security_type = RTW_SECURITY_WPA2_AES_PSK;
    char *name = RT_NULL;

    mode = rthw_wifi_mode_get();
    if (mode == RTHW_MODE_AP)
    {
        name = WLAN0_NAME;
    }
    else if (mode == RTHW_MODE_STA_AP)
    {
        name = WLAN1_NAME;
    }
    else
    {
        return -1;
    }

    if(wext_get_mode(name, &mode) < 0)
    {
        rt_kprintf("L:%d wifi get mode err\n", __LINE__);
        return -1;
    }
    if (password == RT_NULL)
    {
        security_type = RTW_SECURITY_OPEN;
    }

    if(wifi_start_ap(ssid, security_type, password, rt_strlen(ssid), rt_strlen(password), 6) != 0)
    {
        rt_kprintf("ERROR: wifi_start_ap failed\n");
        return -1;
    }

    while(1) 
    {
        char essid[33];
        if(wext_get_ssid(name, (unsigned char *) essid) > 0)
        {
            if(strcmp((const char *) essid, (const char *)ssid) == 0) 
            {
                rt_kprintf("%s started\n", ssid);
                break;
            }
        }
        if(timeout == 0) 
        {
            rt_kprintf("Start AP timeout\n");   
            return -1;
        }
        rt_thread_delay(1 * RT_TICK_PER_SECOND);
        timeout --;
    }

    return 0;
}
예제 #3
0
/*
 * row, col 都是从0开始编号
 */
void rtgui_form_set_item(rtgui_form_t *form, const char * const item, int row, int col, int isupdate)
{
	int offset, len1, len2, i;
	char *pch;
	const char *pch1;

	if (NULL==form || NULL==item)
		return;

	if (row > form->row_cnt_of_fbody || col >= form->head_item_cnt) {
		printf_syn("fun:%s(), row(%d) or col(%d) error, should(%d, %d), %s!\n", __FUNCTION__, row, col,
				   (form->row_cnt_of_fbody+1), form->head_item_cnt, form->head_name[0]);
		return;
	}
	if (FAIL == get_offset_of_col(form, col, &offset))
		return;

	if (row < 1)
		return;
#if 0
	pch  = form->fbody + (row-1)*form->bytes_of_row;
	form_debug(("before set item[%s], %dth line:%s!\n", item, row, pch));
#endif
	/* 编译器对item的处理在某些条件下似乎会出现bug, const char *item */
	len1 = rt_strlen(item);
	len2 = rt_strlen(form->head_name[col]);
	pch  = form->fbody + (row-1)*form->bytes_of_row + offset;
	pch1 = item;
	i = MIN(len1, len2);

	form_debug(("len1:%d, len2:%d, i:%d, item[%s], %#x, %#x, %#x\n", len1, len2, i, item, item, *item, *(item+1)));

	len2 -= i;
	while (0 != i) {
		*pch++ = *pch1++;
		--i;
	}

	/* 用空格填充列剩余位置及列间隔 */
	len2 += GAG_BETWEEN_COL;
	while (len2--)
		*pch++ = ' ';

	/* 将每行的最后一列的最后一个字节设置为'\0' */
	if ((col+1) == form->head_item_cnt)
		*--pch = '\0';

#if 0
	pch  = form->fbody + (row-1)*form->bytes_of_row;
	form_debug(("after set, %dth line:%s!\n", row, pch));
#endif
	if (0 != isupdate)
		rtgui_form_update_row(form, row);

	//rtgui_widget_update(RTGUI_WIDGET(form));
	return;
}
예제 #4
0
void print_sink_data(void)
{
	int i, j, k;
	struct sinkinfo_wl_data_item_st *p;
	rt_err_t ret;
	char title[DEV_SN_BUF_STRING_WITH_NUL_LEN_MAX+4];

	if (NULL == sink_wl_collect_data) {
		printf_syn("func:%s(),  sink_wl_collect_data is NULL\n", __FUNCTION__);
		return;
	}

	ret = rt_sem_take(&sink_wl_data_sem, RT_WAITING_FOREVER);
	if (RT_EOK != ret) {
		printf_syn("take sink_wl_data_sem fail(%d)\n", ret);
		return;
	}

	p = sink_wl_collect_data;
#if 0
	rt_strncpy(title, p->pt_ct_sn, sizeof(title));
	i = rt_strlen(p->pt_ct_sn);
	title[i++] = ' ';
	title[i++] = 'p';
	title[i++] = 'a';
	j = i - 1;
	title[i++] = '-';
	title[i++] = '\0';
#endif

	for (k=0; k<SINKINFO_WL_DATA_ITEM_MAX_NO; ++k) {
		if ('\0' != p->pt_ct_sn[0]) {
			
			rt_strncpy(title, p->pt_ct_sn, sizeof(title));
			i = rt_strlen(p->pt_ct_sn);
			title[i++] = ' ';
			title[i++] = 'p';
			title[i++] = 'a';
			j = i - 1;
			title[i++] = '-';
			title[i++] = '\0';
			
			printf_syn("index %4d:\n", k);
			print_pt_ct_st_info(title, &p->item.ptc_data.pt_pa);
			title[j] = 'b';
			print_pt_ct_st_info(title, &p->item.ptc_data.pt_pb);
			title[j] = 'c';
			print_pt_ct_st_info(title, &p->item.ptc_data.pt_pc);
		}

		++p;
	}

	rt_sem_release(&sink_wl_data_sem);

	return;
}
예제 #5
0
int dfs_elm_getdents(struct dfs_fd *file, struct dirent *dirp, rt_uint32_t count)
{
    DIR *dir;
    FILINFO fno;
    FRESULT result;
    rt_uint32_t index;
    struct dirent *d;

    dir = (DIR *)(file->data);
    RT_ASSERT(dir != RT_NULL);

    /* make integer count */
    count = (count / sizeof(struct dirent)) * sizeof(struct dirent);
    if (count == 0)
        return -DFS_STATUS_EINVAL;

    index = 0;
    while (1)
    {
        char *fn;

        d = dirp + index;

        result = f_readdir(dir, &fno);
        if (result != FR_OK || fno.fname[0] == 0)
            break;

#if _USE_LFN
        fn = *fno.fname ? fno.fname : fno.altname;
#else
        fn = fno.fname;
#endif

        d->d_type = DFS_DT_UNKNOWN;
        if (fno.fattrib & AM_DIR)
            d->d_type = DFS_DT_DIR;
        else
            d->d_type = DFS_DT_REG;

        d->d_namlen = (rt_uint8_t)rt_strlen(fn);
        d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
        rt_strncpy(d->d_name, fn, rt_strlen(fn) + 1);

        index ++;
        if (index * sizeof(struct dirent) >= count)
            break;
    }

    if (index == 0)
        return elm_result_to_dfs(result);

    file->pos += index * sizeof(struct dirent);

    return index * sizeof(struct dirent);
}
예제 #6
0
rt_inline void tof_print(struct hm_tof_data* data)
{
    static char ble_buf[100];
    sprintf(ble_buf, "%ld:tof up=%f down=%f speed=%f\n\r",
            data->time, data->data.up, data->data.down, data->speed);
#if (HM_BOARD_UART_6 == 1)
    hm_ble_write(ble_buf, rt_strlen(ble_buf)+1);
#else
    rt_kprintf(ble_buf, rt_strlen(ble_buf)+1);
#endif
}
예제 #7
0
rt_inline void temp_print(struct hm_temp_data* data)
{
    static char ble_buf[100];
    sprintf(ble_buf, "%ld:temp R_hot=%f R_cold=%f hot=%f cold=%f\n\r",
            data->time, data->data.hot, data->data.cold, data->hot, data->cold);
#if (HM_BOARD_UART_6 == 1)
    hm_ble_write(ble_buf, rt_strlen(ble_buf)+1);
#else
    rt_kprintf(ble_buf, rt_strlen(ble_buf)+1);
#endif
}
예제 #8
0
rt_err_t rt_wlan_device_control(struct rt_wlan_device* device, rt_uint8_t cmd, void* arg)
{
    rt_err_t result;

    RT_ASSERT(device != RT_NULL);

    result = RT_EOK;
    switch (cmd)
    {
    case WLAN_CTRL_SET_SSID:
        RT_ASSERT(arg != RT_NULL);

        if (rt_strlen((char*)arg) >= SSID_NAME_MAX) result = -RT_ERROR;
        else
        {
            rt_strncpy(device->ssid, (char*)arg, SSID_NAME_MAX);
        }
        break;

    case WLAN_CTRL_SET_PASSWORD:
        RT_ASSERT(arg != RT_NULL);
        
        if (rt_strlen((char*)arg) >= PASSWORD_LENGTH_MAX) result = -RT_ERROR;
        else
        {
            rt_strncpy(device->password, (char*)arg, PASSWORD_LENGTH_MAX);
        }
        break;

    case WLAN_CTRL_SET_SECURITY:
        RT_ASSERT(arg != RT_NULL);
        device->security = *(rt_uint8_t*)arg;
        break;

    case WLAN_CTRL_SET_MODE:
        RT_ASSERT(arg != RT_NULL);
        device->mode = *(rt_uint8_t*)arg;
        break;

    case WLAN_CTRL_SET_CHANNEL:
        device->channel = *(rt_uint8_t*)arg;
        break;

	case WLAN_CTRL_SET_BSADDR:
		rt_memcpy(device->bs_addr, (rt_uint8_t*) arg, MAC_LENGTH_MAX);
		break;
    }
    
    return result;
}
예제 #9
0
/*
 * row, col 都是从0开始编号, 是表格的全局编号
 */
void rtgui_form_set_row(rtgui_form_t *form, const char *const rowstr, int row)
{
	int len1, len2, i;
	char *pch;
	const char *pch1;

	if (NULL==form || NULL==rowstr)
		return;

	if (row > form->row_cnt_of_fbody || row<1) {
		form_debug(("fun:%s(), row(%d) error!\n", __FUNCTION__, row));
		return;
	}

	/* 编译器对item的处理在某些条件下似乎会出现bug, const char *item */
	len1 = rt_strlen(rowstr);
	len2 = form->bytes_of_row;
	pch  = form->fbody + (row-1)*form->bytes_of_row;
	pch1 = rowstr;
	i = MIN(len1, len2);

	while (0 != i) {
		*pch++ = *pch1++;
		--i;
	}

	/* 将每行的最后一列的最后一个字节设置为'\0' */
	pch  = form->fbody + (row)*form->bytes_of_row - 1;
	*pch = '\0';

	return;
}
예제 #10
0
/**
 * This function will return the first occurrence of a string.
 *
 * @param s1 the source string
 * @param s2 the find string
 *
 * @return the first occurrence of a s2 in s1, or RT_NULL if no found.
 */
char *rt_strstr(const char *s1, const char *s2)
{
	int l1, l2;

	l2 = rt_strlen(s2);
	if (!l2)
		return (char *)s1;
	l1 = rt_strlen(s1);
	while (l1 >= l2) {
		l1 --;
		if (!rt_memcmp(s1, s2, l2))
			return (char *)s1;
		s1 ++;
	}
	return RT_NULL;
}
예제 #11
0
static char* _module_name(const char *path)
{
    const char *first, *end, *ptr;
    char *name;
    int size;

    ptr   = (char *)path;
    first = ptr;
    end   = path + rt_strlen(path);

    while (*ptr != '\0')
    {
        if (*ptr == '/')
            first = ptr + 1;
        if (*ptr == '.')
            end = ptr - 1;

        ptr ++;
    }

    size = end - first + 1;
    name = rt_malloc(size);
    rt_strncpy(name, first, size);
    name[size] = '\0';

    return name;
}
예제 #12
0
/*
 * head_name[] -- 最后一个元素必须是NULL
 * rows -- 包含表头在内
 */
rtgui_form_t *rtgui_form_create(const char *head_name[], int rows, int cols, rtgui_rect_t *rect)
{
	int i, len;
	struct rtgui_form *form;

	if (NULL==head_name || NULL==rect)
		return NULL;

	form = (struct rtgui_form *)rtgui_widget_create(RTGUI_FORM_TYPE);
	if (NULL == form)
		return NULL;

	i = 0;
	while (NULL != head_name[i])
		++i;

	if (i != cols) {
		form_debug(("%s(), head items (%d) not same as cols(%d)!\n", __FUNCTION__, i, cols));
		goto err_entry;
	}

	form_debug(("%s(), line:%d: rows:%d, cols:%d!\n", __FUNCTION__, __LINE__, rows, cols));

	len = 0;
	for (i=0; i<cols; ++i) {
		len += rt_strlen(head_name[i]);
	}
	len += cols * GAG_BETWEEN_COL;

	form->fbody = rt_calloc(len*(rows-1), 1); /* 不包含表格头部占用的存储空间 */
	if (NULL == form->fbody) {
		form_debug(("fun:%s(), line:%d:%d malloc fail!\n", __FUNCTION__, __LINE__, len*(rows-1)));
		goto err_entry;
	}

	form->head_name = rt_calloc(cols, sizeof(head_name[0]));
	if (NULL == form->head_name) {
		form_debug(("fun:%s(), line:%d:%d malloc fail!\n", __FUNCTION__, __LINE__, cols * sizeof(head_name[0])));
		rt_free(form->fbody);
		goto err_entry;
	}

	form_debug(("%s(), line:%d: fbody-len:%d, head-name-len:%d!\n", __FUNCTION__, __LINE__,
				len*(rows-1), cols * sizeof(head_name[0])));

	for (i=0; i<cols; ++i) {
		form->head_name[i] = head_name[i];
	}
	form->head_item_cnt		= cols;
	form->row_cnt_of_fbody	= rows - 1;
	form->bytes_of_row		= len;

	rtgui_widget_set_rect(RTGUI_WIDGET(form), rect);

	return form;

err_entry:
	rtgui_widget_destroy(RTGUI_WIDGET(form));
	return NULL;
}
예제 #13
0
int cmd_mv(int argc, char** argv)
{
    if (argc != 3)
    {
        rt_kprintf("Usage: mv SOURCE DEST\n");
        rt_kprintf("Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n");
    }
    else
    {
		int fd;
		char *dest = RT_NULL;

        rt_kprintf("%s => %s\n", argv[1], argv[2]);

		fd = open(argv[2], O_DIRECTORY, 0);
		if (fd >= 0)
		{
			char *src;
			
			close(fd);

			/* it's a directory */			
			dest = (char*)rt_malloc(DFS_PATH_MAX);
			if (dest == RT_NULL)
			{
				rt_kprintf("out of memory\n");
				return -RT_ENOMEM;
			}

			src = argv[1] + rt_strlen(argv[1]);
			while (src != argv[1]) 
			{
				if (*src == '/') break;
				src --;
			}

			rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src);
		}
		else
		{
			fd = open(argv[2], O_RDONLY, 0);
			if (fd >= 0)
			{
				close(fd);
				
				unlink(argv[2]);
			}

			dest = argv[2];
		}

		rename(argv[1], dest);
		if (dest != RT_NULL && dest != argv[2]) rt_free(dest);
    }

    return 0;
}
예제 #14
0
int dfs_romfs_getdents(struct dfs_fd *file, struct dirent *dirp, uint32_t count)
{
    rt_size_t index;
    const char *name;
    struct dirent *d;
    struct romfs_dirent *dirent, *sub_dirent;

    dirent = (struct romfs_dirent *)file->data;
    if (check_dirent(dirent) != 0)
        return -EIO;
    RT_ASSERT(dirent->type == ROMFS_DIRENT_DIR);

    /* enter directory */
    dirent = (struct romfs_dirent *)dirent->data;

    /* make integer count */
    count = (count / sizeof(struct dirent));
    if (count == 0)
        return -EINVAL;

    index = 0;
    for (index = 0; index < count && file->pos < file->size; index ++)
    {
        d = dirp + index;

        sub_dirent = &dirent[file->pos];
        name = sub_dirent->name;

        /* fill dirent */
        if (sub_dirent->type == ROMFS_DIRENT_DIR)
            d->d_type = DT_DIR;
        else
            d->d_type = DT_REG;

        d->d_namlen = rt_strlen(name);
        d->d_reclen = (rt_uint16_t)sizeof(struct dirent);
        rt_strncpy(d->d_name, name, rt_strlen(name) + 1);

        /* move to next position */
        ++ file->pos;
    }

    return index * sizeof(struct dirent);
}
예제 #15
0
void rtgui_textbox_ondraw(rtgui_textbox_t *box)
{
	/* draw button */
	rtgui_rect_t rect;
	struct rtgui_dc *dc;
	rtgui_color_t fc;

	RT_ASSERT(box != RT_NULL);

	/* begin drawing */
	dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(box));
	if (dc == RT_NULL)
		return;

	/* get widget rect */
	rtgui_widget_get_rect(RTGUI_WIDGET(box), &rect);
	fc = RTGUI_WIDGET_FOREGROUND(box);

	rtgui_rect_inflate(&rect, -1);

	/* fill widget rect with white color */
	RTGUI_WIDGET_BACKGROUND(box) = white;
	rtgui_dc_fill_rect(dc, &rect);

	rtgui_rect_inflate(&rect, 1);
	/* draw border */
	RTGUI_WIDGET_FOREGROUND(box) = RTGUI_RGB(123, 158, 189);
	rtgui_dc_draw_rect(dc, &rect);

	/* draw text */
	RTGUI_WIDGET_FOREGROUND(box) = fc;
	if (box->text != RT_NULL)
	{
		rect.x1 += RTGUI_WIDGET_DEFAULT_MARGIN;
		/* draw single text */
		if (box->flag & RTGUI_TEXTBOX_MASK)
		{
			/* draw mask char */
			rt_size_t len = rt_strlen(box->text);
			if (len > 0)
			{
				char *text_mask = rtgui_malloc(len + 1);
				rt_memset(text_mask, box->mask_char, len + 1);
				text_mask[len] = 0;
				rtgui_dc_draw_text(dc, text_mask+box->first_pos, &rect);
				rtgui_free(text_mask);
			}
		}
		else
		{
			rtgui_dc_draw_text(dc, box->text+box->first_pos, &rect);
		}
	}

	rtgui_dc_end_drawing(dc);
}
예제 #16
0
/**
 * This function will duplicate a string.
 *
 * @param s the string to be duplicated
 *
 * @return the duplicated string pointer
 */
char *rt_strdup(const char *s)
{
	rt_size_t len = rt_strlen(s) + 1;
	char *tmp = (char *)rt_malloc(len);

	if (!tmp) return RT_NULL;

	rt_memcpy(tmp, s, len);
	return tmp;
}
예제 #17
0
static void elog_kw(uint8_t argc, char **argv) {
    if (argc > 1) {
        if (rt_strlen(argv[1]) <= ELOG_FILTER_KW_MAX_LEN) {
            elog_set_filter_kw(argv[1]);
        } else {
            rt_kprintf("The keyword length is too long. Max is %d.\n", ELOG_FILTER_KW_MAX_LEN);
        }
    } else {
        elog_set_filter_kw("");
    }
}
예제 #18
0
const char* finsh_get_prompt()
{
    #define _MSH_PROMPT "msh "
    #define _PROMPT 	"finsh "
    static char finsh_prompt[RT_CONSOLEBUF_SIZE + 1] = {0};

#ifdef FINSH_USING_MSH
    if (msh_is_used()) strcpy(finsh_prompt, _MSH_PROMPT);
    else
#endif
    strcpy(finsh_prompt, _PROMPT);

#if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR)
    /* get current working directory */
    getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt));
#endif

    strcat(finsh_prompt, ">");

    return finsh_prompt;
}
예제 #19
0
파일: shell.c 프로젝트: onelife/rt-thread
static void finsh_wait_auth(void)
{
    char ch;
    rt_bool_t input_finish = RT_FALSE;
    char password[FINSH_PASSWORD_MAX] = { 0 };
    rt_size_t cur_pos = 0;
    /* password not set */
    if (rt_strlen(finsh_get_password()) == 0) return;
    
    while (1)
    {
        rt_kprintf("Password for login: "******"*");
                    password[cur_pos++] = ch;
                }
                else if (ch == '\b' && cur_pos > 0)
                {
                    /* backspace */
                    password[cur_pos] = '\0';
                    cur_pos--;
                    rt_kprintf("\b \b");
                }
                else if (ch == '\r' || ch == '\n')
                {
                    rt_kprintf("\n");
                    input_finish = RT_TRUE;
                    break;
                }
            }
        }
        if (!rt_strncmp(shell->password, password, FINSH_PASSWORD_MAX)) return;
        else
        {
            /* authentication failed, delay 2S for retry */
            rt_thread_delay(2 * RT_TICK_PER_SECOND);
            rt_kprintf("Sorry, try again.\n");
            cur_pos = 0;
            input_finish = RT_FALSE;
            rt_memset(password, '\0', FINSH_PASSWORD_MAX);
        }
    }
}
예제 #20
0
/* set textbox text */
void rtgui_textbox_set_value(rtgui_textbox_t* box, const char* text)
{
	if(box->text != RT_NULL)
	{/* yet exist something */
		/* free the old text */
		rtgui_free(box->text);
		box->text = RT_NULL;
	}

	/* no something */
	box->line_length = ((rt_strlen(text)+1)/RTGUI_TEXTBOX_LINE_MAX+1)*RTGUI_TEXTBOX_LINE_MAX;

	/* allocate line buffer */
	box->text = rtgui_malloc(box->line_length);
	rt_memset(box->text, 0, box->line_length);

	/* copy text */
	rt_memcpy(box->text, text, rt_strlen(text) + 1);

	/* set current position */
	box->position = rt_strlen(text);
}
예제 #21
0
파일: shell.c 프로젝트: onelife/rt-thread
/**
 * set a new password for finsh
 *
 * @param password new password
 *
 * @return result, RT_EOK on OK, -RT_ERROR on the new password length is less than
 *  FINSH_PASSWORD_MIN or greater than FINSH_PASSWORD_MAX
 */
rt_err_t finsh_set_password(const char *password) {
    rt_ubase_t level;
    rt_size_t pw_len = rt_strlen(password);

    if (pw_len < FINSH_PASSWORD_MIN || pw_len > FINSH_PASSWORD_MAX)
        return -RT_ERROR;

    level = rt_hw_interrupt_disable();
    rt_strncpy(shell->password, password, FINSH_PASSWORD_MAX);
    rt_hw_interrupt_enable(level);

    return RT_EOK;
}
예제 #22
0
int system(const char *command)
{
    int ret = -RT_ENOMEM;
    char *cmd = rt_strdup(command);

    if (cmd)
    {
        ret = msh_exec(cmd, rt_strlen(cmd));
        rt_free(cmd);
    }

    return ret;
}
예제 #23
0
파일: core.c 프로젝트: Andy51/rt-thread
/**
 * This function will handle get_string_descriptor request.
 *
 * @param device the usb device object.
 * @param setup the setup request.
 *
 * @return RT_EOK on successful, -RT_ERROR on invalid request.
 */
static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup)
{
    struct ustring_descriptor str_desc;
    rt_uint8_t index, i;
    rt_uint32_t len;

    /* parameter check */
    RT_ASSERT(device != RT_NULL);
    RT_ASSERT(setup != RT_NULL);

    RT_DEBUG_LOG(RT_DEBUG_USB, ("_get_string_descriptor\n"));

    str_desc.type = USB_DESC_TYPE_STRING;
    index = setup->value & 0xFF;

    if (index > USB_STRING_INTERFACE_INDEX)
    {
        rt_kprintf("unknown string index\n");
        dcd_ep_stall(device->dcd, 0);
        return -RT_ERROR;
    }
    if (index == 0)
    {
        str_desc.bLength = 4;
        str_desc.String[0] = 0x09;
        str_desc.String[1] = 0x04;
    }
    else
    {
        len = rt_strlen(device->str[index]);
        str_desc.bLength = len*2 + 2;

        for (i=0; i<len; i++)
        {
            str_desc.String[i*2] = device->str[index][i];
            str_desc.String[i*2 + 1] = 0;
        }
    }

    if (setup->length > str_desc.bLength)
        len = str_desc.bLength;
    else
        len = setup->length;

    /* send string descriptor to endpoint 0 */
    dcd_ep_write(device->dcd, 0, (rt_uint8_t*)&str_desc, len);

    return RT_EOK;
}
예제 #24
0
파일: adk.c 프로젝트: DigFarmer/aircraft
/**
 * This function will do USB_REQ_SEND_STRING request to set idle period to the usb adk device
 *
 * @param intf the interface instance.
 * @duration the idle period of requesting data.
 * @report_id the report id
 * 
 * @return the error code, RT_EOK on successfully.
*/
static rt_err_t rt_usbh_adk_send_string(struct uintf* intf, rt_uint16_t index, 
    const char* str)
{
    struct ureqest setup;
    uinst_t device;    
    int timeout = 100;
            
        /* parameter check */
    RT_ASSERT(intf != RT_NULL);
    RT_ASSERT(intf->device != RT_NULL);

    device = intf->device;

    setup.request_type = USB_REQ_TYPE_DIR_OUT | USB_REQ_TYPE_VENDOR | 
        USB_REQ_TYPE_DEVICE;
    setup.request = USB_REQ_SEND_STRING;
    setup.index = index;
    setup.length = rt_strlen(str) + 1;
    setup.value = 0;

    if(rt_usb_hcd_control_xfer(device->hcd, device, &setup, (void*)str, 
        rt_strlen(str) + 1, timeout) == 0) return RT_EOK;
    else return -RT_FALSE;   
}
예제 #25
0
static int get_offset_of_col(struct rtgui_form *form, int col, int *offset)
{
	int i, j, len;

	if (NULL == form || col >= form->head_item_cnt) {
		form_debug(("fun:%s(), col(%d) error!\n", __FUNCTION__, col));
		return FAIL;
	}

	j = col;
	len = 0;
	for(i=0; i<j; ++i)
		len += rt_strlen(form->head_name[i]);
	*offset = len + j*GAG_BETWEEN_COL;

	return SUCC;
}
예제 #26
0
파일: textbox.c 프로젝트: xiiing/RTGUI
static void rtgui_textbox_onmouse(rtgui_textbox_t *box, struct rtgui_event_mouse *event)
{
	rt_size_t length;
	rt_uint16_t posbak = box->position;

	RT_ASSERT(box != RT_NULL);
	RT_ASSERT(event != RT_NULL);

	length = rt_strlen((char*)box->text);

	if (event->button & RTGUI_MOUSE_BUTTON_LEFT && event->button & RTGUI_MOUSE_BUTTON_DOWN)
	{
		rt_int32_t x;
		/* single line text */
		/* set caret position */
		x = event->x - RTGUI_WIDGET(box)->extent.x1;
		if (x < 0)
		{
			box->position = 0;
		}
		else if (x > (length - box->first_pos) * box->font_width)
		{
			box->position = length - box->first_pos;
		}
		else
		{
			box->position = x / box->font_width;
		}

		if (box->flag & RTGUI_TEXTBOX_CARET_SHOW)
		{
			if (box->caret_timer != RT_NULL)
				rtgui_timer_stop(box->caret_timer);

			box->flag &= ~RTGUI_TEXTBOX_CARET_SHOW;
			rtgui_textbox_draw_caret(box, posbak);

			if (box->caret_timer != RT_NULL)
				rtgui_timer_start(box->caret_timer);
		}

		rtgui_textbox_init_caret(box, box->position);
		box->flag |= RTGUI_TEXTBOX_CARET_SHOW;
		rtgui_textbox_draw_caret(box, box->position);
	}
}
예제 #27
0
void setenv(uint8_t argc, char **argv) {
    uint8_t i;
    char c_value = NULL;
    char *value = &c_value;
    if (argc > 3) {
        /* environment variable value string together */
        for (i = 0; i < argc - 2; i++) {
            argv[2 + i][rt_strlen(argv[2 + i])] = ' ';
        }
    }
    if (argc == 1) {
        ef_set_env(value, value);
    } else if (argc == 2) {
        ef_set_env(argv[1], value);
    } else {
        ef_set_env(argv[1], argv[2]);
    }
}
예제 #28
0
void rtgui_label_set_text(rtgui_label_t* label, const char* text)
{
	RT_ASSERT(label != RT_NULL);

	if (label->text != RT_NULL)
	{
		/* it's a same text string */
		if (rt_strncmp(text, label->text, rt_strlen(text)) == 0) return;
		
		/* release old text memory */
		rtgui_free(label->text);
	}

	if (text != RT_NULL) label->text = (char*)rt_strdup((const char*)text);
	else label->text = RT_NULL;

	/* update widget */
	rtgui_theme_draw_label(label);
}
예제 #29
0
파일: dfs_uffs.c 프로젝트: bobo8909/RTT
static int dfs_uffs_mount(
	struct dfs_filesystem* fs,
    unsigned long rwflag,
    const void* data)
{
	rt_base_t index;
	uffs_MountTable * mount_part;
	struct rt_mtd_nand_device * dev;
	
	RT_ASSERT(rt_strlen(fs->path) < (UFFS_MOUNT_PATH_MAX-1));
	dev = RT_MTD_NAND_DEVICE(fs->dev_id);

	/*1. find a empty entry in partition table */
	for (index = 0; index < UFFS_DEVICE_MAX ; index ++)
	{
		if (nand_part[index].dev == RT_NULL)
			break;
	}
	if (index == UFFS_DEVICE_MAX)
		return -DFS_STATUS_ENOENT;

	/*2. fill partition structure */
	nand_part[index].dev = dev;

	/* make a right mount path for uffs, end with '/' */
	rt_snprintf(nand_part[index].mount_path, UFFS_MOUNT_PATH_MAX, "%s/", fs->path);
	if (nand_part[index].mount_path[1] == '/')
		nand_part[index].mount_path[1] = 0;

	mount_part = &(nand_part[index].mount_table);
	mount_part->mount	= nand_part[index].mount_path;
	mount_part->dev = &(nand_part[index].uffs_dev);
	rt_memset(mount_part->dev, 0, sizeof(uffs_Device));//in order to make uffs happy.
	mount_part->dev->_private = dev;   /* save dev_id into uffs */
	mount_part->start_block = dev->block_start;
	mount_part->end_block = dev->block_end;
	/*3. mount uffs */
	if (init_uffs_fs(&nand_part[index]) < 0)
	{
		return uffs_result_to_dfs(uffs_get_error());
	}
	return 0;
}
예제 #30
0
파일: utils.c 프로젝트: 1847123212/SFUD
/**
 * Calc hardware version's Integer value
 */
void calc_hardware_version(void) {
    char const *start_addr = NULL;
    char *match_addr = NULL;
    char c_value[4] = { 0 };
    uint8_t c_length = 0, i = 0;

    start_addr = get_hardware_version();
    match_addr = rt_strstr((char *) start_addr, ".");
    while (match_addr != NULL) {
        c_length = match_addr - start_addr;
        rt_memcpy(c_value, start_addr, c_length);
        hardware_version[i++] = atoi(c_value);
        match_addr++;
        start_addr = match_addr;
        match_addr = rt_strstr((char *) start_addr, ".");
    }
    c_length = rt_strlen(start_addr);
    rt_memcpy(c_value, start_addr, c_length);
    hardware_version[i] = atoi(c_value);
}