![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
for baska
Dependencies: Hepta9axis HeptaBattery HeptaCamera_GPS HeptaTemp SDFileSystem mbed
Fork of Lab4-11_model_program_3 by
main.cpp@19:373bc6926349, 2018-08-22 (annotated)
- Committer:
- ponpoko1939
- Date:
- Wed Aug 22 02:15:07 2018 +0000
- Revision:
- 19:373bc6926349
- Parent:
- 17:2b3b88724c68
Second & Third Question;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 0:bdbd3d6fc5d5 | 1 | #include "mbed.h" |
mbed_official | 0:bdbd3d6fc5d5 | 2 | #include "SDFileSystem.h" |
HEPTA | 17:2b3b88724c68 | 3 | #include "HeptaBattery.h" |
umeume | 2:1c5cdb2c3e0f | 4 | #include "HeptaCamera_GPS.h" |
umeume | 2:1c5cdb2c3e0f | 5 | #include "Hepta9axis.h" |
umeume | 2:1c5cdb2c3e0f | 6 | #include "HeptaTemp.h" |
umeume | 2:1c5cdb2c3e0f | 7 | |
umeume | 2:1c5cdb2c3e0f | 8 | Serial pc(USBTX,USBRX); |
HEPTA | 9:942eb6e8c117 | 9 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
HEPTA | 17:2b3b88724c68 | 10 | HeptaBattery battery(p16,p26); |
umeume | 2:1c5cdb2c3e0f | 11 | HeptaCamera_GPS cam_gps(p13, p14,p25,p24); |
HEPTA | 10:4d6870d0caa0 | 12 | Hepta9axis n_axis(p28,p27,0xD0,0x18); |
ponpoko1939 | 19:373bc6926349 | 13 | HeptaTemp temper(p17); |
HEPTA | 17:2b3b88724c68 | 14 | |
HEPTA | 17:2b3b88724c68 | 15 | DigitalOut myleds[] = {LED1,LED2,LED3,LED4};; |
HEPTA | 17:2b3b88724c68 | 16 | |
HEPTA | 17:2b3b88724c68 | 17 | int rcmd = 0,cmdflag = 0; |
umeume | 2:1c5cdb2c3e0f | 18 | |
HEPTA | 17:2b3b88724c68 | 19 | void commandget() |
HEPTA | 17:2b3b88724c68 | 20 | { |
HEPTA | 17:2b3b88724c68 | 21 | rcmd=pc.getc(); |
HEPTA | 17:2b3b88724c68 | 22 | cmdflag = 1; |
HEPTA | 17:2b3b88724c68 | 23 | } |
HEPTA | 17:2b3b88724c68 | 24 | void receive(int *xrcmd, int *xcmdflag) |
HEPTA | 17:2b3b88724c68 | 25 | { |
HEPTA | 17:2b3b88724c68 | 26 | pc.attach(commandget,Serial::RxIrq); |
HEPTA | 17:2b3b88724c68 | 27 | *xrcmd = rcmd; |
HEPTA | 17:2b3b88724c68 | 28 | *xcmdflag = cmdflag; |
HEPTA | 17:2b3b88724c68 | 29 | } |
HEPTA | 17:2b3b88724c68 | 30 | |
HEPTA | 17:2b3b88724c68 | 31 | void initialize() |
HEPTA | 17:2b3b88724c68 | 32 | { |
HEPTA | 17:2b3b88724c68 | 33 | rcmd = 0; |
HEPTA | 17:2b3b88724c68 | 34 | cmdflag = 0; |
HEPTA | 17:2b3b88724c68 | 35 | } |
umeume | 5:c5ccb1b07e8f | 36 | |
umeume | 2:1c5cdb2c3e0f | 37 | int main() |
umeume | 2:1c5cdb2c3e0f | 38 | { |
HEPTA | 17:2b3b88724c68 | 39 | pc.baud(9600); |
HEPTA | 17:2b3b88724c68 | 40 | float bt; |
ponpoko1939 | 19:373bc6926349 | 41 | float temp; |
HEPTA | 17:2b3b88724c68 | 42 | char str[100]; |
HEPTA | 17:2b3b88724c68 | 43 | float ax,ay,az; |
HEPTA | 17:2b3b88724c68 | 44 | float gx,gy,gz; |
HEPTA | 17:2b3b88724c68 | 45 | float mx,my,mz; |
HEPTA | 17:2b3b88724c68 | 46 | int quality=0,stnum=0,gps_check=0; |
HEPTA | 17:2b3b88724c68 | 47 | char ns='A',ew='B',aunit='m'; |
HEPTA | 17:2b3b88724c68 | 48 | float time=0.0,latitude=0.0,longitude=0.0,hacu=0.0,altitude=0.0; |
HEPTA | 17:2b3b88724c68 | 49 | int flag = 0; |
HEPTA | 17:2b3b88724c68 | 50 | while(1) { |
HEPTA | 17:2b3b88724c68 | 51 | battery.power_saving_mode(&flag,&bt); |
ponpoko1939 | 19:373bc6926349 | 52 | temper.temp_sense(&temp); |
HEPTA | 17:2b3b88724c68 | 53 | wait(0.5); |
ponpoko1939 | 19:373bc6926349 | 54 | pc.printf("flag = %d, bt = %.2f [V]\r\n",flag,bt); |
HEPTA | 17:2b3b88724c68 | 55 | if(flag == 1) { |
HEPTA | 17:2b3b88724c68 | 56 | pc.printf("Low Battery\r\n"); |
ponpoko1939 | 19:373bc6926349 | 57 | } else if(temp > 35.0) { |
HEPTA | 17:2b3b88724c68 | 58 | pc.printf("High Temperaturer\n"); |
ponpoko1939 | 19:373bc6926349 | 59 | } else if((flag == 1) & (temp > 35.0)) { |
HEPTA | 17:2b3b88724c68 | 60 | pc.printf("Low Battery and High Temperaturer\n"); |
HEPTA | 17:2b3b88724c68 | 61 | } |
HEPTA | 17:2b3b88724c68 | 62 | receive(&rcmd,&cmdflag); |
HEPTA | 17:2b3b88724c68 | 63 | if (cmdflag == 1) { |
HEPTA | 17:2b3b88724c68 | 64 | pc.printf("Command Get = %d\r\n",rcmd); |
HEPTA | 17:2b3b88724c68 | 65 | if (rcmd == 'a') { |
HEPTA | 17:2b3b88724c68 | 66 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 67 | pc.printf("Count = %d\r\n",i); |
HEPTA | 17:2b3b88724c68 | 68 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 69 | } |
HEPTA | 17:2b3b88724c68 | 70 | } |
HEPTA | 17:2b3b88724c68 | 71 | if (rcmd == 'b') { |
HEPTA | 17:2b3b88724c68 | 72 | mkdir("/sd/mydir", 0777); |
HEPTA | 17:2b3b88724c68 | 73 | FILE *fp = fopen("/sd/mydir/battery.txt","w"); |
HEPTA | 17:2b3b88724c68 | 74 | if(fp == NULL) { |
HEPTA | 17:2b3b88724c68 | 75 | error("Could not open file for write\r\n"); |
HEPTA | 17:2b3b88724c68 | 76 | } else { |
HEPTA | 17:2b3b88724c68 | 77 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 78 | battery.vol(&bt); |
HEPTA | 17:2b3b88724c68 | 79 | fprintf(fp,"%f\r\n",bt); |
HEPTA | 17:2b3b88724c68 | 80 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 81 | } |
HEPTA | 17:2b3b88724c68 | 82 | fclose(fp); |
HEPTA | 17:2b3b88724c68 | 83 | } |
HEPTA | 17:2b3b88724c68 | 84 | FILE *fp1 = fopen("/sd/mydir/battery.txt","r"); |
HEPTA | 17:2b3b88724c68 | 85 | if(fp1 == NULL) { |
HEPTA | 17:2b3b88724c68 | 86 | error("Could not open file for read\r\n"); |
HEPTA | 17:2b3b88724c68 | 87 | } else { |
HEPTA | 17:2b3b88724c68 | 88 | for(int i = 0; i < 10; i++) { |
HEPTA | 17:2b3b88724c68 | 89 | fgets(str,100,fp1); |
HEPTA | 17:2b3b88724c68 | 90 | puts(str); |
HEPTA | 17:2b3b88724c68 | 91 | wait(1.0); |
HEPTA | 17:2b3b88724c68 | 92 | } |
HEPTA | 17:2b3b88724c68 | 93 | fclose(fp1); |
HEPTA | 17:2b3b88724c68 | 94 | } |
HEPTA | 17:2b3b88724c68 | 95 | }// |
HEPTA | 17:2b3b88724c68 | 96 | if (rcmd == 'c') { |
ponpoko1939 | 19:373bc6926349 | 97 | //pc.printf("Command Get = %d", 'rcmd'); |
ponpoko1939 | 19:373bc6926349 | 98 | //get temperture |
ponpoko1939 | 19:373bc6926349 | 99 | temper.temp_sense(&temp); |
ponpoko1939 | 19:373bc6926349 | 100 | //get 9-axis |
ponpoko1939 | 19:373bc6926349 | 101 | n_axis.sen_acc(&ax,&ay,&az); |
ponpoko1939 | 19:373bc6926349 | 102 | n_axis.sen_gyro(&gx,&gy,&gz); |
ponpoko1939 | 19:373bc6926349 | 103 | n_axis.sen_mag(&mx,&my,&mz); |
ponpoko1939 | 19:373bc6926349 | 104 | //get GPS Data |
ponpoko1939 | 19:373bc6926349 | 105 | cam_gps.gga_sensing(&time, &latitude, &ns, &longitude, &ew, &quality, &stnum, &hacu, &altitude, &aunit, &gps_check); |
HEPTA | 17:2b3b88724c68 | 106 | |
ponpoko1939 | 19:373bc6926349 | 107 | //Display_All Data |
ponpoko1939 | 19:373bc6926349 | 108 | pc.printf("temp = %.2f[C]\r\n",temp); |
ponpoko1939 | 19:373bc6926349 | 109 | pc.printf("%f,%f,%f\r\n",ax,ay,az); |
ponpoko1939 | 19:373bc6926349 | 110 | pc.printf("%f,%f,%f\r\n",gx,gy,gz); |
ponpoko1939 | 19:373bc6926349 | 111 | pc.printf("%f,%f,%f\r\n",mx,my,mz); |
ponpoko1939 | 19:373bc6926349 | 112 | pc.printf("GPGGA,%f,%f,%c,%f,%c,%d,%d,%f,%f,%c\r\n",time,latitude,ns,longitude,ew,quality,stnum,hacu,altitude,aunit); |
ponpoko1939 | 19:373bc6926349 | 113 | wait(0.3); |
HEPTA | 17:2b3b88724c68 | 114 | } |
HEPTA | 17:2b3b88724c68 | 115 | if (rcmd == 'd') { |
ponpoko1939 | 19:373bc6926349 | 116 | pc.printf("Camera Snapshot Mode\r\n"); |
ponpoko1939 | 19:373bc6926349 | 117 | pc.printf("Hit Any Key To Take Picture\r\n"); |
ponpoko1939 | 19:373bc6926349 | 118 | while(!pc.readable()) {} |
ponpoko1939 | 19:373bc6926349 | 119 | cam_gps.Sync(); |
ponpoko1939 | 19:373bc6926349 | 120 | cam_gps.initialize(HeptaCamera_GPS::Baud115200, HeptaCamera_GPS::JpegResolution320x240); |
ponpoko1939 | 19:373bc6926349 | 121 | cam_gps.test_jpeg_snapshot_picture("/sd/test.jpg"); |
HEPTA | 17:2b3b88724c68 | 122 | } |
HEPTA | 17:2b3b88724c68 | 123 | initialize(); |
HEPTA | 17:2b3b88724c68 | 124 | } |
HEPTA | 17:2b3b88724c68 | 125 | } |
ponpoko1939 | 19:373bc6926349 | 126 | } |