diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/README.md b/arc_design_contest/2018/NCKU_electronic_bookcases/README.md new file mode 100644 index 00000000..f8c74eec --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/README.md @@ -0,0 +1,141 @@ +arc-2018-Team4 electronic bookcases +================== + +* [Introduction](#overview) +* [Video](#video) +* [Configuration](#struct) + * [Hardware](#hardware) + * [Software](#software) + * [Makefile](#Makefile) +* [source code](#code) + +

Introduction

+ +The project name is “electronic bookcases”, which is designed to digitize the information inside the library. + +With the server that stores the data, administrators can easily manage and directly grasp the first-hand information at any time. + +As for clients, procedures such as borrowing or returning books will be facilitated. Clients will be able to handle several formalities by interacting with such system instead of librarian. The system will then collect related data so that administrators can do their work with comfort. + +Moreover, we hope to promote the system for in-depth analysis. Throughout further operation which provides convenient capability of management, administrators can be aware of popularity of certain books or have other thorough information in hand. + + +

Video

+https://v.youku.com/v_show/id_XMzY3OTI0MDg3Ng==.html?spm=a2h3j.8428770.3416059.1 + +

Configuration

+

Hardware

+ +* **DesignWare ARC EM Starter Kit(EMSK)** + +* **Linkit 7688 DUO** + +* **LCD** + +* **Keyboard** +* **A lot of LEDS (depend on how big your shelf is)** + +The version of EM Starter Kit is currently EMSK22 em7d. + +Linkit 7688 DUO is meant to build internet connection between client and server side. + +#### Hardware Connection +1. The linkit 7688 DUO is connected with ARC EMSK via uart on **J1** +2. Lcd is connected with ARC EMSK via I2C on **J4** +3. Keyboard is connected with ARC EMSK via gpio on **J3** +4. LEDS are connected with ARC EMSK via gpio on **J5 and J6** +5. Configure your EMSKs with proper core configuration. + +

Software

+ +* **Metaware or ARC GNU Toolset** +* **Arduino IDE (for linkit 7688 DUO mcu)** +* **Filezilla or other ftp software** +* **Serial port terminal, such as putty, tera-term or minicom (for linkit 7688 DUO mpu)** + +In this project, we use **embarc osp 2017.12** and **arc gnu tool chain 2017.09** + +#### Run This Application + +Modify the settings for connecting to the App, as shown below: + +Here take **EMSK2.2 - ARC EM7D** with GNU Toolset and **Linkit 7688 DUO** with Arduino IDE and filezilla for example to show how to run this application. + +1. We need to use embARC GNU Toolset to load application for EMSK and run. + +2. Set linkit to client mode and connect to wifi router. + +3. Open Arduino IDE to load application for linkit 7688 DUO MCU and run. + +4. Open putty and start a ssh connect with linkit MPU. + +5. Open Filezilla to upload application for linkit 7688 DUO MPU and use putty to run. +-Before running application on linkit 7688 DUO MPU , modify following code first: + + url="http://192.168.1.103//ARC2DB.php" + +**URL depends on where your mySQL server is.** + +
Get ipaddress
+ +- Take Windows as example: + + command line: ipconfig + +

Makefile

+ +- Target options about EMSK and toolchain: + + BOARD ?= emsk + BD_VER ?= 22 + CUR_CORE ?= arcem7d + TOOLCHAIN ?= gnu + +- The relative series of the root directory, depends on your structure. + + # + # root dir of embARC + # + EMBARC_ROOT = ../.. + +

source code

+ +* **src** + +| folder/file | Function | +| ------------------------ | -----------------------------------| +| src/arc | source code for EMBARC | +| src/linkit7688 | source code for linkit7688DUO | +| src/database | source code for database (mySQL) | + +* **src/arc/** + +| folder/file | Function | +| ------------------------ | -----------------------------------| +| team4/ | project's source code folder | +| team4/main.h & main.c | project's main function | +| team4/LCD.h & LCD.c | LCD drivers | +| team4/makefile | project's configuration | + +* **src/linkit7688** + +| folder/file | Function | +| -------------------------- | ----------------------------------------------------- | +| linkit-mpu/ | linkit 7688 DUO mpu source code folder | +| linkit-mpu/arc2018.py | deal with network in this project | +| linkit_mcu/ | linkit 7688 DUO arduino-compatible mcu source code folder| +| linkit_mcu/linkit_mcu.ino | bridge between **arc emsk** and **linkit MPU** | + +* **src/database/Library** + +| folder/file | Function | +| -------------------------------- | -------------------------------------------| +| ARC2DB.php | project source code for database operation | +| ARC-Hive Library Information.php| display all information | +| Book.php | display books' status | +| connect database.php | project source code for database connection| +| Location.php | display available location | +| ReservationRecoed.php | display reservation history of each books | +| WaitingQueue.php | display current reservation status | + + diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/doc/Team4doc.rar b/arc_design_contest/2018/NCKU_electronic_bookcases/doc/Team4doc.rar new file mode 100644 index 00000000..dcc5af63 Binary files /dev/null and b/arc_design_contest/2018/NCKU_electronic_bookcases/doc/Team4doc.rar differ diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.c b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.c new file mode 100644 index 00000000..c61f4413 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.c @@ -0,0 +1,122 @@ +#include "LCD.h" + +static DEV_IIC *LCD; +/***************************************************************************** + Lcd_Init - setup spi port for LCD driver + *****************************************************************************/ +void Lcd_Init(DEV_IIC *LCD_obj) { + LCD = LCD_obj; +} + +/***************************************************************************** + Lcd_ClearScreen - CLear screen + *****************************************************************************/ +void Lcd_ClearScreen(void) { + uint8_t iic_cmd[4] = { 0x1B, '[', '0', 'j' }; + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 4); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} + +/***************************************************************************** + Lcd_Home - set cursor at home position + *****************************************************************************/ +void Lcd_Home(void) { + uint8_t iic_cmd[6] = { 0x1B, '[', '0', ';', '0', 'H' }; + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 6); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} + +/***************************************************************************** + Lcd_Cursor - set cursor at postion row:col + *****************************************************************************/ +void Lcd_Cursor(uint8_t row, uint8_t col) { + unsigned char col_first_digit = col / 10 + '0'; + unsigned char col_second_digit = col % 10 + '0'; + uint8_t iic_cmd[MAX_LCD_COL + 7] = { 0x1B, '[', row + '0', ';', + col_first_digit, col_second_digit, 'H' }; + + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 7); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} + +/***************************************************************************** + Lcd_CursorOff - swtch cursor off + *****************************************************************************/ +void Lcd_CursorOff(void) { + uint8_t iic_cmd[4] = { 0x1B, '[', '0', 'c' }; + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 4); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} +/***************************************************************************** + Lcd_ClearRow - clear selected row + *****************************************************************************/ +void Lcd_ClearRow(uint8_t row) { + // set cursor to start position of the line + Lcd_Cursor(row, 0); + //erase from current pos to end of line + uint8_t iic_cmd[4] = { 0x1B, '[', '0', 'K' }; + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 4); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} + +/***************************************************************************** + Lcd_DisplayMode - Set 16-byte of 40 bytes stings length + *****************************************************************************/ +void Lcd_DisplayMode(int onoff) { + uint8_t iic_cmd[4] = { 0x1B, '[', '0', 'h' }; + + if (onoff == 1) { + iic_cmd[2] = '0'; //wrap @ 16 chars + } else { + iic_cmd[2] = '1'; //wrap @ 40 chars + } + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 4); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} + +/***************************************************************************** + Lcd_DisplayOnOff - On/Off display + *****************************************************************************/ +void Lcd_DisplayOnOff(int onoff) { + uint8_t iic_cmd[4] = { 0x1B, '[', '3', 'e' }; + + if (onoff == 1) { + iic_cmd[2] = '1'; //on + } else { + iic_cmd[2] = '0'; //off + } + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, 4); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} +void Lcd_DisplayString(uint8_t row, uint8_t col, char *strng) { + unsigned int length = 0; + unsigned char byte; + unsigned int i; + uint8_t *bufptr; + uint8_t iic_cmd[MAX_LCD_COL]; + + Lcd_ClearRow(row); + Lcd_Cursor(row, col); + + bufptr = iic_cmd; + for (i = length = 0; i < MAX_LCD_COL; i++) { + byte = *strng++; + if (byte) { + if (byte != '\r' && byte != '\n') { + *bufptr++ = byte; + length++; + } + } else + break; + } + LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_RESTART)); + LCD->iic_write(iic_cmd, length); + //LCD->iic_control(IIC_CMD_MST_SET_NEXT_COND, CONV2VOID(IIC_MODE_STOP)); +} diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.h b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.h new file mode 100644 index 00000000..fc8af812 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/LCD.h @@ -0,0 +1,14 @@ +#include "embARC.h" +#include "embARC_debug.h" +/***************************FOR PMOD CLS LCD*************************************/ +#define MAX_LCD_COL 16 +/***************************Fun Declaration******************************/ +void Lcd_Init (DEV_IIC *LCD_obj); +void Lcd_ClearScreen (void); +void Lcd_Home (void); +void Lcd_Cursor (uint8_t row, uint8_t col); +void Lcd_CursorOff (void); +void Lcd_ClearRow (uint8_t row); +void Lcd_DisplayMode (int onoff); +void Lcd_DisplayOnOff (int onoff); +void Lcd_DisplayString(uint8_t row, uint8_t col, char *strng); diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.c b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.c new file mode 100644 index 00000000..07af10d0 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.c @@ -0,0 +1,447 @@ +#include "main.h" + +static DEV_UART *Console; +static DEV_UART *linkit; +static DEV_GPIO *led; +static DEV_IIC *LCD; + +static button_status keyboard_table[4][4] = { 0 }; +static DEV_GPIO * keyboard_row; +static DEV_GPIO * keyboard_col; +static DEV_GPIO * port_C_led; +static DEV_GPIO * port_A_led; +static char *msg; + +/** main entry */ +int main(void) { + //set up device + device_setup(); + board_delay_ms(2000, 1); + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "A(Search)"); + Lcd_DisplayString(1, 0, "B(Borrow)"); + board_delay_ms(2000, 1); + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "C(Return)"); + Lcd_DisplayString(1, 0, "D(Reservation)"); + + while (1) { + board_delay_ms(2000, 1); + Lcd_ClearScreen(); + port_C_led->gpio_write(0x0, J5_PIN1to4_MASK_C); + port_A_led->gpio_write(0x0, J56_MASK_A); + Lcd_DisplayString(0, 0, "Select Function\r\n"); + Lcd_DisplayString(1, 0, "A,B,C,D *:help"); + + /*we will use the string below later*/ + char cmd[CMD_Length] = { 0 }; + for (int base = 0; base < CMD_Length; base++) { + cmd[base] = ' '; + } //Your ID:________ + cmd[CMD_Length - 1] = 'Z'; + + char book[16] = "BOOK ID:"; + for (int base = 0; base < Book_ID_Length; base++) { + book[8 + base] = '_'; + } //BOOK ID:________ + + char user[16] = "Your ID:"; + for (int base = 0; base < User_ID_Length; base++) { + user[8 + base] = '_'; + } //Your ID:________ + + char location[16] = "Location:"; + for (int base = 0; base < location_length; base++) { + location[9 + base] = '_'; + } //Location:________ + + /*GET WHAT USER WANT TO DO*/ + int function = btn(); + switch (function) { + case Search: { + Lcd_DisplayString(0, 0, "Search \n\r"); + Lcd_DisplayString(1, 0, book); + + /*Enter Book ID*/ + for (int count = 0; count < Book_ID_Length; count++) { + int input = btn(); + cmd[count + 1] = keyboard_Convert[input]; + book[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(1, 0, book); + } + sendcmd(cmd, function); + /*get response*/ + rev(function); + break; + } + case Borrow: { + Lcd_DisplayString(0, 0, "Borrow \n\r"); + Lcd_DisplayString(1, 0, book); + /*Enter Book ID*/ + for (int count = 0; count < Book_ID_Length; count++) { + int input = btn(); + cmd[count + 1] = keyboard_Convert[input]; + book[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(1, 0, book); + } + + /*Enter User ID*/ + Lcd_DisplayString(0, 0, user); + for (int count = 0; count < User_ID_Length; count++) { + int input = btn(); + cmd[count + Book_ID_Length + 1] = keyboard_Convert[input]; + user[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(0, 0, user); + } + sendcmd(cmd, function); + /*get response*/ + rev(function); + break; + } + case Giveback: { + Lcd_DisplayString(0, 0, "Giveback \n\r"); + Lcd_DisplayString(1, 0, book); + /*Enter Book ID*/ + for (int count = 0; count < Book_ID_Length; count++) { + int input = btn(); + cmd[count + 1] = keyboard_Convert[input]; + book[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(1, 0, book); + } + /*Enter Location*/ + Lcd_DisplayString(0, 0, location); + for (int count = 0; count < location_length; count++) { + if (count == 1) { + cmd[count + Book_ID_Length + 1] = '-'; + location[10] = '-'; + Lcd_DisplayString(0, 0, location); + } else { + int input = btn(); + if (count == 0) { + location[9] = keyboard_Convert[input]; + } else { + location[11] = keyboard_Convert[input]; + } + cmd[count + Book_ID_Length + 1] = keyboard_Convert[input]; + Lcd_DisplayString(0, 0, location); + } + } + sendcmd(cmd, function); + /*get response*/ + rev(function); + break; + } + case help: { + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "A(Search)"); + Lcd_DisplayString(1, 0, "B(Borrow)"); + board_delay_ms(2000, 1); + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "C(Return)"); + Lcd_DisplayString(1, 0, "D(Reservation)"); + break; + } + case Reservation: { + Lcd_DisplayString(0, 0, "A:New"); + Lcd_DisplayString(1, 0, "B:Cancel"); + do { + int res_function = btn(); + if (res_function == New_Reservation) { + function = NewReservation; + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "A:New"); + msg = "New_Reservation \n\r"; + Console->uart_write(msg, strlen(msg)); + break; + } else if (res_function == Cancel_Reservation) { + function = CancelReservation; + Lcd_ClearScreen(); + Lcd_DisplayString(0, 0, "B:Cancel"); + msg = "Cancel_Reservation \n\r"; + Console->uart_write(msg, strlen(msg)); + break; + } else { + Lcd_DisplayString(0, 0, "A:New"); + Lcd_DisplayString(1, 0, "B:Cancel"); + } + } while (true); + Lcd_DisplayString(1, 0, book); + /*Enter Book ID*/ + for (int count = 0; count < Book_ID_Length; count++) { + int input = btn(); + cmd[count + 1] = keyboard_Convert[input]; + book[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(1, 0, book); + } + + /*Enter User ID*/ + Lcd_DisplayString(0, 0, user); + for (int count = 0; count < User_ID_Length; count++) { + int input = btn(); + cmd[count + Book_ID_Length + 1] = keyboard_Convert[input]; + user[8 + count] = keyboard_Convert[input]; + Lcd_DisplayString(0, 0, user); + } + + sendcmd(cmd, function); + /*get response*/ + rev(function); + break; + } + default: + break; + } + } +} +int btn(void) { + uint32_t data; + uint32_t buffer; + int i, j; + while (1) { + for (i = 0; i < 4; i++) { + //scan 4 rows + keyboard_row->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, + (void *) (0x10000 << i)); + keyboard_row->gpio_write(0x00000000, J3_PIN1to4_MASK_C); + board_delay_ms(1, 1); + keyboard_col->gpio_read(&data, J3_PIN7to10_MASK_A); + + for (j = 0; j < 4; j++) { + //scan 4 columns + if (data & (0x10000 << j)) { + if (keyboard_table[i][j].ispress == true) { + keyboard_table[i][j].release_time = board_get_cur_us(); + keyboard_table[i][j].ispress = debounce_start_off; + } else if (keyboard_table[i][j].ispress == debounce_start_on) { + keyboard_table[i][j].ispress = false; + } else if (keyboard_table[i][j].ispress + == debounce_start_off) { + if (board_get_cur_us() + - keyboard_table[i][j].release_time + >= 100000ul) { + keyboard_table[i][j].ispress = false; + } + } else { + keyboard_table[i][j].ispress = false; + } + } else { + if (keyboard_table[i][j].ispress == false) { + keyboard_table[i][j].press_time = board_get_cur_us(); + keyboard_table[i][j].ispress = debounce_start_on; + } else if (keyboard_table[i][j].ispress == debounce_start_on) { + if (board_get_cur_us() - keyboard_table[i][j].press_time + >= 10000ul) { + keyboard_table[i][j].ispress = true; + //printf("PRESS %c\n", keyboard_Convert[i * 4 + j]); + return (i * 4 + j); + } + } else if (keyboard_table[i][j].ispress + == debounce_start_off) { + keyboard_table[i][j].ispress = true; + } else { + keyboard_table[i][j].ispress = true; + } + } + } + keyboard_row->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, + (void *) (J3_PIN1to4_MASK_C)); + } + } +} +void device_setup(void) { + board_init(); + mux_setup(); + /*get device*/ + linkit = uart_get_dev(LINKIT_UART_ID); //get linkit pointer + Console = uart_get_dev(PC_UART_ID); //get console pointer + led = gpio_get_dev(EMSK_GPIO_PORT_B_ID); //get on-board led pointer + LCD = iic_get_dev(LCD_IIC_PORT_PM4); + keyboard_row = gpio_get_dev(keyboard_row_ID); //get keyboard_row pointer + keyboard_col = gpio_get_dev(keyboard_col_ID); //get keyboard_col pointer + port_C_led = keyboard_row; + port_A_led = keyboard_col; + + /*LCD setup*/ + LCD->iic_open(DEV_MASTER_MODE, IIC_SPEED_HIGH); + LCD->iic_control(IIC_CMD_MST_SET_TAR_ADDR, CONV2VOID(LCD_Slave_Address)); + Lcd_Init(LCD); + Lcd_DisplayOnOff(1); //display on + Lcd_DisplayMode(1); //wrap 16 chars + Lcd_ClearScreen(); //clear screen + Lcd_CursorOff(); + Lcd_DisplayString(0, 0, "Initialize..."); + Lcd_DisplayString(1, 0, "Hello My Friend"); + //open Console Device + led->gpio_open(0x1FF); + Console->uart_open(UART_BAUDRATE_115200); + linkit->uart_open(UART_BAUDRATE_9600); + led->gpio_write(0x055, 0x1FF); + + /*set up for 4*4 keyboard*/ + keyboard_row->gpio_close(); /* opened before now close it */ + keyboard_col->gpio_close(); /* opened before now close it */ + keyboard_row->gpio_open(J3_PIN1to4_MASK_C | J5_PIN1to4_MASK_C); + keyboard_col->gpio_open(J3_PIN7to10_MASK_A | J56_MASK_A); + keyboard_row->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, + (void *) (J3_PIN1to4_MASK_C)); + keyboard_col->gpio_control(GPIO_CMD_SET_BIT_DIR_INPUT, + (void *) (J3_PIN7to10_MASK_A)); + keyboard_row->gpio_write(0x00000, J3_PIN1to4_MASK_C); + + /*LED SETUP*/ + //port_C_led->gpio_open(J5_PIN1to4_MASK_C); + //port_A_led->gpio_open(J56_MASK_A); + port_C_led->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, + (void *) (J5_PIN1to4_MASK_C)); + port_A_led->gpio_control(GPIO_CMD_SET_BIT_DIR_OUTPUT, + (void *) (J56_MASK_A)); + board_delay_ms(1, 1); +} +void mux_setup(void) { + set_pmod_mux( PM1_UR_UART_0 | //PM1 for linkit7688DUO + PM3_GPIO_AC | //PM3 for LCD + PM4_I2C_GPIO_D | //PM4 for keyboard + PM5_UR_GPIO_C | //PM5 for LEDS + PM5_LR_GPIO_A | //PM5 for LEDS + PM6_LR_GPIO_A); //PM6 for LEDS + + set_uart_map(0x9c);//old version board +} +void sendcmd(char cmd[], int function) { + cmd[0] = keyboard_Convert[function]; + Console->uart_write("\r\n", 2); + Console->uart_write(cmd, CMD_Length); + /*send data to linkit 7688 MPU*/ + linkit->uart_write(cmd, CMD_Length); +} +void rev(int operation) { + uint64_t start_us; + start_us = board_get_cur_us(); + char rev[16] = { 0 }; + int count = 0; + while (board_get_cur_us() - start_us < (uint64_t) 10000000) { //give 10 seconds for response + int available; + linkit->uart_control(UART_CMD_GET_RXAVAIL, &available); + if (available >= 4) { + board_delay_ms(10, 1); + linkit->uart_read(&rev[count], available); + count += available; + if (rev[0] == 'M') { // Error Message is started with character 'M' + sprintf(msg, "Error number:%c\n\r", rev[1]); + Lcd_DisplayString(0, 0, msg); + linkit->uart_control(UART_CMD_GET_RXAVAIL, &available); + while (available != 0) {/*flush input buffer*/ + linkit->uart_read(rev, 1); + linkit->uart_control(UART_CMD_GET_RXAVAIL, &available); + } + break; + } else { + int tem = 0; + char strng[16] = { 0 }; + /*get string*/ + while (tem < 10) { + if (rev[tem] == 'Z') + break; + strng[tem] = rev[tem]; + tem++; + } + + board_delay_ms(1, 1); + /*classify response*/ + if (rev[0] == 'E') { + switch (operation) { + case Search: { + switch (rev[2]) { + case '0': { + Lcd_DisplayString(0, 0, "No Such ID"); + break; + } + case '1': { + Lcd_DisplayString(0, 0, "Not in shelf"); + break; + } + } + break; + } + case Borrow: { + switch (rev[2]) { + case '0': { + Lcd_DisplayString(0, 0, "No Such ID"); + break; + } + case '1': { + Lcd_DisplayString(0, 0, "Borrowed"); + break; + } + case '2': { + Lcd_DisplayString(0, 0, "Already Reserved"); + break; + } + } + break; + } + case Giveback: { + switch (rev[2]) { + case '0': { + Lcd_DisplayString(0, 0, "No Such ID"); + break; + } + case '1': { + Lcd_DisplayString(0, 0, "Already returned"); + break; + } + case '2': { + Lcd_DisplayString(0, 0, "No such location"); + break; + } + } + break; + } + case NewReservation: { + switch (rev[2]) { + case '0': { + Lcd_DisplayString(0, 0, "No Matched Data"); + break; + } + } + break; + } + case CancelReservation: { + switch (rev[2]) { + case '0': { + Lcd_DisplayString(0, 0, "No Matched Data"); + break; + } + } + break; + } + } + } else if (rev[0] == 'O') { + Lcd_DisplayString(0, 0, "Success!!"); + } else { + if (operation == Search) { + + int locate = rev[2] - '1'; + if (rev[0] == '1') { + port_A_led->gpio_write(0x1000000 << locate, + J56_MASK_A); + } else { + port_C_led->gpio_write(0x1000000 << locate, + J5_PIN1to4_MASK_C); + ; + } + } + Lcd_DisplayString(0, 0, strng); + } + + /*flush input buffer*/ + linkit->uart_control(UART_CMD_GET_RXAVAIL, &available); + while (available != 0) { + linkit->uart_read(rev, 1); + linkit->uart_control(UART_CMD_GET_RXAVAIL, &available); + } + break; + } + } + } +} diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.h b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.h new file mode 100644 index 00000000..cc2a42ad --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/main.h @@ -0,0 +1,67 @@ +/***************************GPIO Libraries*******************************/ +#include "embARC.h" +#include "embARC_debug.h" +#include +#include +#include +#include "LCD.h" + +/***************************FOR Console UART1****************************/ +#define PC_UART_ID DW_UART_1_ID //Console ID +/***************************FOR Pmod1 Linkit 7688 DUO UART0**************/ +#define LINKIT_UART_ID DW_UART_0_ID //Linkit 7688 DUO ID +/***************************FOR GPIO*************************************/ +#define EMSK_GPIO_PORT_B_ID DW_GPIO_PORT_B //GPIO-B ID +#define BOARD_LED_MASK (0x1ff) +/***************************FOR LCD*************************************/ +#define LCD_IIC_PORT_PM4 DW_IIC_1_ID +#define LCD_Slave_Address 0x48 +#define MAX_LCD_COL 16 +/***************************For mux**************************************/ +#include "../../board/emsk/drivers/mux/mux.h" +/***************************FOR Pmod3 4*4 keyboard***********************/ +#define J3_PIN7to10_MASK_A 0xf0000 +#define J3_PIN1to4_MASK_C 0xf0000 +#define J56_MASK_A 0x1f000000 +#define J5_PIN1to4_MASK_C 0xf000000 +#define keyboard_row_ID DW_GPIO_PORT_C //keyboard_row_ID +#define keyboard_col_ID DW_GPIO_PORT_A //keyboard_col_ID +/***************************FOR Debounce*********************************/ +#define false 0 +#define true 1 +#define debounce_start_on 2 +#define debounce_start_off 3 +typedef struct _button_status{ + int ispress; + uint64_t press_time; + uint64_t release_time; +} button_status; +const static char keyboard_Convert[] = { + '1', '2', '3', 'A', + '4', '5', '6', 'B', + '7', '8', '9', 'C', + '*', '0', '#', 'D', + 'E','F' +}; +/***************************User Function********************************/ +#define Book_ID_Length 2 +#define location_length 3 +#define Func_ID_Length 2 +#define User_ID_Length 5 +#define CMD_Length 9//(FUNC)+(BOOKID)+(USERID)+Z +#define Search 3 //A +#define Borrow 7 //B +#define Giveback 11 //C +#define help 12 +#define Reservation 15 //D +#define NewReservation 16 +#define CancelReservation 17 +#define New_Reservation 3 //A +#define Cancel_Reservation 7 //B + +/***************************Fun Declaration******************************/ +int btn(void); +void device_setup(void); +void mux_setup(void); +void sendcmd(char cmd[], int function); +void rev(int operation); diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/makefile b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/makefile new file mode 100644 index 00000000..a6c00c0c --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/arc/team4/makefile @@ -0,0 +1,54 @@ +## embARC application makefile template ## +### You can copy this file to your application folder +### and rename it to makefile. +## + +# Application name +APPL ?= ARC-TEAM4 + +# Optimization Level +# Please Refer to toolchain_xxx.mk for this option +OLEVEL ?= O2 + +## +# Current Board And Core +## +BOARD ?= emsk +BD_VER ?= 22 +CUR_CORE ?= arcem7d + +## +# select debugging jtag +## +JTAG ?= usb + +## +# Set toolchain +## +TOOLCHAIN ?= gnu + +# +# root dir of embARC +# +EMBARC_ROOT = ./../.. + +MID_SEL = + +# application defines +APPL_DEFINES = + + +# application source dirs +APPL_CSRC_DIR = . +APPL_ASMSRC_DIR = . + +# application include dirs +APPL_INC_DIR = . + +# include current project makefile +COMMON_COMPILE_PREREQUISITES += makefile + +### Options above must be added before include options.mk ### +# include key embARC build system makefile +override EMBARC_ROOT := $(strip $(subst \,/,$(EMBARC_ROOT))) +include $(EMBARC_ROOT)/options/options.mk \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC-Hive-Library-Information.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC-Hive-Library-Information.php new file mode 100644 index 00000000..05c66312 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC-Hive-Library-Information.php @@ -0,0 +1,65 @@ + + +Library information + + + + + + + + + + $Table"; + echo ""; + echo ""; + while ($info= mysqli_fetch_field($sqldata)) { + echo " "; + } + echo ""; + + ///* + while ($row=mysqli_fetch_array($sqldata)) { + echo ""; + for ($i=0; $i >1 ; $i++) { + echo ""; + } + echo ""; + } + echo "
".$info->name."
".$row[$i]."
"; + echo ""; + + } + + + Display("Book"); + Display("Location"); + Display("WaitingQueue"); + Display("ReservationRecord"); + + + + ?> + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC2DB.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC2DB.php new file mode 100644 index 00000000..a159ee86 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ARC2DB.php @@ -0,0 +1,390 @@ +'$StartIndex' "; + mysqli_query($GLOBALS['dbcon'],$query); + + + $query="SELECT max(priority) AS priority FROM WaitingQueue"; + $sqldata=mysqli_fetch_assoc(mysqli_query($GLOBALS['dbcon'],$query)); + $EndPriority=$sqldata['priority']; + + $query="UPDATE WaitingQueue SET `Book$ID` =NULL WHERE priority ='$EndPriority'"; + mysqli_query($GLOBALS['dbcon'],$query); + + $query="SELECT * FROM WaitingQueue WHERE priority='$EndPriority'"; + $sqldata=mysqli_fetch_array(mysqli_query($GLOBALS['dbcon'],$query)); + + + #delete empty rows in DB + $deleteRow=TRUE; + for ($i=1; $i >1 ; $i++) { + if($sqldata[$i]!=NULL){ + $deleteRow=FALSE; + break; + } + } + + if($deleteRow){ + $query="DELETE FROM WaitingQueue WHERE priority='$EndPriority'"; + mysqli_query($GLOBALS['dbcon'],$query); + } + + $query="ALTER TABLE WaitingQueue AUTO_INCREMENT = 1"; + mysqli_query($GLOBALS['dbcon'],$query); + unset($_SESSION['ID']); + unset($_SESSION['User']); + } +} + + +Search(); +Borrow(); +PopWaitingQueue(); +NewReservation(); +GiveBack(); + +/* +fclose($myfile); +fclose($current); +//*/ + +?> \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Book.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Book.php new file mode 100644 index 00000000..7a50e2c7 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Book.php @@ -0,0 +1,60 @@ + + +Library information + + + + + + + + + + $Table"; + echo ""; + echo ""; + while ($info= mysqli_fetch_field($sqldata)) { + echo " "; + } + echo ""; + + ///* + while ($row=mysqli_fetch_array($sqldata)) { + echo ""; + for ($i=0; $i >1 ; $i++) { + echo ""; + } + echo ""; + } + echo "
".$info->name."
".$row[$i]."
"; + echo ""; + } + + + Display("Book"); + + + ?> + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Location.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Location.php new file mode 100644 index 00000000..1d78c214 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/Location.php @@ -0,0 +1,61 @@ + + +Library information + + + + + + + + + + $Table"; + echo ""; + echo ""; + while ($info= mysqli_fetch_field($sqldata)) { + echo " "; + } + echo ""; + + ///* + while ($row=mysqli_fetch_array($sqldata)) { + echo ""; + for ($i=0; $i >1 ; $i++) { + echo ""; + } + echo ""; + } + echo "
".$info->name."
".$row[$i]."
"; + echo ""; + } + + + + Display("Location"); + + + ?> + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ReservationRecord.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ReservationRecord.php new file mode 100644 index 00000000..7a8f771c --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/ReservationRecord.php @@ -0,0 +1,60 @@ + + +Library information + + + + + + + + + + $Table"; + echo ""; + echo ""; + while ($info= mysqli_fetch_field($sqldata)) { + echo " "; + } + echo ""; + + ///* + while ($row=mysqli_fetch_array($sqldata)) { + echo ""; + for ($i=0; $i >1 ; $i++) { + echo ""; + } + echo ""; + } + echo "
".$info->name."
".$row[$i]."
"; + echo ""; + } + + + + Display("ReservationRecord"); + + ?> + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/WaitingQueue.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/WaitingQueue.php new file mode 100644 index 00000000..8946f6a4 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/WaitingQueue.php @@ -0,0 +1,61 @@ + + +Library information + + + + + + + + + + $Table"; + echo ""; + echo ""; + while ($info= mysqli_fetch_field($sqldata)) { + echo " "; + } + echo ""; + + ///* + while ($row=mysqli_fetch_array($sqldata)) { + echo ""; + for ($i=0; $i >1 ; $i++) { + echo ""; + } + echo ""; + } + echo "
".$info->name."
".$row[$i]."
"; + echo ""; + } + + + + Display("WaitingQueue"); + + + ?> + + \ No newline at end of file diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/connect database.php b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/connect database.php new file mode 100644 index 00000000..84ab7e82 --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/database/Library/connect database.php @@ -0,0 +1,13 @@ + + diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit-mpu/arc2018.py b/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit-mpu/arc2018.py new file mode 100644 index 00000000..a02f28ef --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit-mpu/arc2018.py @@ -0,0 +1,86 @@ +import requests +import serial +import time + +book_ID_length = 2 +command_ext_length = 2 +user_ID_length = 5 +command_total_length = 9 + +url="http://192.168.1.102/ARC2DB.php" +s = None +def setup(): + global s + # open serial COM port to /dev/ttyS0, which maps to UART0(D0/D1) + # the baudrate is set to 57600 and should be the same as the one + # specified in the Arduino sketch uploaded to ATmega32U4. + s = serial.Serial("/dev/ttyS0", 57600) + +def loop(): + if s.inWaiting() >= book_ID_length+command_ext_length: + a=s.read(s.inWaiting()) + if a[command_total_length-1] == 'Z' : ##end of cmd + if a[0] == 'A': + s.flushInput() + mydata={"SearchID":a[1:1+book_ID_length]} + response=requests.post(url,data=mydata) + response.raise_for_status() + print(response.text[1:]) + if "error mysql connect" in response.text: + s.write("E-2Z") + else: + temp = response.text[1:] + s.write(temp.encode()+"Z") + elif a[0] == 'B': + s.flushInput() + mydata={"BorrowID":a[1:1+book_ID_length],"NewOwner":a[1+book_ID_length:1+book_ID_length+user_ID_length]} + response=requests.post(url,data=mydata) + response.raise_for_status() + print(response.text[1:]) + if "error mysql connect" in response.text: + s.write("E-2Z") + else: + temp = response.text[1:] + s.write(temp.encode()+"Z") + elif a[0] == 'C': + s.flushInput() + mydata={"ReturnID":a[1:1+book_ID_length],"ReturnLocation":a[1+book_ID_length:1+book_ID_length+3]} + response=requests.post(url,data=mydata) + response.raise_for_status() + print(response.text[1:]) + if "error mysql connect" in response.text: + s.write("E-2Z") + else: + temp = response.text[1:] + s.write(temp.encode()+"Z") + elif a[0] == 'D': + s.flushInput() + mydata={"ReserveID":a[1:1+book_ID_length],"Reservation":a[1+book_ID_length:1+book_ID_length+user_ID_length]} + response=requests.post(url,data=mydata) + response.raise_for_status() + print(response.text[1:]) + if "error mysql connect" in response.text: + s.write("E-2Z") + else: + temp = response.text[1:] + s.write(temp.encode()+"Z") + elif a[0] == 'E': + s.flushInput() + mydata={"CancelID":a[1:1+book_ID_length],"CancelReservation":a[1+book_ID_length:1+book_ID_length+user_ID_length]} + response=requests.post(url,data=mydata) + response.raise_for_status() + print(response.text[1:]) + if "error mysql connect" in response.text: + s.write("E-2Z") + else: + temp = response.text[1:] + s.write(temp.encode()+"Z") + else: + s.write("0") + else: + s.write("0") + +if __name__=='__main__': + setup() + while True: + loop() diff --git a/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit_mcu/linkit_mcu.ino b/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit_mcu/linkit_mcu.ino new file mode 100644 index 00000000..f272604c --- /dev/null +++ b/arc_design_contest/2018/NCKU_electronic_bookcases/src/linkit7688/linkit_mcu/linkit_mcu.ino @@ -0,0 +1,116 @@ +#include +#define book_ID_length 2 +#define extension_bit 2 +#define User_ID_length 5 +#define command_length 9 +#define end_of_cmd_index command_length - 1 + +/*define function code*/ +#define Search 'A' +#define Borrow 'B' +#define GiveBack 'C' +#define New_Reservation 'D' +#define Cancel_Reservation 'E' + +/*define error message*/ +#define E_ARC_OK "M11Z" /*!< ok */ +#define E_ARC_Trans "M22Z" /*!< invalid cmd */ +#define E_MPU_OK "M33Z" /*!< ok */ +#define E_MPU_Trans "M44Z" /*!< invalid cmd */ +#define E_MPU_NoRes "M55Z" + +int LED = 13; +const byte rxPin = 10; +const byte txPin = 11; + +// set up a new serial object ->communivate with arc_emsk +SoftwareSerial mySerial(rxPin, txPin); + +void setup() +{ + + Serial.begin(9600); /*PC baudrate*/ + Serial1.begin(57600); /*linkit 7688 duo mpu baud rate*/ + pinMode(rxPin, INPUT); + pinMode(txPin, OUTPUT); + mySerial.begin(9600); /*arc baud rate*/ + pinMode(LED, OUTPUT); + //mySerial.listen(); +} +void loop() +{ + if (mySerial.available() == command_length) + { + /*Read Data from ARC EMSK*/ + int strlength = mySerial.available(); + Serial.println(strlength); + char uart_text[command_length] = {0}; + for (int i = 0; i < command_length; i++) + { + uart_text[i] = ' '; + } + for (int index = 0; index < command_length; index++) + { + uart_text[index] = mySerial.read(); + } + /*Verify the gotten*/ + if (uart_text[end_of_cmd_index] == 'Z') + { + switch (uart_text[0]) + { + case Search: + case GiveBack: + case Borrow: + case New_Reservation: + case Cancel_Reservation: + { + Serial.print(uart_text); + /*send data to linkit 7688 MPU*/ + Serial1.write(uart_text, command_length); + /*Wait and GET RESPONSE FORM LINKIT 7688 MPU*/ + char rev[6] = {0}; + int count = 0; + unsigned long current_time = millis(); + while (millis() - current_time < 5000) + { + if (Serial1.available()) + { + delay(10); + /*Z is end of data from mySQL*/ + rev[count] = Serial1.read(); + if (rev[0] == '0')//mySQL server no response + { + count = -1; //indicate end of transmissting + Serial.println(rev); + delay(10); + mySerial.write(E_MPU_Trans); + break; + } + if (rev[count] == 'Z') + { + Serial1.flush(); + count = -1; //indicateend of transmissting + delay(10); + mySerial.write(rev); + Serial.println(rev); + break; + } + count++; + } + } + if (count != -1) + { + delay(10); + mySerial.write(E_MPU_NoRes); + } + break; + } + } + } + else + { + mySerial.write(E_ARC_Trans); + mySerial.flush(); + } + } +}