<input type="text" name="em9" id="em9" value="${tud.em9 }" autocomplete="off"/>添加不能为空
时间: 2023-12-12 11:03:28 浏览: 28
可以使用has-value和has-values这两个npm包来判断输入是否为空。具体方法如下:
```javascript
// 安装has-value和has-values
npm install has-value has-values
// 引入has-value和has-values
const hasValue = require('has-value');
const hasValues = require('has-values');
// 判断单个输入是否为空
const input = '';
console.log(hasValue(input)); // 输出:false
// 判断多个输入是否都不为空
const inputs = ['', 'abc', null, undefined];
console.log(hasValues(inputs)); // 输出:false
```
相关问题
tud_hid_report()怎么使用
函数tud_hid_report()是TinyUSB库中用于发送HID报告的函数。它的使用方式如下:
1. 首先,需要在你的代码中包含头文件 "tinyusb.h"。
2. 然后,在你的代码中定义一个与HID设备对应的结构体,可以使用tusb_hid_report_descriptor_t类型。例如:
```
tusb_hid_report_descriptor_t const midi_report_desc[] =
{
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x81, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x01, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x82, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x02, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x83, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x03, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x84, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x04, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x85, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x05, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x86, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x06, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x87, 64, 10 },
{ 0, 0, HID_PROTOCOL_NONE, sizeof(midi_report), 0x07, 64, 10 },
{ 0, 0, 0, 0, 0, 0, 0 }, // end of report descriptor
};
```
其中,midi_report_desc是一个数组,用来描述HID设备的各个特性。这里只是一个示例,具体内容需要根据实际情况进行修改。
3. 在你的代码中调用tud_hid_report()函数,将要发送的HID报告数据写入到函数的参数buf中。例如:
```
void send_midi_report(uint8_t const *report, uint32_t len)
{
tud_hid_report(0, report, len);
}
```
其中,第一个参数0是HID接口的编号,如果你的设备只有一个HID接口,可以直接传入0;第二个参数report是一个指向要发送的HID报告数据的指针;第三个参数len是要发送的HID报告数据的长度。
4. 最后,将你的代码中的send_midi_report()函数调用放在适当的位置,以便在需要发送HID报告时进行调用。
注意:在使用tud_hid_report()函数之前,需要先调用tud_task()函数,以进行TinyUSB库的初始化。
灵动微mm32f系列的 tinyusb 例程 是怎样进入 suspend 模式的,以及怎样退出的,请根据demo code ,帮我写一份进入 suspend 和 resume 的示例代码
在灵动微mm32f系列的 tinyusb 例程中,进入和退出suspend模式的代码如下:
进入suspend模式:
```c
void tud_suspend_cb(void)
{
// Wake up by uart or button press
// so no need to do anything here
// but must call tud_rh_suspend_complete() to acknowledge the suspend request
tud_rh_suspend_complete();
}
// Invoked when usb bus is resumed
void tud_resume_cb(void)
{
(void) tud_control_xfer(0, 0, 0, NULL, 0); // dummy control request to wake up host if it is sleeping
}
```
在进入suspend模式时,需要调用tud_rh_suspend_complete()函数,以确认收到suspend请求。当usb bus被唤醒时,调用tud_resume_cb()函数。
退出suspend模式:
```c
// Invoked when received control request to enter DFU mode
bool tud_control_request_cb(uint8_t rhport, tusb_control_request_t const * p_request)
{
switch (p_request->bmRequestType_bit.typeRecipient)
{
case TUSB_REQ_TYPE_STANDARD:
switch (p_request->bRequest)
{
case TUSB_REQ_SET_FEATURE:
if ( p_request->wValue == 0 ) tud_suspend();
break;
case TUSB_REQ_CLEAR_FEATURE:
if ( p_request->wValue == 0 ) tud_resume();
break;
}
break;
}
return false;
}
void tud_suspend(void)
{
// Stop usb
usb_device_disconnect();
// Enter into deep sleep mode
// ...
}
void tud_resume(void)
{
// Leave deep sleep mode
// ...
// Start usb
usb_device_connect();
}
```
在退出suspend模式时,需要在tud_control_request_cb()函数中,根据收到的控制请求来判断是否需要退出suspend模式。在tud_suspend()函数中,停止usb设备,并进入深度睡眠模式。在tud_resume()函数中,退出深度睡眠模式,并重新启动usb设备。