1 Star 0 Fork 1

DFRobot/DFRobot_Display

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DFRobot_Display_Clock.cpp 3.29 KB
一键复制 编辑 原始数据 按行查看 历史
wenyi 提交于 2018-04-20 15:02 +08:00 . fix bug and add lib clock
#include "DFRobot_Display_Clock.h"
DFRobot_Display_Clock::DFRobot_Display_Clock(DFRobot_Display* pDisplay)
{
_pDisplay = pDisplay;
_hourWidth = 1;
_minWidth = 1;
_secWidth = 1;
}
void DFRobot_Display_Clock::setClockDial(int16_t x, int16_t y, uint16_t r)
{
_x = x;
_y = y;
_r = r;
}
void DFRobot_Display_Clock::setPointerColor(uint16_t hc, uint16_t mc, uint16_t sc)
{
_hourColor = hc;
_minColor = mc;
_secColor = sc;
}
void DFRobot_Display_Clock::setPointerLength(uint16_t hl, uint16_t ml, uint16_t sl)
{
_hourLen = hl;
_minLen = ml;
_secLen = sl;
}
void DFRobot_Display_Clock::setDialColor(uint16_t border, uint16_t background)
{
_background = background;
_borderColor = border;
}
void DFRobot_Display_Clock::setPointerWidth(uint16_t hw, uint16_t mw, uint16_t sw)
{
_hourWidth = hw;
_minWidth = mw;
_secWidth = sw;
}
void DFRobot_Display_Clock::showDial()
{
uint16_t lastLineWidth = _pDisplay->getLineWidth();
_pDisplay->setLineWidth(1);
_pDisplay->fillCircle(_x, _y, _r, _background);
_pDisplay->drawCircle(_x, _y, _r, _borderColor);
_pDisplay->drawVLine(_x, _y - _r, _r / 8, _borderColor);
_pDisplay->drawHLine(_x + _r, _y, - _r / 8, _borderColor);
_pDisplay->drawVLine(_x, _y + _r, - _r / 8, _borderColor);
_pDisplay->drawHLine(_x - _r, _y, _r / 8, _borderColor);
int16_t x, y;
calcPointerPosition(5, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(10, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(20, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(25, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(35, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(40, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(50, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
calcPointerPosition(55, _r, &x, &y);
_pDisplay->drawLine(x * 7 / 8, y * 7 / 8, x, y, _borderColor);
_pDisplay->setLineWidth(lastLineWidth);
}
void DFRobot_Display_Clock::updateClock(uint8_t h, uint8_t m, uint8_t s)
{
uint16_t w = _pDisplay->getLineWidth();
_pDisplay->setLineWidth(_hourWidth);
_pDisplay->drawLine(_x, _y, _lastHourX, _lastHourY, _background);
calcPointerPositionHour(h, m, _hourLen, &_lastHourX, &_lastHourY);
_pDisplay->drawLine(_x, _y, _lastHourX, _lastHourY, _hourColor);
_DEBUG_CODE(
Serial.println();
Serial.print("hour pointer ");
Serial.print(_x);
Serial.print(" ");
Serial.print(_y);
Serial.print(" ");
Serial.print(_lastHourX);
Serial.print(" ");
Serial.print(_lastHourY);
Serial.println(" ");
);
_pDisplay->setLineWidth(_minWidth);
_pDisplay->drawLine(_x, _y, _lastMinX, _lastMinY, _background);
calcPointerPosition(m, _minLen, &_lastMinX, &_lastMinY);
_pDisplay->drawLine(_x, _y, _lastMinX, _lastMinY, _minColor);
_pDisplay->setLineWidth(_secWidth);
_pDisplay->drawLine(_x, _y, _lastSecX, _lastSecY, _background);
calcPointerPosition(s, _secLen, &_lastSecX, &_lastSecY);
_pDisplay->drawLine(_x, _y, _lastSecX, _lastSecY, _secColor);
_pDisplay->setLineWidth(w);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dfrobot/DFRobot_Display.git
git@gitee.com:dfrobot/DFRobot_Display.git
dfrobot
DFRobot_Display
DFRobot_Display
master

搜索帮助