Interface layer for the mbed boards ready for the JAVA library
Dependencies: C12832 LM75B MMA7660 mbed FXOS8700Q
Fork of frdm_serial by
Revision 8:d70e3e3690fd, committed 2017-01-06
- Comitter:
- Condo2k4
- Date:
- Fri Jan 06 11:08:56 2017 +0000
- Parent:
- 7:238c6fd5c209
- Commit message:
- Extended LCD functionality.; Temporarily disable LEDs
Changed in this revision
diff -r 238c6fd5c209 -r d70e3e3690fd FXOS8700Q.lib --- a/FXOS8700Q.lib Tue Feb 16 23:07:10 2016 +0000 +++ b/FXOS8700Q.lib Fri Jan 06 11:08:56 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/JimCarver/code/FXOS8700Q/#5553a64d0762 +http://developer.mbed.org/teams/NXP/code/FXOS8700Q/#aee7dea904e2
diff -r 238c6fd5c209 -r d70e3e3690fd main.cpp --- a/main.cpp Tue Feb 16 23:07:10 2016 +0000 +++ b/main.cpp Fri Jan 06 11:08:56 2017 +0000 @@ -17,8 +17,13 @@ LM75B temp(D14, D15); MMA7660 sAcc(D14, D15); -FXOS8700Q_acc bAcc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board -FXOS8700Q_mag bMag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board +I2C i2c(PTE25, PTE24); +//FXOS8700Q fxos(i2c, FXOS8700CQ_SLAVE_ADDR1); +FXOS8700QAccelerometer bAcc(i2c, FXOS8700CQ_SLAVE_ADDR1); // Configured for the FRDM-K64F with onboard sensors +FXOS8700QMagnetometer bMag(i2c, FXOS8700CQ_SLAVE_ADDR1); + +//FXOS8700Q_acc bAcc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board +//FXOS8700Q_mag bMag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // Proper Ports and I2C Address for K64F Freedom board InterruptIn sw2_int(SW2), sw3_int(SW3), up_int(A2), down_int(A3), left_int(A4), right_int(A5), fire_int(D4); DigitalIn sw2(SW2), sw3(SW3), up(A2), down(A3), left(A4), right(A5), fire(D4); @@ -159,7 +164,7 @@ } void get_heading() { - MotionSensorDataUnits mag; + motion_data_units_t mag; bMag.getAxis(mag); float heading = atan2(-(mag.x-20.0f),mag.y-5.0f)*180.0f/M_PI; if(heading<0) heading+=360.0f; @@ -174,8 +179,15 @@ lr = r; lg = g; lb = b; } +void set_piezo() { // set piezo buzzer + float vol = pc.readFloat(); + float period = 1.0f/pc.readFloat(); + spkr=vol*0.5f; //convert volume to duty cycle + spkr.period(period); +} + void read_board_magno() { //read board magno - MotionSensorDataUnits mag; + motion_data_units_t mag; bMag.getAxis(mag); pc.sendFloat(mag.x); pc.sendFloat(mag.y); @@ -183,10 +195,11 @@ } void read_board_accel() { //read board accel - float f; - bAcc.getX(&f); pc.sendFloat(f); - bAcc.getY(&f); pc.sendFloat(f); - bAcc.getZ(&f); pc.sendFloat(f); + motion_data_units_t acc; + bAcc.getAxis(acc); + pc.sendFloat(acc.x); + pc.sendFloat(acc.y); + pc.sendFloat(acc.z); } void set_lcd_position() { //set lcd position @@ -211,11 +224,39 @@ lcd.copy_to_lcd(); } -void set_piezo() { // set piezo buzzer - float vol = pc.readFloat(); - float period = 1.0f/pc.readFloat(); - spkr=vol*0.5f; //convert volume to duty cycle - spkr.period(period); +void draw_circle() { + char xyrc[4]; + pc.readData(xyrc, 4); + lcd.circle(xyrc[0],xyrc[1],xyrc[2],xyrc[3]); + lcd.copy_to_lcd(); +} + +void fill_circle() { + char xyrc[4]; + pc.readData(xyrc, 4); + lcd.fillcircle(xyrc[0],xyrc[1],xyrc[2],xyrc[3]); + lcd.copy_to_lcd(); +} + +void draw_line() { + char xyxyc[5]; + pc.readData(xyxyc, 5); + lcd.line(xyxyc[0],xyxyc[1],xyxyc[2],xyxyc[3],xyxyc[4]); + lcd.copy_to_lcd(); +} + +void draw_rect() { + char xyxyc[5]; + pc.readData(xyxyc, 5); + lcd.rect(xyxyc[0],xyxyc[1],xyxyc[2],xyxyc[3],xyxyc[4]); + lcd.copy_to_lcd(); +} + +void fill_rect() { + char xyxyc[5]; + pc.readData(xyxyc, 5); + lcd.fillrect(xyxyc[0],xyxyc[1],xyxyc[2],xyxyc[3],xyxyc[4]); + lcd.copy_to_lcd(); } void clear_lcd() { //clear lcd @@ -245,6 +286,15 @@ bAcc.enable(); bMag.enable(); + //Pretty wait + ctr=0; + lcd.locate(0,0); + lcd.printf("Awaiting connection..."); + waitTicker.attach(&waitTick,0.5); + while((!pc.readable()) && (pc.readChar()!=RECONNECT)) sleep(); + waitTicker.detach(); + cleanup(); + sw2_int.mode (PullUp); sw2_int.fall(&sw2Down); sw2_int.rise(&sw2Up); @@ -273,15 +323,6 @@ fire_int.rise(&fireDown); fire_int.fall(&fireUp); - //Pretty wait - ctr=0; - lcd.locate(0,0); - lcd.printf("Awaiting connection..."); - waitTicker.attach(&waitTick,0.5); - while((!pc.readable()) && (pc.readChar()!=RECONNECT)) sleep(); - waitTicker.detach(); - cleanup(); - for(;;) { //Check if any interrupts fired if(flags&SW2_UP) {
diff -r 238c6fd5c209 -r d70e3e3690fd main.h --- a/main.h Tue Feb 16 23:07:10 2016 +0000 +++ b/main.h Fri Jan 06 11:08:56 2017 +0000 @@ -10,11 +10,11 @@ //read commands READ_DIGITAL = 0, READ_POT, READ_TEMP, READ_BOARD_ACCEL, READ_SHIELD_ACCEL, READ_BOARD_MAGNO, //set commands - SET_SHIELD_LED, SET_BOARD_LED,SET_PIEZO, + SET_SHIELD_LED, SET_BOARD_LED, SET_PIEZO, //higher level get commands GET_ORIENTATION, GET_SIDE, GET_HEADING, //lcd commands - SET_LCD_POSITION, PRINT_TEXT, SET_PIXEL, CLEAR_LCD, + SET_LCD_POSITION, PRINT_TEXT, SET_PIXEL, DRAW_CIRCLE, FILL_CIRCLE, DRAW_LINE, DRAW_RECT, FILL_RECT, CLEAR_LCD, //other commands RECONNECT, COMMAND_LENGTH } command_character; @@ -34,6 +34,11 @@ void set_lcd_position(); void print_text(); void set_lcd_pixel(); +void draw_circle(); +void fill_circle(); +void draw_line(); +void draw_rect(); +void fill_rect(); void clear_lcd(); void reconnect(); @@ -45,7 +50,7 @@ get_orientation, get_side, get_heading, - set_lcd_position, print_text, set_lcd_pixel, clear_lcd, + set_lcd_position, print_text, set_lcd_pixel, draw_circle, fill_circle, draw_line, draw_rect, fill_rect, clear_lcd, reconnect };