bowen liu
/
mbed-os-example-blinky
ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/demo/main.cpp@50:9ecaa144d1f3, 2017-07-18 (annotated)
- Committer:
- tmboy
- Date:
- Tue Jul 18 09:08:52 2017 +0000
- Revision:
- 50:9ecaa144d1f3
- Parent:
- 47:9e361da97763
add .json
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TMBOY | 47:9e361da97763 | 1 | // Copyright (2016) Baidu Inc. All rights reserved. |
TMBOY | 47:9e361da97763 | 2 | /** |
TMBOY | 47:9e361da97763 | 3 | * File: main.cpp |
TMBOY | 47:9e361da97763 | 4 | * Desc: Sample code for startup DuerOS |
TMBOY | 47:9e361da97763 | 5 | */ |
TMBOY | 47:9e361da97763 | 6 | |
TMBOY | 47:9e361da97763 | 7 | #include "mbed.h" |
TMBOY | 47:9e361da97763 | 8 | #include "baidu_media_manager.h" |
TMBOY | 47:9e361da97763 | 9 | #include "duer_app.h" |
TMBOY | 47:9e361da97763 | 10 | #include "events.h" |
TMBOY | 47:9e361da97763 | 11 | #include "duer_log.h" |
TMBOY | 47:9e361da97763 | 12 | #if defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 13 | #include "SDMMCFileSystem.h" |
TMBOY | 47:9e361da97763 | 14 | #include "WiFiStackInterface.h" |
TMBOY | 47:9e361da97763 | 15 | #include "factory_test.h" |
TMBOY | 47:9e361da97763 | 16 | #include "gpadckey.h" |
TMBOY | 47:9e361da97763 | 17 | #ifdef RDA_SMART_CONFIG |
TMBOY | 47:9e361da97763 | 18 | #include "rda5981_smartconfig.h" |
TMBOY | 47:9e361da97763 | 19 | #endif // RDA_SMART_CONFIG |
TMBOY | 47:9e361da97763 | 20 | #elif defined(TARGET_K64F) |
TMBOY | 47:9e361da97763 | 21 | #include "SDFileSystem.h" |
TMBOY | 47:9e361da97763 | 22 | #include "EthernetInterface.h" |
TMBOY | 47:9e361da97763 | 23 | #else |
TMBOY | 47:9e361da97763 | 24 | #error "Not supported" |
TMBOY | 47:9e361da97763 | 25 | #endif // TARGET_UNO_91H |
TMBOY | 47:9e361da97763 | 26 | |
TMBOY | 47:9e361da97763 | 27 | #if defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 28 | |
TMBOY | 47:9e361da97763 | 29 | // TODO: Configure your AP |
TMBOY | 47:9e361da97763 | 30 | #ifndef CUSTOM_SSID |
TMBOY | 47:9e361da97763 | 31 | #define CUSTOM_SSID ("TP-LINK_69DA") |
TMBOY | 47:9e361da97763 | 32 | #endif // CUSTOM_SSID |
TMBOY | 47:9e361da97763 | 33 | |
TMBOY | 47:9e361da97763 | 34 | #ifndef CUSTOM_PASSWD |
TMBOY | 47:9e361da97763 | 35 | #define CUSTOM_PASSWD ("qwertyuiop") |
TMBOY | 47:9e361da97763 | 36 | #endif // CUSTOM_PASSWD |
TMBOY | 47:9e361da97763 | 37 | |
TMBOY | 47:9e361da97763 | 38 | GpadcKey key_up(KEY_A3); |
TMBOY | 47:9e361da97763 | 39 | GpadcKey key_down(KEY_A4); |
TMBOY | 47:9e361da97763 | 40 | |
TMBOY | 47:9e361da97763 | 41 | // Initialize SD card |
TMBOY | 47:9e361da97763 | 42 | SDMMCFileSystem g_sd(GPIO_PIN9, GPIO_PIN0, GPIO_PIN3, GPIO_PIN7, GPIO_PIN12, GPIO_PIN13, "sd"); |
TMBOY | 47:9e361da97763 | 43 | |
TMBOY | 47:9e361da97763 | 44 | static WiFiStackInterface s_net_stack; |
TMBOY | 47:9e361da97763 | 45 | #else |
TMBOY | 47:9e361da97763 | 46 | SDFileSystem g_sd = SDFileSystem(D11, D12, D13, D10, "sd"); |
TMBOY | 47:9e361da97763 | 47 | static EthernetInterface s_net_stack; |
TMBOY | 47:9e361da97763 | 48 | #endif // TARGET_UNO_91H |
TMBOY | 47:9e361da97763 | 49 | |
TMBOY | 47:9e361da97763 | 50 | static unsigned char s_volume = 8; |
TMBOY | 47:9e361da97763 | 51 | |
TMBOY | 47:9e361da97763 | 52 | void* baidu_get_netstack_instance(void) { |
TMBOY | 47:9e361da97763 | 53 | return (void*)&s_net_stack; |
TMBOY | 47:9e361da97763 | 54 | } |
TMBOY | 47:9e361da97763 | 55 | |
TMBOY | 47:9e361da97763 | 56 | void voice_up() { |
TMBOY | 47:9e361da97763 | 57 | if (s_volume < 15) { |
TMBOY | 47:9e361da97763 | 58 | duer::MediaManager::instance().set_volume(++s_volume); |
TMBOY | 47:9e361da97763 | 59 | } |
TMBOY | 47:9e361da97763 | 60 | } |
TMBOY | 47:9e361da97763 | 61 | |
TMBOY | 47:9e361da97763 | 62 | void voice_down() { |
TMBOY | 47:9e361da97763 | 63 | if (s_volume > 0) { |
TMBOY | 47:9e361da97763 | 64 | duer::MediaManager::instance().set_volume(--s_volume); |
TMBOY | 47:9e361da97763 | 65 | } |
TMBOY | 47:9e361da97763 | 66 | } |
TMBOY | 47:9e361da97763 | 67 | |
TMBOY | 47:9e361da97763 | 68 | // main() runs in its own thread in the OS |
TMBOY | 47:9e361da97763 | 69 | int main() { |
TMBOY | 47:9e361da97763 | 70 | #if defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 71 | // Initialize RDA FLASH |
TMBOY | 47:9e361da97763 | 72 | const unsigned int RDA_FLASH_SIZE = 0x400000; // Flash Size |
TMBOY | 47:9e361da97763 | 73 | const unsigned int RDA_SYS_DATA_ADDR = 0x18204000; // System Data Area, fixed size 4KB |
TMBOY | 47:9e361da97763 | 74 | const unsigned int RDA_USER_DATA_ADDR = 0x18205000; // User Data Area start address |
TMBOY | 47:9e361da97763 | 75 | const unsigned int RDA_USER_DATA_LENG = 0x3000; // User Data Area Length |
TMBOY | 47:9e361da97763 | 76 | |
TMBOY | 47:9e361da97763 | 77 | rda5981_set_flash_size(RDA_FLASH_SIZE); |
TMBOY | 47:9e361da97763 | 78 | rda5981_set_user_data_addr(RDA_SYS_DATA_ADDR, RDA_USER_DATA_ADDR, RDA_USER_DATA_LENG); |
TMBOY | 47:9e361da97763 | 79 | |
TMBOY | 47:9e361da97763 | 80 | // Test added by RDA |
TMBOY | 47:9e361da97763 | 81 | factory_test(); |
TMBOY | 47:9e361da97763 | 82 | #endif |
TMBOY | 47:9e361da97763 | 83 | |
TMBOY | 47:9e361da97763 | 84 | DUER_LOGI("\nEntry Tinydu Main>>>>\n"); |
TMBOY | 47:9e361da97763 | 85 | |
TMBOY | 47:9e361da97763 | 86 | duer::MediaManager::instance().initialize(); |
TMBOY | 47:9e361da97763 | 87 | |
TMBOY | 47:9e361da97763 | 88 | #if defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 89 | key_up.fall(&voice_up); |
TMBOY | 47:9e361da97763 | 90 | key_down.fall(&voice_down); |
TMBOY | 47:9e361da97763 | 91 | #endif |
TMBOY | 47:9e361da97763 | 92 | |
TMBOY | 47:9e361da97763 | 93 | // Brings up the network interface |
TMBOY | 47:9e361da97763 | 94 | #ifdef RDA_SMART_CONFIG |
TMBOY | 47:9e361da97763 | 95 | typedef void (*dummy_func)(); |
TMBOY | 47:9e361da97763 | 96 | mbed::GpadcKey key_erase = mbed::GpadcKey(KEY_A2); |
TMBOY | 47:9e361da97763 | 97 | key_erase.fall((dummy_func)rda5981_flash_erase_smartconfig_data); |
TMBOY | 47:9e361da97763 | 98 | |
TMBOY | 47:9e361da97763 | 99 | if (s_net_stack.connect(NULL, NULL, NSAPI_SECURITY_NONE) == 0) { |
TMBOY | 47:9e361da97763 | 100 | #elif defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 101 | if (s_net_stack.connect(CUSTOM_SSID, CUSTOM_PASSWD, NSAPI_SECURITY_NONE) == 0) { |
TMBOY | 47:9e361da97763 | 102 | #else |
TMBOY | 47:9e361da97763 | 103 | if (s_net_stack.connect() == 0) { |
TMBOY | 47:9e361da97763 | 104 | #endif // RDA_SMART_CONFIG |
TMBOY | 47:9e361da97763 | 105 | const char* ip = s_net_stack.get_ip_address(); |
TMBOY | 47:9e361da97763 | 106 | const char* mac = s_net_stack.get_mac_address(); |
TMBOY | 47:9e361da97763 | 107 | DUER_LOGI("IP address is: %s", ip ? ip : "No IP"); |
TMBOY | 47:9e361da97763 | 108 | DUER_LOGI("MAC address is: %s", mac ? mac : "No MAC"); |
TMBOY | 47:9e361da97763 | 109 | } else { |
TMBOY | 47:9e361da97763 | 110 | DUER_LOGE("Network initial failed...."); |
TMBOY | 47:9e361da97763 | 111 | Thread::wait(osWaitForever); |
TMBOY | 47:9e361da97763 | 112 | } |
TMBOY | 47:9e361da97763 | 113 | |
TMBOY | 47:9e361da97763 | 114 | duer::SocketAdapter::set_network_interface(&s_net_stack); |
TMBOY | 47:9e361da97763 | 115 | |
TMBOY | 47:9e361da97763 | 116 | duer::MediaManager::instance().set_volume(s_volume); |
TMBOY | 47:9e361da97763 | 117 | |
TMBOY | 47:9e361da97763 | 118 | duer::DuerApp app; |
TMBOY | 47:9e361da97763 | 119 | app.start(); |
TMBOY | 47:9e361da97763 | 120 | |
TMBOY | 47:9e361da97763 | 121 | duer::event_loop(); |
TMBOY | 47:9e361da97763 | 122 | } |