Skip to content

Commit

Permalink
Format Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyu-Zhao committed Jul 8, 2022
1 parent 693cb4d commit 8fc1c98
Show file tree
Hide file tree
Showing 266 changed files with 71,937 additions and 64,848 deletions.
127 changes: 66 additions & 61 deletions examples/Advanced/EzData/EzData.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,84 +3,89 @@
* Copyright (c) 2021 by M5Stack
* Equipped with M5StickC-Plus sample source code
* 配套 M5StickC-Plus 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/core/m5stickc_plus
* 获取更多资料请访问https://docs.m5stack.com/zh_CN/core/m5stickc_plus
* Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus
*
* describe:EzData
* date:2021/10/23
* Describe: EzData
* Date: 2021/10/23
*******************************************************************************
*/
#include "M5StickCPlus.h"
#include "M5_EzData.h"

// Configure the name and password of the connected wifi and your token. 配置所连接wifi的名称、密码以及你的token
const char* ssid = "Explore-F";
// Configure the name and password of the connected wifi and your token.
// 配置所连接wifi的名称、密码以及你的token
const char* ssid = "Explore-F";
const char* password = "xingchentansuo123";
const char* token = "";
const char* token = "";

void setup() {
M5.begin(); //Initialize M5Stack
M5.Lcd.setRotation(3);
if(setupWifi(ssid,password)){ //Connect to wifi. 连接到wifi
M5.Lcd.printf("Success connecting to %s\n",ssid);
}else{
M5.Lcd.printf("Connecting to %s failed\n",ssid);
}
M5.begin(); // Initialize M5Stack
M5.Lcd.setRotation(3);
if (setupWifi(ssid, password)) { // Connect to wifi. 连接到wifi
M5.Lcd.printf("Success connecting to %s\n", ssid);
} else {
M5.Lcd.printf("Connecting to %s failed\n", ssid);
}
}

void loop() {
//Save the data 20 to the top of the testData topic queue. 保存数据20至 testData 队列首位
if(setData(token,"testData",20)){
M5.Lcd.printf("Success sending data to the topic\n");
}else{
M5.Lcd.print("Fail to save data\n");
}
delay(5000);
// Save the data 20 to the top of the testData topic queue. 保存数据20至
// testData 队列首位
if (setData(token, "testData", 20)) {
M5.Lcd.printf("Success sending data to the topic\n");
} else {
M5.Lcd.print("Fail to save data\n");
}
delay(5000);

//Save 3 data in sequence to the first place of testList. 依次保存3个数据至 testList首位
for(int i=0;i<3;i++){
if(addToList(token,"testList",i)){
M5.Lcd.printf("Success sending %d to the list\n",i);
}else{
M5.Lcd.print("Fail to save data\n");
// Save 3 data in sequence to the first place of testList. 依次保存3个数据至
// testList首位
for (int i = 0; i < 3; i++) {
if (addToList(token, "testList", i)) {
M5.Lcd.printf("Success sending %d to the list\n", i);
} else {
M5.Lcd.print("Fail to save data\n");
}
delay(100);
}
delay(100);
}
delay(5000);
delay(5000);

//Get a piece of data from a topic and store the value in result. 从一个 topic中获取一个数据,并将值存储在 result
int result=0;
if(getData(token,"testData",result)){
M5.Lcd.printf("Success get data %d\n",result);
}else{
M5.Lcd.print("Fail to get data\n");
}
delay(5000);
// Get a piece of data from a topic and store the value in result. 从一个
// topic中获取一个数据,并将值存储在 result
int result = 0;
if (getData(token, "testData", result)) {
M5.Lcd.printf("Success get data %d\n", result);
} else {
M5.Lcd.print("Fail to get data\n");
}
delay(5000);

//Get a set of data from a list and store the values in the Array array. 从一个 list中获取一组数据,并将值存储在 Array数组中
int Array[3]={};
if(getData(token,"testList",Array,0,3)){
M5.Lcd.print("Success get list\n");
for(int i=0;i<3;i++){
M5.Lcd.printf("Array[%d]=%d,",i,Array[i]);
// Get a set of data from a list and store the values in the Array array.
// 从一个 list中获取一组数据,并将值存储在 Array数组中
int Array[3] = {};
if (getData(token, "testList", Array, 0, 3)) {
M5.Lcd.print("Success get list\n");
for (int i = 0; i < 3; i++) {
M5.Lcd.printf("Array[%d]=%d,", i, Array[i]);
}
M5.Lcd.println("");
} else {
M5.Lcd.println("Fail to get data");
}
M5.Lcd.println("");
}else{
M5.Lcd.println("Fail to get data");
}
delay(5000);
delay(5000);

//Remove data
if(removeData(token,"testData"))
M5.Lcd.printf("Success remove data\n");
else
M5.Lcd.println("Fail to remove data");
// Remove data
if (removeData(token, "testData"))
M5.Lcd.printf("Success remove data\n");
else
M5.Lcd.println("Fail to remove data");

if(removeData(token,"testList"))
M5.Lcd.printf("Success remove data from the list\n");
else
M5.Lcd.println("Fail to remove data");
delay(5000);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0,0);
if (removeData(token, "testList"))
M5.Lcd.printf("Success remove data from the list\n");
else
M5.Lcd.println("Fail to remove data");
delay(5000);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setCursor(0, 0);
}
111 changes: 59 additions & 52 deletions examples/Advanced/HallSensor/HallSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Copyright (c) 2021 by M5Stack
* Equipped with M5StickC-Plus sample source code
* 配套 M5StickC-Plus 示例源代码
* Visit the website for more informationhttps://docs.m5stack.com/en/core/m5stickc_plus
* 获取更多资料请访问https://docs.m5stack.com/zh_CN/core/m5stickc_plus
* Visit for more information: https://docs.m5stack.com/en/core/m5stickc_plus
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/core/m5stickc_plus
*
* describe:Hall sensor. 霍尔传感器
* date:2021/9/18
* Describe: Hall sensor. 霍尔传感器
* Date: 2021/9/18
*******************************************************************************
The ESP32 MCU has build in Hall sensor. ESP32 MCU内置霍尔传感器
It is not very suscescible but if you bring a magnet close to the
Expand All @@ -17,69 +17,76 @@
#include <M5StickCPlus.h>

#define HORIZONTAL_RESOLUTION 135 //屏幕水平分辨率
#define VERTICAL_RESOLUTION 240 //屏幕竖直分辨率
#define VERTICAL_RESOLUTION 240 //屏幕竖直分辨率
#define POSITION_OFFSET_Y 20

uint16_t oldSignal[HORIZONTAL_RESOLUTION];

float ESP32_hallRead() //ESP32 hall value read. ESP32霍尔值读取
float ESP32_hallRead() // ESP32 hall value read. ESP32霍尔值读取
{
float value = 0;
int count = 400;
// mean value filter. 数据低通滤波器
for (int n = 0; n < count; n++) value += hallRead();
return value / count * 10;
float value = 0;
int count = 400;
// mean value filter. 数据低通滤波器
for (int n = 0; n < count; n++) value += hallRead();
return value / count * 10;
}

float HallOffset = 0; ////Store the initial value of magnetic force. 存储磁力的初值
float HallOffset =
0; ////Store the initial value of magnetic force. 存储磁力的初值

void setup()
{
M5.begin();
M5.Lcd.printf("\nESP32 Hall sensor:"); //Screen printout. 屏幕打印输出
HallOffset = ESP32_hallRead(); // callibrate the output value to the magnetic field at start up. 在启动时将输出值校准到磁场
void setup() {
M5.begin();
M5.Lcd.printf("\nESP32 Hall sensor:"); // Screen printout. 屏幕打印输出
HallOffset =
ESP32_hallRead(); // callibrate the output value to the magnetic field
// at start up. 在启动时将输出值校准到磁场
}

float LowPassFilteredValue=0;
void showSignal()
{
int n;
float LowPassFilteredValue = 0;
void showSignal() {
int n;

int oldx;
int oldy;
int oldSig;
int x, y;
int oldx;
int oldy;
int oldSig;
int x, y;

for (n = 0; n < HORIZONTAL_RESOLUTION; n++) //在水平分辨率内,每个像素点根据计算得到的磁力大小绘制
{ //Within the horizontal resolution, each pixel is drawn according to the calculated magnetic force
x = n;
float value = ESP32_hallRead()- HallOffset; //Reduce the influence of own magnetism. 减少自身磁力的影响
LowPassFilteredValue+=(value-LowPassFilteredValue)*0.05;
M5.Lcd.setCursor(50, 30);
M5.Lcd.print((int)LowPassFilteredValue);
M5.Lcd.print(" ");
M5.Lcd.setCursor(0, 40);
y = map(value , -127, 127, VERTICAL_RESOLUTION, POSITION_OFFSET_Y); //将value映射至-30~30的范围内,以免绘制超出屏幕
for (n = 0; n < HORIZONTAL_RESOLUTION;
n++) //在水平分辨率内,每个像素点根据计算得到的磁力大小绘制
{ // Within the horizontal resolution, each pixel is drawn according to the
// calculated magnetic force
x = n;
float value =
ESP32_hallRead() - HallOffset; // Reduce the influence of own
// magnetism. 减少自身磁力的影响
LowPassFilteredValue += (value - LowPassFilteredValue) * 0.05;
M5.Lcd.setCursor(50, 30);
M5.Lcd.print((int)LowPassFilteredValue);
M5.Lcd.print(" ");
M5.Lcd.setCursor(0, 40);
y = map(
value, -127, 127, VERTICAL_RESOLUTION,
POSITION_OFFSET_Y); //将value映射至-30~30的范围内,以免绘制超出屏幕

if (n > 0)
{
// delete old line element. 删除上次画的线
M5.Lcd.drawLine(oldx , oldSig, x, oldSignal[n], BLACK );
if (n > 0) {
// delete old line element. 删除上次画的线
M5.Lcd.drawLine(oldx, oldSig, x, oldSignal[n], BLACK);

// draw new line element. 画新的线
if (n < HORIZONTAL_RESOLUTION - 1) // don't draw last element because it would generate artifacts. 不能绘制最后一个像素
{
M5.Lcd.drawLine(oldx,oldy,x,y, GREEN);
}
// draw new line element. 画新的线
if (n < HORIZONTAL_RESOLUTION -
1) // don't draw last element because it would generate
// artifacts. 不能绘制最后一个像素
{
M5.Lcd.drawLine(oldx, oldy, x, y, GREEN);
}
}
oldx = x;
oldy = y;
oldSig = oldSignal[n];
oldSignal[n] = y;
}
oldx = x;
oldy = y;
oldSig = oldSignal[n];
oldSignal[n] = y;
}
}

void loop(void)
{
showSignal();
void loop(void) {
showSignal();
}
Loading

0 comments on commit 8fc1c98

Please sign in to comment.