diff --git a/arduino_ESP32_oscilloscope/myBlueTooth.cpp b/arduino_ESP32_oscilloscope/myBlueTooth.cpp deleted file mode 100644 index c45099540d55a4d48da3583a3decc1fb088a9242..0000000000000000000000000000000000000000 --- a/arduino_ESP32_oscilloscope/myBlueTooth.cpp +++ /dev/null @@ -1,362 +0,0 @@ -#include "myBlueTooth.h" -/* -1)前半段是对蓝牙的进行封装, -2)后半段是对“学会助手”的ESP32核心板移植操作 - 如果出现 stm32f1 可以使用,在 esp32 中不能使用, - 可以自己进行修改代码,或者向“学会助手”的群里提出来,等待处理 -*/ -BluetoothSerial SerialBT; - -static char receivedBuffer[100]; - -void BTConfirmRequestCallback(uint32_t numVal); -void BTAuthCompleteCallback(boolean success); -/*************蓝牙参数配置**********************/ -void Bluetooth_Event(esp_spp_cb_event_t event, esp_spp_cb_param_t *param); // 蓝牙事件回调函数 - -/*蓝牙参数配置*/ -// 初始化蓝牙配置 -void initializeBluetooth(const String &deviceName) -{ - SerialBT.enableSSP(); // 在begin之前调用 - SerialBT.onConfirmRequest(BTConfirmRequestCallback); - SerialBT.onAuthComplete(BTAuthCompleteCallback); - SerialBT.register_callback(Bluetooth_Event); // 设置事件回调函数 连接 断开 发送 接收 - SerialBT.begin(deviceName); // Bluetooth device name -} - -/*蓝牙发送浮点数据,转为字符串发送*/ -void sendFloatViaBluetooth(const float data) -{ - char dstr[20]; - sprintf(dstr, "%.2f", data); // 浮点数转字符串 - SerialBT.write((uint8_t *)dstr, strlen(dstr)); // 直接发送整个字符串 -} - -/*蓝牙发送字符串*/ -void sendStringViaBluetooth(const char *stringData) -{ - if (stringData != NULL) - { - SerialBT.write((uint8_t *)stringData, strlen(stringData)); - } -} - -/*获取蓝牙发送内容*/ -char *getReceivedBluetoothData() -{ - return receivedBuffer; -} - -/******************* 蓝牙事件回调函数 ******************/ -void Bluetooth_Event(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) // 蓝牙事件回调函数 -{ - uint16_t index = 0; - - switch (event) - { - // 蓝牙连接成功标志 - case ESP_SPP_SRV_OPEN_EVT: - case ESP_SPP_OPEN_EVT: - { - char connection[] = "connection successful!\r\n"; - sendStringViaBluetooth(connection); - break; - } - // 蓝牙断开连接标志 - case ESP_SPP_CLOSE_EVT: - { - char disconnect[] = "disconnect successful!\r\n"; - sendStringViaBluetooth(disconnect); - break; - } - // 数据接收标志 - case ESP_SPP_DATA_IND_EVT: - { - memset(receivedBuffer, 0, sizeof(receivedBuffer)); - while (SerialBT.available()) // 等待接收完成 - { - receivedBuffer[index++] = SerialBT.read(); // 按字节存储 - } - break; - } - // 数据发送标志 - case ESP_SPP_WRITE_EVT: - { - Serial.write("send complete!\r\n"); - break; - } - } -} - -// 认证请求回调 -void BTConfirmRequestCallback(uint32_t numVal) -{ - // numVal是主机发来的识别码 - Serial.printf("recv pin: %d \r\n", numVal); - - // 这里要对这个识别码进行判断,是否和主机一样或是是否是我们从机内置的密码 - // 然后再判断是否确定连接,我们这里直接确认了 - - SerialBT.confirmReply(true); - // SerialBT.confirmReply(false); // 如果要拒绝就用这句 -} - -// 认证结果回调函数 -void BTAuthCompleteCallback(boolean success) -{ - if (success) - Serial.println("Pairing success!!"); - else - Serial.println("Pairing failed, rejected by user!!"); -} - -/********************************************************************************************************************** - *@brief 学会助手安卓版本APP虚拟示波器下位机测试程序 - *@by 一品芝麻糕 - *@notice 与学会助手APP虚拟示波器配合使用 - * 硬件:STM32F103C8T6,通信模块:蓝牙模块(建议经典蓝牙) - * 接线: - * A9 ----- RX - * A10----- TX - * 5V ----- 5V - * GND----- GND - *@version 1.4.0 - * 2024-04-24 - * 西电 嵌牛实验室 - *********************************************************************************************************************/ - -// 发送一个字节 -bool XHZS_SendByte(uint8_t *byte) -{ - // 参数校验:确保byte不是空指针。 - if (byte == nullptr) - { - return false; - } - else - { - SerialBT.write(*byte); - return true; - } -} - -// 发送数组 -bool XHZS_SendArray(uint8_t *array, size_t arraySize) -{ - - if (array == nullptr || arraySize == 0) - { - return false; - } - else - { - // 数组发生是个耗时操作,建议DMA优化 - SerialBT.write(array, arraySize); - return true; - } -} - -/************************************************************** - *函数名称:XHZS_SendWave - *简 介:学会助手APP虚拟示波器下位机程序(兼容山外) - *输 入:wareaddr:数据数组起始地址 waresize:数组大小 - *输 出:无 - *注意事项:void *waveaddr 为数组类型,char and string 类型无效 - *注意事项:示波器支持 uin16_t,建立一个 uint16_t fun[4] 数组, - 元素是通道数量 - **************************************************************/ -void XHZS_SendWave(const void *waveAddr, uint16_t waveSize) -{ - // 参数检查 - if (waveAddr == nullptr || waveSize == 0) - { - return; - } - uint8_t cmd_head[2] = {0x03, 0xFC}; // 帧头 - uint8_t cmd_tail[2] = {0xFC, 0x03}; // 帧尾 - - XHZS_SendArray(cmd_head, sizeof(cmd_head)); // 发送帧头 - XHZS_SendArray((uint8_t *)waveAddr, waveSize); // 发送数据 - XHZS_SendArray(cmd_tail, sizeof(cmd_tail)); // 发送帧尾 -} - -// /************************************************************** -// *函数名称:SendWave -// *简 介:发送数据到学会助手APP虚拟示波器 -// *输 入:无 -// *输 出:无 -// *注意事项:将要发送的数据赋值给Wave数组即可,通道依次对应 -// **************************************************************/ -void SendWave() -{ - float i; - float Wave[4] = {0}; // 注意数据类型;数组大小即为通道数量,最多四条通道 - - // 正弦波测试 - for (i = 0; i < 500; i += 0.1) - { - Wave[0] = sin(i); - Wave[1] = cos(i); - Wave[2] = -sin(i); - Wave[3] = -cos(i); - XHZS_SendWave(Wave, sizeof(Wave)); - - vTaskDelay(100 / portTICK_PERIOD_MS); - } -} -// // 重载函数测试中使用 -// void XHZS_SendWave() -// { -// float i; -// float Wave[4] = {0}; // 注意数据类型;数组大小即为通道数量,最多四条通道 -// // // test one channel start -// // Wave[0] = 2; -// // Wave[1] = 4; -// // Wave[2] = 6; -// // Wave[3] = 8; - -// // XHZS_SendWave((uint8_t *)Wave, sizeof(Wave)); -// // test one channel end -// // --------------------------------------------- -// // // test two channel start -// // // 正弦波测试 -// for (i = 0; i < 500; i += 0.1) -// { -// Wave[0] = sin(i); -// Wave[1] = cos(i); -// Wave[2] = -sin(i); -// Wave[3] = -cos(i); -// XHZS_SendWave((uint8_t *)Wave, sizeof(Wave)); - -// vTaskDelay(100 / portTICK_PERIOD_MS); -// } -// // test two channel end -// } - -/************************************************************** - *函数名称:OscGetFloat - *简 介:将字符转为浮点数 - *输 入:p:字符串;value:用于获取输出值 - *输 出:(==0)转成功;(!=0)转失败 - *注意事项:虚拟示波器调参用,以','为数据分隔符 - **************************************************************/ -char XHZS_OscGetFloat(const char *p, float *value) -{ - // c11:11.04,c12:109,c13:434,c14:32, - int i; - int negative_flag = 1; - int float_flag = 0; - float tmp_value = 0; - for (i = 0; i < 16; i++) - { - if (*p == ',') // 检测到分隔符,返回值 - { - tmp_value *= negative_flag; - *value = tmp_value; - return 0; - } - else if (*p == '-') // 检测到负号 - { - negative_flag = -1; - } - else if (*p == '.') // 检测到小数点 - { - float_flag = -1; - } - else if (*p >= '0' && *p <= '9') - { - if (float_flag == 0) - { - tmp_value = tmp_value * 10 + (*p - 0x30); - } - else - { - tmp_value += (*p - 0x30) * pow(10, float_flag); - float_flag--; - } - } - else - { - return 1; - } - p++; - } - return 2; -} - -/************************************************************** - *函数名称:OscGetValue - *简 介:从字符串中获取指定参数数值 - *输 入:p:字符串,以'\0'结尾,否则将出错 - * name:指定参数名称,如"c12"获取第1组第2个参数; - * value:用于获取输出值; - *输 出:(==0)转成功;(!=0)转失败 - *注意事项:虚拟示波器调参用,字符串中以'\0'为结束符 - **************************************************************/ -char XHZS_OscGetValue(const char *p, const char *name, float *value) -{ - // c11:114,c12:109,c13:434,c14:32, - float tmp_value; - int feedback; - p = strstr(p, name); - if (p == NULL) - { - return 1; - } - p += 4; - feedback = XHZS_OscGetFloat(p, &tmp_value); - if (feedback == 0) - { - *value = tmp_value; - return 0; - } - return 2; -} - -// 蓝牙部分测试 start --------------------- -void test_blueTooth() -{ - - float floatValue = 3.14; - String str = "hello world"; - // 串口发送数据 - sendFloatViaBluetooth(floatValue); - sendStringViaBluetooth(str.c_str()); - // 串口接收数据,发送到串口, - SerialBT.println(getReceivedBluetoothData()); - // 蓝牙部分测试 end -} - -// 学会助手 test1 start -int intValue = 2; -float floatValue = 6.04; -// 测试字符串的变量发送 -void test_sendString() -{ - intValue = (intValue > 20 ? 0 : (intValue += 1)); - floatValue = (floatValue > 20 ? -10 : (floatValue += 4)); - - SerialBT.printf("w:%d,%0.2f,6,8\r\n", intValue, floatValue); -} - -// 正弦波输出测试 -void test_sendSin() -{ - // XHZS_SendWave(); - SendWave(); -} - -// 示波器的输入和输出测试 -void test_oscilloscope_input_and_output() -{ - float floatValue1, floatValue2, floatValue3, floatValue4; - char *charData = getReceivedBluetoothData(); - - XHZS_OscGetValue(charData, "c11", &floatValue1); - XHZS_OscGetValue(charData, "c12", &floatValue2); - XHZS_OscGetValue(charData, "c13", &floatValue3); - XHZS_OscGetValue(charData, "c14", &floatValue4); - - SerialBT.printf("w:%0.2f,%0.2f,%0.2f,%0.2f\r\n", floatValue1, floatValue2, floatValue3, floatValue4); -} diff --git a/arduino_ESP32_oscilloscope/myBlueTooth.h b/arduino_ESP32_oscilloscope/myBlueTooth.h deleted file mode 100644 index 89af78398bcd6f8522703265e6e190b114fd60e7..0000000000000000000000000000000000000000 --- a/arduino_ESP32_oscilloscope/myBlueTooth.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * myBlueTooth.cpp + myBlueTooth.h - * 功能:对ESP32经典蓝牙的简单封装,工作在从机模式,基于单字节蓝牙发送定义了浮点数、字符串等发送函数 - * 说明:接收蓝牙数据时通过中断接收,直接调用相应接口就能读取 - */ -#ifndef MYBLUETOOTH_H_ -#define MYBLUETOOTH_H_ - -#include -#include -#include - -// 初始化蓝牙设备并设置设备名称 -void initializeBluetooth(const String &deviceName = "mini_bot"); - -// 将浮点数转换为字符串并通过蓝牙发送 -void sendFloatViaBluetooth(const float data); - -// 通过蓝牙发送字符串 -void sendStringViaBluetooth(const char *stringData); - -// 获取通过蓝牙接收的字符串数据 -char *getReceivedBluetoothData(); - -// 学会助手移植部分 start ------------------------- -// 发送单个字节数据 -bool XHZS_SendByte(uint8_t *byte); - -// 发送字节数组 -bool XHZS_SendArray(uint8_t *array, size_t arraySize); - -// 发送波形数据, 测试 -// void XHZS_SendWave(); - -// 此函数用于向示波器发送波形数据 -// 它作为一个模板,演示了如何正确地输出波形 -// 用户应根据所需的具体波形类型调整函数内部的逻辑 -void SendWave(); - -// 发送一组数据,包括帧头、内容和帧尾 -void XHZS_SendWave(const void *waveAddr, uint16_t waveSize); - -// 从字符串中解析并获取浮点数 -// char XHZS_OscGetFloat(const char *p, float *value); - -// 根据名称从字符串中提取并获取值 -char XHZS_OscGetValue(const char *p, const char *name, float *value); - -// 学会助手移植部分 end ------------------------- -// 学会助手使用案例 start --------------------- - -void test_blueTooth(); // 蓝牙测试 - -void test_sendString(); // 测试字符串的变量发送 - -void test_sendSin(); // 正弦波输出测试 - -void test_oscilloscope_input_and_output(); // 示波器的输入和输出测试 - -// 学会助手使用案例 end --------------------- - -#endif /* MYBLUETOOTH_H_ */ diff --git a/arduino_ESP32_oscilloscope/oscilloscope.ino b/arduino_ESP32_oscilloscope/oscilloscope.ino deleted file mode 100644 index ce8efc717c8855f1ed75e4f400bcc519584c932e..0000000000000000000000000000000000000000 --- a/arduino_ESP32_oscilloscope/oscilloscope.ino +++ /dev/null @@ -1,26 +0,0 @@ -// -// select engineering environment: ESP32_WROVER_Kit(all_versions) -// 想使用“学会助手”功能,查看 myBlueTooth.h 头文件里面有相关说明 -// 学会助手的示波器部分可以使用,功能与基于 STM32 的 keil工程一致 -// -// #include -#include "myBlueTooth.h" - -void setup() -{ - initializeBluetooth(); // 默认蓝牙名称为:mini_bot - Serial.begin(115200); // 开启串口通信,频率为:115200 -} -void loop() -{ - // test_blueTooth(); // 蓝牙测试 - - // test_sendString(); // 测试字符串的变量发送 - - test_sendSin(); // 正弦波输出测试 - - // test_oscilloscope_input_and_output(); // 示波器的输入和输出测试 - - vTaskDelay(100 / portTICK_PERIOD_MS); -} -// 想使用“学会助手”功能,查看 myBlueTooth.h 头文件里面有相关说明 diff --git a/platfromIO_ESP32_oscilloscope/.gitignore b/platfromIO_ESP32_oscilloscope/.gitignore deleted file mode 100644 index 89cc49cbd652508924b868ea609fa8f6b758ec56..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -.pio -.vscode/.browse.c_cpp.db* -.vscode/c_cpp_properties.json -.vscode/launch.json -.vscode/ipch diff --git a/platfromIO_ESP32_oscilloscope/.vscode/extensions.json b/platfromIO_ESP32_oscilloscope/.vscode/extensions.json deleted file mode 100644 index 080e70d08b9811fa743afe5094658dba0ed6b7c2..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/.vscode/extensions.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - // See http://go.microsoft.com/fwlink/?LinkId=827846 - // for the documentation about the extensions.json format - "recommendations": [ - "platformio.platformio-ide" - ], - "unwantedRecommendations": [ - "ms-vscode.cpptools-extension-pack" - ] -} diff --git a/platfromIO_ESP32_oscilloscope/include/README b/platfromIO_ESP32_oscilloscope/include/README deleted file mode 100644 index 194dcd43252dcbeb2044ee38510415041a0e7b47..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.cpp b/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.cpp deleted file mode 100644 index 61a9cc818851c17d41a4d1f93e9e3abb048897e2..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.cpp +++ /dev/null @@ -1,44 +0,0 @@ -#include "Interrupts_and_timers.h" -// 定时中断 start -Ticker timer; -void t_setupInterrupts() -{ - Serial.begin(115200); - timer.attach_ms(1000, timerInterrupt); // 每隔1000ms触发一次中断 -} -void timerInterrupt() -{ - Serial.println("Timer interrupt!"); -} -// 定时中断 end -//--------------------------------- -// 硬件状态中断 start -const int INTERRUPT_PIN = 2; // 假设使用数字引脚2作为中断引脚 -static bool lastState = LOW; // 上次读取的引脚状态 -static int number = 0; - -void h_setupInterrupts() -{ - Serial.begin(115200); - pinMode(INTERRUPT_PIN, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), handleInterrupt, FALLING); -} -void handleInterrupt() -{ - if (LOW == digitalRead(INTERRUPT_PIN)) - { - number++; - lastState = HIGH; - } - else if (HIGH == digitalRead(INTERRUPT_PIN)) - { - lastState = LOW; - } -} -void handleInterruptPrintf() -{ - // 主循环可以在这里进行其他任务 - Serial.printf("count: %d\n", number); - delay(30); -} -// 硬件状态中断 start diff --git a/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.h b/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.h deleted file mode 100644 index 0a02c6c101cbd741fbc94f85be61f92a638d5f4b..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/Interrupts_and_timers/Interrupts_and_timers.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __INTERRUPTS_AND_TIMERS_H__ -#define __INTERRUPTS_AND_TIMERS_H__ - -#include -#include - - -void t_setupInterrupts(); -void timerInterrupt(); - -void h_setupInterrupts(); -void handleInterrupt(); -void handleInterruptPrintf(); - - -#endif diff --git a/platfromIO_ESP32_oscilloscope/lib/README b/platfromIO_ESP32_oscilloscope/lib/README deleted file mode 100644 index 2593a33f9faf73cd984d3bc0218161d925927554..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/README +++ /dev/null @@ -1,46 +0,0 @@ - -This directory is intended for project specific (private) libraries. -PlatformIO will compile them to static libraries and link into executable file. - -The source code of each library should be placed in an own separate directory -("lib/your_library_name/[here are source files]"). - -For example, see a structure of the following two libraries `Foo` and `Bar`: - -|--lib -| | -| |--Bar -| | |--docs -| | |--examples -| | |--src -| | |- Bar.c -| | |- Bar.h -| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html -| | -| |--Foo -| | |- Foo.c -| | |- Foo.h -| | -| |- README --> THIS FILE -| -|- platformio.ini -|--src - |- main.c - -and a contents of `src/main.c`: -``` -#include -#include - -int main (void) -{ - ... -} - -``` - -PlatformIO Library Dependency Finder will find automatically dependent -libraries scanning project source files. - -More information about PlatformIO Library Dependency Finder -- https://docs.platformio.org/page/librarymanager/ldf.html diff --git a/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.cpp b/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.cpp deleted file mode 100644 index cd7ba1190d1500bf16f1c1d056ed2a9ce3bdf918..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.cpp +++ /dev/null @@ -1,64 +0,0 @@ -#include "WS2812B_LED.h" - -// Define the array of leds - -CRGB leds[NUM_LEDS]; -int delay_time = 500; - -bool isLed = true; -void ws2812b_led_init() -{ - - FastLED.addLeds(leds, NUM_LEDS); // GRB ordering is typical -} -void ws2812b_led_Blink() -{ - // leds[0] = CRGB::Green; - // FastLED.setBrightness(1); // 设置亮度 - // FastLED.show(); - // delay(delay_time); - // leds[0] = CRGB::Yellow; - // FastLED.setBrightness(1); // 设置亮度 - // FastLED.show(); - // delay(delay_time); - // // Turn the LED on, then pause - // leds[0] = CRGB::Blue; - // FastLED.setBrightness(1); // 设置亮度 - // FastLED.show(); - // delay(delay_time); - - // if (isLed == true) - // { - // leds[0] = CRGB::DarkGreen; - // FastLED.setBrightness(1); // 设置亮度 - // FastLED.show(); - // isLed = false; - // } - // else - // { - // leds[0] = CRGB::DarkRed; - // FastLED.setBrightness(1); // 设置亮度 - // FastLED.show(); - // isLed = true; - // } - - // isLed = !isLed; - - switch (isLed) - { - case true: - leds[0] = CRGB::DarkGreen; - FastLED.setBrightness(1); // 设置亮度 - FastLED.show(); - isLed = false; - delay(delay_time); - break; - case false: - leds[0] = CRGB::DarkRed; - FastLED.setBrightness(1); // 设置亮度 - FastLED.show(); - isLed = true; - delay(delay_time); - break; - } -} diff --git a/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.h b/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.h deleted file mode 100644 index 41ffa8dc90d7ae013b727e3c966028e9442a93ed..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/WS2812B_LED/WS2812B_LED.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __WS2812B_LED_H__ -#define __WS2812B_LED_H__ -/* -ESP32-WROOM-32E 硬件 HSPI 引脚 -MISO 12 -MISI 13 -SCK 14 -SS 15 -*/ -#include -#include - -// How many leds in your strip? -#define NUM_LEDS 1 - -#define DATA_PIN 16 -#define CLOCK_PIN 14 - - -void ws2812b_led_init(); -void ws2812b_led_Blink(); - -#endif diff --git a/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.cpp b/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.cpp deleted file mode 100644 index 65872d3f4206804ac3d0ddd55105eb5b20987f7a..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.cpp +++ /dev/null @@ -1,353 +0,0 @@ -#include "myBlueTooth.h" -/* -1)前半段是对蓝牙的进行封装, -2)后半段是对“学会助手”的ESP32核心板移植操作 - 如果出现 stm32f1 可以使用,在 esp32 中不能使用, - 可以自己进行修改代码,或者向“学会助手”的群里提出来,等待处理 -*/ -BluetoothSerial SerialBT; - -static char receivedBuffer[120]; - -void BTConfirmRequestCallback(uint32_t numVal); -void BTAuthCompleteCallback(boolean success); -/*************蓝牙参数配置**********************/ -void Bluetooth_Event(esp_spp_cb_event_t event, esp_spp_cb_param_t *param); // 蓝牙事件回调函数 - -/*蓝牙参数配置*/ -// 初始化蓝牙配置 -void initializeBluetooth(const String &deviceName) -{ - SerialBT.enableSSP(); // 在begin之前调用 - SerialBT.onConfirmRequest(BTConfirmRequestCallback); - SerialBT.onAuthComplete(BTAuthCompleteCallback); - SerialBT.register_callback(Bluetooth_Event); // 设置事件回调函数 连接 断开 发送 接收 - SerialBT.begin(deviceName); // Bluetooth device name -} - -/*蓝牙发送浮点数据,转为字符串发送*/ -void sendFloatViaBluetooth(const float data) -{ - char dstr[20]; - sprintf(dstr, "%.2f", data); // 浮点数转字符串 - SerialBT.write((uint8_t *)dstr, strlen(dstr)); // 直接发送整个字符串 -} - -/*蓝牙发送字符串*/ -void sendStringViaBluetooth(const char *stringData) -{ - if (stringData != NULL) - { - SerialBT.write((uint8_t *)stringData, strlen(stringData)); - } -} - -/*获取蓝牙发送内容*/ -char *getReceivedBluetoothData() -{ - return receivedBuffer; -} - -/******************* 蓝牙事件回调函数 ******************/ -void Bluetooth_Event(esp_spp_cb_event_t event, esp_spp_cb_param_t *param) // 蓝牙事件回调函数 -{ - uint16_t index = 0; - - switch (event) - { - // 蓝牙连接成功标志 - case ESP_SPP_SRV_OPEN_EVT: - case ESP_SPP_OPEN_EVT: - { - char connection[] = "connection successful!\r\n"; - sendStringViaBluetooth(connection); - break; - } - // 蓝牙断开连接标志 - case ESP_SPP_CLOSE_EVT: - { - char disconnect[] = "disconnect successful!\r\n"; - sendStringViaBluetooth(disconnect); - break; - } - // 数据接收标志 - case ESP_SPP_DATA_IND_EVT: - { - memset(receivedBuffer, 0, sizeof(receivedBuffer)); - while (SerialBT.available()) // 等待接收完成 - { - receivedBuffer[index++] = SerialBT.read(); // 按字节存储 - } - break; - } - // 数据发送标志 - case ESP_SPP_WRITE_EVT: - { - Serial.write("send complete!\r\n"); - break; - } - } -} - -// 认证请求回调 -void BTConfirmRequestCallback(uint32_t numVal) -{ - // numVal是主机发来的识别码 - Serial.printf("recv pin: %d \r\n", numVal); - - // 这里要对这个识别码进行判断,是否和主机一样或是是否是我们从机内置的密码 - // 然后再判断是否确定连接,我们这里直接确认了 - - SerialBT.confirmReply(true); - // SerialBT.confirmReply(false); // 如果要拒绝就用这句 -} - -// 认证结果回调函数 -void BTAuthCompleteCallback(boolean success) -{ - if (success) - Serial.println("Pairing success!!"); - else - Serial.println("Pairing failed, rejected by user!!"); -} - -/********************************************************************************************************************** - *@brief 学会助手安卓版本APP虚拟示波器下位机测试程序 - *@by 一品芝麻糕 - *@notice 与学会助手APP虚拟示波器配合使用 - * 硬件:STM32F103C8T6,通信模块:蓝牙模块(建议经典蓝牙) - * 接线: - * A9 ----- RX - * A10----- TX - * 5V ----- 5V - * GND----- GND - *@version 1.4.0 - * 2024-04-24 - * 西电 嵌牛实验室 - *********************************************************************************************************************/ - -// 发送一个字节 -bool XHZS_SendByte(const uint8_t *byte) -{ - // 参数校验:确保byte不是空指针。 - if (byte == nullptr) - { - return false; - } - else - { - SerialBT.write(*byte); - return true; - } -} - -// 发送数组 -bool XHZS_SendArray(const uint8_t *array, size_t arraySize) -{ - - if (array == nullptr || arraySize == 0) - { - return false; - } - else - { - // 数组发生是个耗时操作,建议DMA优化 - SerialBT.write(array, arraySize); - return true; - } -} - -/************************************************************** - *函数名称:XHZS_SendWave - *简 介:学会助手APP虚拟示波器下位机程序(兼容山外) - *输 入:wareaddr:数据数组起始地址 waresize:数组大小 - *输 出:无 - *注意事项:void *waveaddr 为数组类型,char and string 类型无效 - *注意事项:示波器支持 uin16_t,建立一个 uint16_t fun[4] 数组, - 元素是通道数量 - **************************************************************/ -void XHZS_SendWave(const void *waveAddr, uint16_t waveSize) -{ - // 参数检查 - if (waveAddr == nullptr || waveSize == 0) - { - return; - } - uint8_t cmd_head[2] = {0x03, 0xFC}; // 帧头 - uint8_t cmd_tail[2] = {0xFC, 0x03}; // 帧尾 - - XHZS_SendArray(cmd_head, sizeof(cmd_head)); // 发送帧头 - XHZS_SendArray((uint8_t *)waveAddr, waveSize); // 发送数据 - XHZS_SendArray(cmd_tail, sizeof(cmd_tail)); // 发送帧尾 -} - -/************************************************************** - *函数名称:OscGetFloat - *简 介:将字符转为浮点数 - *输 入:p:字符串;value:用于获取输出值 - *输 出:(==0)转成功;(!=0)转失败 - *注意事项:虚拟示波器调参用,以','为数据分隔符 - **************************************************************/ -char XHZS_OscGetFloat(const char *p, float *value) -{ - // c11:11.04,c12:109,c13:434,c14:32, - int i; - int negative_flag = 1; - int float_flag = 0; - float tmp_value = 0; - for (i = 0; i < 16; i++) - { - if (*p == ',') // 检测到分隔符,返回值 - { - tmp_value *= negative_flag; - *value = tmp_value; - return 0; - } - else if (*p == '-') // 检测到负号 - { - negative_flag = -1; - } - else if (*p == '.') // 检测到小数点 - { - float_flag = -1; - } - else if (*p >= '0' && *p <= '9') - { - if (float_flag == 0) - { - tmp_value = tmp_value * 10 + (*p - 0x30); - } - else - { - tmp_value += (*p - 0x30) * pow(10, float_flag); - float_flag--; - } - } - else - { - return 1; - } - p++; - } - return 2; -} - -/************************************************************** - *函数名称:OscGetValue - *简 介:从字符串中获取指定参数数值 - *输 入:p:字符串,以'\0'结尾,否则将出错 - * name:指定参数名称,如"c12"获取第1组第2个参数; - * value:用于获取输出值; - *输 出:(==0)转成功;(!=0)转失败 - *注意事项:虚拟示波器调参用,字符串中以'\0'为结束符 - **************************************************************/ -char XHZS_OscGetValue(const char *p, const char *name, float *value) -{ - // c11:114,c12:109,c13:434,c14:32, - float tmp_value; - int feedback; - p = strstr(p, name); - if (p == NULL) - { - return 1; - } - p += 4; - feedback = XHZS_OscGetFloat(p, &tmp_value); - if (feedback == 0) - { - *value = tmp_value; - return 0; - } - return 2; -} -/************************************************************** - *函数名称:XHZS_ReceiveData - *简 介:读取接收到的蓝牙数据 - *输 入:无 - *输 出:char *data type - *注意事项:接收数据的缓冲区大小为120字节 - **************************************************************/ -char *XHZS_ReceiveData() -{ - return receivedBuffer; -} - -// /************************************************************** -// *函数名称:SendWave -// *简 介:发送数据到学会助手APP虚拟示波器 -// *输 入:无 -// *输 出:无 -// *注意事项:将要发送的数据赋值给Wave数组即可,通道依次对应 -// **************************************************************/ -void SendWave() -{ - // 输出平行线测试 start ----------------------- - int32_t line[4] = {0}; // 注意数据类型;数组大小即为通道数量,最多四条通道 - for (size_t i = 0; i < 500; i += 0.1) - { - line[0] = (line[0] > 10 ? -10 : (line[0] += 1)); - line[1] = 10.0; - line[2] = 5.0; - line[3] = 0.0; - - XHZS_SendWave(line, sizeof(line)); - vTaskDelay(50 / portTICK_PERIOD_MS); // 延时 100ms - } - // 输出平行线测试 end ----------------------- - - // // 正弦波测试 start ----------------------- - // float Wave[4] = {0}; // 注意数据类型;数组大小即为通道数量,最多四条通道 - - // for (float i = 0; i < 500; i += 0.1) - // { - // Wave[0] = sin(i); - // Wave[1] = cos(i); - // Wave[2] = -sin(i); - // Wave[3] = -cos(i); - // XHZS_SendWave(Wave, sizeof(Wave)); - - // vTaskDelay(50 / portTICK_PERIOD_MS); - // } - // // 正弦波测试 end ----------------------- -} - -// 串口输入和输出案例 -void test_serial_port_sending_and_receiving() -{ - vTaskDelay(300 / portTICK_PERIOD_MS); // 延时函数100ms,相当于 delay(100); 效果一样, 相当于刷新 - // 假设手机端的学会助手串口发送:hello - char *receiveData = XHZS_ReceiveData(); // 获取蓝牙发送过来的数据 - - // // Case one start - XHZS_SendByte((uint8_t *)receiveData); // 向手机串口发送数据,接收到:h - XHZS_SendArray((uint8_t *)receiveData, strlen(receiveData)); // 向手机串口发送数据,接收到:hello - // // Case one end - - // case two start - // Serial.printf("Computer:%s\r\n", receiveData); // 向电脑发送数据,接收到: hello - // SerialBT.printf("mobile phone:%s\r\n", receiveData); // 向手机串口发送数据,接收到:hello - // case two end -} -// 输出指定的数据类型案例 -void test_type_of_output() -{ - SendWave(); -} - -// 示波器输入和输出案例 -void test_oscilloscope_input_and_output() -{ - float floatValue1, floatValue2, floatValue3, floatValue4; // 准备数据类型 - char *charData = getReceivedBluetoothData(); // 获取蓝牙接收的数据 - - // 将字符串中的字段的数值提取出来 - // c11:14.12,c12:22,c13:33,c14: 55.66, - // c13字段,数值为33 - XHZS_OscGetValue(charData, "c11", &floatValue1); - XHZS_OscGetValue(charData, "c12", &floatValue2); - XHZS_OscGetValue(charData, "c13", &floatValue3); - XHZS_OscGetValue(charData, "c14", &floatValue4); - - SerialBT.printf("w:%0.2f,%0.2f,%0.2f,%0.2f\r\n", floatValue1, floatValue2, floatValue3, floatValue4); - vTaskDelay(50 / portTICK_PERIOD_MS); // 延时函数100ms,相当于 delay(100); 效果一样, 相当于刷新 -} diff --git a/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.h b/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.h deleted file mode 100644 index 91fdabdbb589a643bac4f20b693bcf9e4017b6fb..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/lib/myBlueTooth/myBlueTooth.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * myBlueTooth.cpp + myBlueTooth.h - * 功能:对ESP32经典蓝牙的简单封装,工作在从机模式,基于单字节蓝牙发送定义了浮点数、字符串等发送函数 - * 说明:接收蓝牙数据时通过中断接收,直接调用相应接口就能读取 - */ -#ifndef MYBLUETOOTH_H_ -#define MYBLUETOOTH_H_ - -#include -#include -#include - - -// 对蓝牙进行封装 start ------------------------- - -// 初始化蓝牙设备并设置设备名称 -void initializeBluetooth(const String &deviceName = "mini_bot"); - -// 将浮点数转换为字符串并通过蓝牙发送 -void sendFloatViaBluetooth(const float data); - -// 通过蓝牙发送字符串 -void sendStringViaBluetooth(const char *stringData); - -// 获取通过蓝牙接收的字符串数据 -char *getReceivedBluetoothData(); - -// 对蓝牙进行封装 end ------------------------- -// 学会助手移植部分 start ------------------------- - -// 发送单个字节数据 -bool XHZS_SendByte(const uint8_t *byte); - -// 发送数组数据 -bool XHZS_SendArray(const uint8_t *array, size_t arraySize); - -// 此函数用于向示波器发送波形数据 -// 它作为一个模板,演示了如何正确地输出波形 -// 用户应根据所需的具体波形类型调整函数内部的逻辑 -void SendWave(); - -// 发送一组数据,包括帧头、内容和帧尾 -void XHZS_SendWave(const void *waveAddr, uint16_t waveSize); - -// 从字符串中解析并获取浮点数 -char XHZS_OscGetFloat(const char *p, float *value); - -// 根据名称从字符串中提取并获取值 -char XHZS_OscGetValue(const char *p, const char *name, float *value); - -// 读取接收到的蓝牙数据 -char *XHZS_ReceiveData(); - -// 学会助手移植部分 end ------------------------- -// 学会助手,函数使用示范 start --------------------- - -void test_serial_port_sending_and_receiving(); // 串口输入和输出案例 - -void test_type_of_output(); // 输出指定的数据类型案例 - -void test_oscilloscope_input_and_output(); // 示波器输入和输出案例 - -// 学会助手,函数使用示范 end --------------------- - -#endif /* MYBLUETOOTH_H_ */ diff --git a/platfromIO_ESP32_oscilloscope/partitions.csv b/platfromIO_ESP32_oscilloscope/partitions.csv deleted file mode 100644 index 39995d8e068cf79cc6ac619f86d8c003434c8af9..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/partitions.csv +++ /dev/null @@ -1,6 +0,0 @@ -# Name, Type, SubType, Offset, Size, Flags -nvs, data, nvs, 0x9000, 0x6000, -phy_init, data, phy, 0xf000, 0x1000, -factory, app, factory, 0x10000, 0x300000, -spiffs, data, spiffs, 0x310000, 0x30000, -coredump, data, coredump, 0x340000, 0xc0000, diff --git a/platfromIO_ESP32_oscilloscope/platformio.ini b/platfromIO_ESP32_oscilloscope/platformio.ini deleted file mode 100644 index 7e9a2ad9f7485cdd8eb7fd4ea9d24b003aabb72d..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/platformio.ini +++ /dev/null @@ -1,15 +0,0 @@ -; PlatformIO Project Configuration File -; -; Build options: build flags, source filter -; Upload options: custom upload port, speed and extra flags -; Library options: dependencies, extra library storages -; Advanced options: extra scripting -; -; Please visit documentation for the other options and examples -; https://docs.platformio.org/page/projectconf.html - -[env:esp-wrover-kit] -platform = espressif32 -board = esp-wrover-kit -framework = arduino -board_build.partitions = partitions.csv diff --git a/platfromIO_ESP32_oscilloscope/src/main.cpp b/platfromIO_ESP32_oscilloscope/src/main.cpp deleted file mode 100644 index 3fe13c7cf82c4501e84673d409dd23374017a931..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/src/main.cpp +++ /dev/null @@ -1,24 +0,0 @@ -// -// select engineering environment: ESP32_WROVER_Kit(all_versions) -// 想使用“学会助手”功能,查看 myBlueTooth.h 头文件里面有相关说明 -// 学会助手的串口和示波器,可以使用 ^_^ -// -#include -#include "myBlueTooth.h" - -BluetoothSerial SerialBlueTooth; // 实例化蓝牙串口 -void setup() -{ - initializeBluetooth(); // 默认蓝牙名称:mini_bot - Serial.begin(115200); // 开启串口通信,频率为:115200 -} -void loop() -{ - // test_serial_port_sending_and_receiving(); // 串口发送和接收案例 - - test_type_of_output(); - - // test_oscilloscope_input_and_output(); -} - - diff --git a/platfromIO_ESP32_oscilloscope/test/README b/platfromIO_ESP32_oscilloscope/test/README deleted file mode 100644 index 9b1e87bc67c90e7f09a92a3e855444b085c655a6..0000000000000000000000000000000000000000 --- a/platfromIO_ESP32_oscilloscope/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PlatformIO Test Runner and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PlatformIO Unit Testing: -- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html