Bmag incl gps rettelse
Dependencies: mbed WDT MODSERIAL BME280
main.h
00001 #include <string> 00002 #include "mbed.h" 00003 #include <time.h> 00004 #include "rtos.h" 00005 #include <Ticker.h> 00006 #include "MODSERIAL/MODSERIAL.h" 00007 #include "NMEA/NMEA.h" 00008 #include "USBHostMSD.h" 00009 #include "WDT/WDT.h" 00010 #include "SPS/SPS.h" 00011 #include "BMAG/BMAG.h" 00012 #include "ErrorHandler/ErrorHandler.h" 00013 #include "BME280/BME280.h" 00014 00015 #define FWSRCVERSION "x" 00016 #define FWIVERSION "1.0.0.7" 00017 #define IDENTIFIERID "00" 00018 #define ENCODING "0" 00019 #define TIMEZONE "ZZZ" 00020 #define SOURCEIDENTIFICATION "0000" 00021 #define GROUP "00" 00022 #define DATALINEVERSION "04" 00023 #define TAG "BMAG" 00024 00025 using namespace std; 00026 00027 //GPS communication init 00028 static MODSERIAL gps(p13, p14, 128); 00029 00030 //BMAG communication init 00031 static MODSERIAL bmag(p9, p10, 64); 00032 00033 //Debug serial connection 00034 static Serial dbg(USBTX, USBRX); 00035 00036 //GPS Rx callback prototype 00037 void rxCallback(MODSERIAL_IRQ_INFO *q); 00038 00039 //BMAG Rx callback prototype 00040 void bmagrxCallback(MODSERIAL_IRQ_INFO *q); 00041 00042 //GPS NMEA Parser 00043 static NMEA gpsNMEA; 00044 00045 //BMAG Parser 00046 static BMAG magParser; 00047 00048 //BME280 i2c conn 00049 static I2C BME280_i2c(p28, p27); 00050 00051 //BME 280 instance 00052 static BME280 BME; 00053 00054 //EA_OLED display 00055 Thread thr_writelines; 00056 SPI * spiptr; 00057 DigitalOut * csptr; 00058 string l1; 00059 string l2; 00060 00061 void init_config(char c){ 00062 *csptr = 0; //chip select to start data transmission 00063 spiptr->write(c); 00064 *csptr = 1; //chip select to end data transmission 00065 wait_us(2); 00066 }; 00067 00068 00069 void EA_OLED(){ 00070 //clear l1 and l2 00071 00072 l1 = ""; 00073 l2 = ""; 00074 00075 spiptr = new SPI(p5, p6, p7); 00076 csptr = new DigitalOut(p8); 00077 00078 *csptr = 1; //high at idle 00079 00080 spiptr->format(10,3); //10bit, high steady state clock 00081 spiptr->frequency(1000000); //1MHz spi clock 00082 00083 00084 //function set european chararacter set 00085 init_config(0x39); 00086 //display off 00087 init_config(0x08); 00088 //entry mode set increment cursor by 1 not shifting display 00089 init_config(0x06); 00090 //Character mode and internel power on 00091 init_config(0x17); 00092 //clear display 00093 init_config(0x01); 00094 //return home 00095 init_config(0x02); 00096 //display on 00097 init_config(0x0C); 00098 wait_ms(10); //Time to stabilize (wont work without) 00099 00100 00101 }; 00102 00103 00104 void clear_display(){ 00105 //clear display 00106 *csptr = 0; //chip select to start data transmission 00107 spiptr->write(0x01); 00108 *csptr = 1; //chip select to end data transmission 00109 Thread::wait(1); 00110 }; 00111 00112 void clear_display_waiting(){ 00113 //clear display 00114 init_config(0x01); 00115 wait_ms(1); 00116 }; 00117 00118 void write_lines(){ 00119 00120 //cursor return 00121 *csptr = 0; //chip select to start data transmission 00122 spiptr->write(0x02); 00123 *csptr = 1; //chip select to end data transmission 00124 Thread::wait(1); 00125 00126 //write l1 00127 for(int i = 0; i < strlen(l1.c_str()); i++){ 00128 *csptr = 0; //chip select to start data transmission 00129 spiptr->write(0x200 | l1[i]); //add 0x02 for character transmission 00130 *csptr = 1; //chip select to end data transmission 00131 Thread::wait(1); 00132 } 00133 00134 //cursor return + cursor pos set 00135 *csptr = 0; //chip select to start data transmission 00136 spiptr->write(0x02); 00137 *csptr = 1; //chip select to end data transmission 00138 wait_us(1000); 00139 Thread::wait(1); 00140 00141 for(int i = 0; i < 64; i++){ 00142 *csptr = 0; //chip select to start data transmission 00143 spiptr->write(0x14); 00144 *csptr = 1; //chip select to end data transmission 00145 wait_us(2); 00146 } 00147 00148 00149 //write l2 00150 for(int i = 0; i < strlen(l2.c_str()); i++){ 00151 *csptr = 0; //chip select to start data transmission 00152 spiptr->write(0x200 | l2[i]); //add 0x02 for character transmission 00153 *csptr = 1; //chip select to end data transmission 00154 wait_us(1000); 00155 Thread::wait(1); 00156 } 00157 //dbg.printf("Display_Updated\r\n"); 00158 }; 00159
Generated on Wed Jul 13 2022 08:04:14 by 1.7.2