【开源项目学习】esp8266点阵时钟函数分析

文件名称

简介

主要函数
esp8266-lattice-clock-awtirx.ino

handleUdpData()//处理接收到的UDP数据

showTimeCallback()//显示时间回调函数

showTime(uint8_t showmode)//显示时间

handlePower()

setup()

loop()

BlinkerSupport.h 点灯科技相关的东西

directionCallback(const String &state)

brightCallback(int32_t value)

powerCallback(int32_t value)

miotPowerState(const String &state)

miotBright(const String &bright)

miotQuery(int32_t queryCode)

initBlinker()

ConfigWifiHtml.h 配网HTML
DateTimes.cpp/.h

DateTimes::getTimes()//获取时间信息

DateTimes::getDates()//获取日期信息

DateTimes::getTemperature()//获取温度信息

DateTimes::setDateTimes(long timestamp)//时钟芯片和系统时间设置时间信息

DateTimes::getTimestamp()//获取时间戳信息

DateTimes::timestampAdd()//系统时间每秒++

DateTimes::saveCountdownTimestamp(long timestamp)//保存倒计时时间戳信息

DateTimes::getCountdownTimestamp()//获取倒计时时间戳信息

EEPROMTool.h

static EEPROMTOOLS EEPROMTool;

定义在结构体中了这些函数。

saveData(uint8_t *data, int offset, int length)

saveDataOne(uint8_t data, int offset)

*loadData(int offset, int length)//EEPROM获取数据

loadDataOne(int offset)

clearData(int offset, int length)

clearAll()

*backupAll()

restoreAll(uint8_t *arr)

Functions.cpp/.h 功能??

Functions::Functions()

Functions::Functions(PilotLight *pilotLightobj)

Functions::reset()//重置功能和模式

Functions::setPowerAndMode(unsigned char power, unsigned char mode)//设置功能和模式

Functions::setPower(unsigned char power)//设置功能

Functions::setMode(unsigned char mode)//设置当前模式

Functions::powerUp()//功能增加(功能切换)

Functions::powerDown()//功能减少,未定义

Functions::modeUp()//模式加

Functions::modeDown()//模式减,未定义

Functions::getCurrPower()//获取当前功能

Functions::getCurrMode()//获取当前模式

HttpTool.cpp/.h

bilibili获取粉丝数量

这里是作者自己写的服务器获取的

HttpTool::bilibiliFans()//刷新bilibili粉丝

HttpTool::saveBuid(long uid)//保存UID到EEPROM

HttpTool::loadBuid()//从EEPROM中加载bilibili的UID

HttpTool::updateBilibiliFlag()//使更新flag为TRUE

Lattice.cpp/.h 显示

Lattice::init()//初始化

Lattice::shutdown(bool down)//是否启用点阵屏幕

Lattice::setBrightness(uint8_t bright, bool save)//设置亮度

Lattice::setDirection(bool direct)//切换显示方向

Lattice::reset()//

Lattice::initLattice()//初始化实际显示数组

Lattice::refreshLed()//刷新LED显示

Lattice::showDataLed(const unsigned char (*arr)[rowLength])//

Lattice::reversalLR(uint8_t index)//左右翻转(图案左右对称)

Lattice::reversalUD(uint8_t index)//上下翻转(图案上下对称)

Lattice::progressBar(uint8_t offset)//显示底部进度条

Lattice::upOrDownMove(uint8_t index, uint8_t region, bool direction)//向下移动缓冲数据

*Lattice::getNumData(uint8_t number, bool showzero)//得到要显示的数字

*Lattice::getBigNumData(uint8_t number, uint8_t offset)

Lattice::offsetBuff(uint8_t index, int8_t offset)//数据位移?

Lattice::offsetData(uint8_t index, int8_t offset)//数据移位

Lattice::showLongIcon(uint8_t index)//显示图案??

Lattice::showNum(uint8_t index, int nums)

Lattice::rightMoveData(bool isright)//Move

Lattice::rightMoveBuff()//Move

Lattice::downMoveData(bool isdown)//Move

Lattice::downMoveBuff()//Move

Lattice::downMoveBuff(uint8_t *arr)//Move

Lattice::showTime(uint8_t *arr, void (*callback)())//显示时间1

Lattice::showTime2(uint8_t *arr, void (*callback)())//显示时间2

Lattice::showTime3(uint8_t *arr, void (*callback)())//显示时间3

Lattice::showCountDownTime(long remain, uint8_t *arr, bool showmode, bool minutechange)//显示倒计时

Lattice::showLongNumber(uint8_t *arr)//显示一个长的数

Lattice::showNumAndIcon(uint8_t no, uint8_t *arr)//显示图标+粉丝数

Lattice::showDate2(uint8_t *arr)//显示日期2

Lattice::showDate3(uint8_t *arr)//显示日期3

Lattice::showTemperature(uint8_t *arr)//显示温度

Lattice::showUserData(uint8_t mode)//显示用户自定义数据

Lattice::clearShow()//清空显示?

Lattice::showFull()//全部显示?

Lattice::lightning(uint8_t index)//bilibili眼睛闪烁

Lattice::showOtaUpdate(uint8_t num)

Main.h 头文件引用,对象定义

initStatus()//初始化状态

singleAClickHandler()//A按键单击

singleBClickHandler()//B按键单机

doubleAClickHandler()//A按键双击

longAClickStartHandler()//???????不理解

longAClickHandler()//A按键长按

initTouch()//初始化按键信息

subBili(uint8_t *data)//订阅bilibili用户ID

setCountdown(uint8_t *data)//设置倒计时信息

initSleepTime()//初始化休眠时间

setSleepTime(uint8_t *data)//设置睡眠时间

sleepTimeLoop()//睡眠

resetTime(uint8_t *data)//重置时间

setUserData(uint8_t *data)//设置用户数据

showCountDown()//显示倒计时

showDate(uint8_t showmode)//显示日期

showTemperature()//显示温度

showBiliFans()//显示bilibili粉丝数

showUserData(uint8_t showmode)//显示用户自定义数据

touchLoop()//按键中断处理

Ota.cpp/.h OTA   

Otas::Otas()

Otas::Otas(Lattice *latticeobj, PilotLight *pilotLightobj)

Otas::flashing()

Otas::showLongIcon(int type)

Otas::showOtaUpdate(int process)

Otas::reset()

Otas::update_started()

Otas::update_finished()

Otas::update_progress(long cur, long total)

Otas::update_error(int err)

Otas::updateOta(int version)//OTA升级

PilotLight.cpp/.h 指示灯

PilotLight::PilotLight()

PilotLight::flashing()//闪烁LED

PilotLight::flashing(int ms)//闪烁LED

PilotLight::bright()//亮

PilotLight::dim()//灭

System.cpp/.h

System::System()

System::reset_system()//重置系统

System::uint8t_to_long(uint8_t *data, int length)//类型转换

System::delay_time(int ms, void (*callback)())//重新定义延迟函数

Udps.cpp/.h UDP

Udps::Udps()

Udps::Udps(DateTimes *datetimesobj, Lattice *latticeobj, PilotLight *pilotLightobj)//构造函数

Udps::initudp()//初始化UDP客户端

Udps::sendNTPpacket()//发送NTP请求

Udps::getNtpTimestamp()//获取当前时间戳

Udpdata Udps::userLatticeLoop(uint8_t power, uint8_t mode, uint8_t version)//接收自定义UDP协议的数据

Udps::updateTime()//更新系统时间

wifis.cpp/.h WiFi

Wifis::Wifis()

Wifis::Wifis(Lattice *latticeobj, PilotLight *pilotLightobj)

Wifis::wifiloop()//轮询

Wifis::initWifi()//初始化

Wifis::handleIndex()//处理主页请求

Wifis::handleConfigWifi()//处理配网请求

Wifis::handleWifiList()//处理wifi扫描请求

Wifis::initWebServer()//初始化web服务

Wifis::connWifi()//连接wifi

Wifis::enableApMode()//进入热点模式

Wifis::isApMode()//是否未热点模式

EEPROM相关宏定义

EEPROM_BEGIN 1536 文件开始存储地址
EEPROM_LENGTH 50 长度
REMEMBER_WIFI 记住wifi内存地址
WIFI_MODE wifi模式内存地址
DIRECTION 屏幕显示方向内存地址
BRIGHTNESS 屏幕亮度内存地址
SLEEP_TIME 存睡眠时间相关(共5位)
BILIBILI_UID 存储bilibilii的UID(共5位)
COUNTDOWN_TIME 存储倒计时时间戳(共5位)
H12_ADDR 存放H12标记 \\\ 这里占位,暂无任何意义
ANNI_DAY 存放纪念日 月和 日 \\\ 这里占位,暂无任何意义
#define EEPROM_BEGIN 1536
#define EEPROM_LENGTH 50

enum EEPROM_ADDRESS_ENUM
{

  REMEMBER_WIFI = EEPROM_BEGIN + 1,   // 记住wifi内存地址
  WIFI_MODE = EEPROM_BEGIN + 2,       // wifi模式内存地址
  DIRECTION = EEPROM_BEGIN + 3,       // 屏幕显示方向内存地址
  BRIGHTNESS = EEPROM_BEGIN + 4,      // 屏幕亮度内存地址
  SLEEP_TIME = EEPROM_BEGIN + 5,      // 从第5位到第9位来存睡眠时间相关
  BILIBILI_UID = EEPROM_BEGIN + 10,   // 从10到14来存储bilibilii的UID
  COUNTDOWN_TIME = EEPROM_BEGIN + 15, // 从15到19来存储倒计时时间戳
  H12_ADDR = EEPROM_BEGIN + 20,       // 12位存放H12标记 \\\ 这里占位,暂无任何意义
  ANNI_DAY = EEPROM_BEGIN + 21        // 10,11存放纪念日 月和 日 \\\ 这里占位,暂无任何意义
};

DateTimes定义

static long currtimestamp 当前时间戳
struct Times
{
  uint8_t h;
  uint8_t m;
  uint8_t s;
};

struct Dates
{
  uint16_t y;
  uint8_t m;
  uint8_t d;
};


// 当前时间戳,冗余做法,即时钟芯片没有或者不生效时,使用系统的时间戳来反馈时间
static long currtimestamp = 0;

Functions功能相关定义

SHOW_TIME 显示时间
SHOW_DATE 显示日期
POWER2 显示日期
BILIFANS 显示bilibili粉丝数量
CUSTOM 显示用户自定义数据
COUNTDOWN 显示倒计时
RESETTIME NTP更新时间
RESET 系统重置
enum ModeEnum
{
    // 功能0: 显示时间
    SHOW_TIME = 0,
    // 功能1: 显示日期
    SHOW_DATE = 1,
    // 功能2: 显示日期
    POWER2 = 2,
    // 显示bilibili粉丝数量
    BILIFANS = 3,
    // 显示用户自定义数据
    CUSTOM = 4,
    // 显示倒计时
    COUNTDOWN = 5,
    // NTP更新时间
    RESETTIME = 98,
    // 系统重置
    RESET = 99
};

#define POWER_SIZE 6

const int modePower[POWER_SIZE] = {3, 3, 1, 1, 5, 1}; // 每个功能对应多少种模式

UDP相关

#define localPort 1234     // 监听本地UDP数据包端口
#define remoteNtpPort 123  // 远程服务端口
#define NTP_PACKET_SIZE 48 // NTP数据包数据长度

struct Udpdata
{
  uint8_t rt;       // 返回类型
  uint8_t te;       // 数据类型
  uint8_t lh;       // 数据长度
  uint8_t data[64]; // 数据包
};

Lattice

struct LatticeSetting
{
    // 点阵屏幕是否显示
    bool isShutdown = false;

    // 屏幕亮度
    uint8_t brightness = 0x0;

    // 显示方向, true: 正方向,false: 反方向
    bool direction = false;

    // 用户自定义数据
    uint8_t userData[32];

    // 速度
    uint8_t speed = 1;
};

LatticeSetting latticeSetting;
//Main.h
Lattice lattice = Lattice();                             // 点阵显示对象

猜你喜欢

转载自blog.csdn.net/qq_41650023/article/details/124640155