diff --git a/main/remotedisplaywebsocket.h b/main/remotedisplaywebsocket.h index cdb1038..238978e 100644 --- a/main/remotedisplaywebsocket.h +++ b/main/remotedisplaywebsocket.h @@ -14,11 +14,9 @@ #define RDWS_TAG "remotedisplay" -namespace remotedisplay -{ +namespace remotedisplay { -namespace -{ +namespace { enum class msg_type : uint8_t { @@ -145,10 +143,10 @@ void drawGenericString(msg_type type, std::string_view string, int32_t x, int32_ return; } - drawString_msg dcstr = { (int16_t)x, (int16_t)y, font }; + drawString_msg dcstr = { static_cast(x), static_cast(y), font }; std::string buf; emitMessageHeader(buf, msg_type::drawCentreString); - buf += std::string_view((char *)&dcstr, sizeof(dcstr)); + buf += std::string_view(reinterpret_cast(&dcstr), sizeof(dcstr)); buf += (char)string.length(); buf += string; @@ -164,52 +162,52 @@ void drawCentreString(std::string_view string, int32_t x, int32_t y, uint8_t fon void drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size) { - drawChar_msg dc = { (int16_t)x, (int16_t)y, (uint16_t)c, color, bg, size }; - sendDrawMsg(msg_type::drawChar, std::string_view((char *)&dc, sizeof(dc))); + drawChar_msg dc = { static_cast(x), static_cast(y), static_cast(c), color, bg, size }; + sendDrawMsg(msg_type::drawChar, std::string_view(reinterpret_cast(&dc), sizeof(dc))); } void drawCircle(int32_t x, int32_t y, int32_t r, uint32_t color) { - drawCircle_msg dcirc = { (int16_t)x, (int16_t)y, (int16_t)r, (uint16_t)color }; - sendDrawMsg(msg_type::drawCircle, std::string_view((char *)&dcirc, sizeof(dcirc))); + drawCircle_msg dcirc = { static_cast(x), static_cast(y), static_cast(r), static_cast(color) }; + sendDrawMsg(msg_type::drawCircle, std::string_view(reinterpret_cast(&dcirc), sizeof(dcirc))); } void drawEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { - drawEllipse_msg dellip = { (int16_t)x, (int16_t)y, (int16_t)rx, (int16_t)ry, color }; - sendDrawMsg(msg_type::drawEllipse, std::string_view((char *)&dellip, sizeof(dellip))); + drawEllipse_msg dellip = { static_cast(x), static_cast(y), static_cast(rx), static_cast(ry), color }; + sendDrawMsg(msg_type::drawEllipse, std::string_view(reinterpret_cast(&dellip), sizeof(dellip))); } void drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color) { - drawHVLine_msg dhl = { (int16_t)x, (int16_t)y, (int16_t)w, color }; - sendDrawMsg(msg_type::drawHLine, std::string_view((char *)&dhl, sizeof(dhl))); + drawHVLine_msg dhl = { static_cast(x), static_cast(y), static_cast(w), color }; + sendDrawMsg(msg_type::drawHLine, std::string_view(reinterpret_cast(&dhl), sizeof(dhl))); } void drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color) { - drawHVLine_msg dvl = { (int16_t)x, (int16_t)y, (int16_t)h, color }; - sendDrawMsg(msg_type::drawVLine, std::string_view((char *)&dvl, sizeof(dvl))); + drawHVLine_msg dvl = { static_cast(x), static_cast(y), static_cast(h), color }; + sendDrawMsg(msg_type::drawVLine, std::string_view(reinterpret_cast(&dvl), sizeof(dvl))); } void drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color) { - drawLine_msg dl = { (int16_t)xs, (int16_t)ys, (int16_t)xe, (int16_t)ye, color }; - sendDrawMsg(msg_type::drawLine, std::string_view((char *)&dl, sizeof(dl))); + drawLine_msg dl = { static_cast(xs), static_cast(ys), static_cast(xe), static_cast(ye), color }; + sendDrawMsg(msg_type::drawLine, std::string_view(reinterpret_cast(&dl), sizeof(dl))); } void drawPixel(int32_t x, int32_t y, uint16_t color) { - return; // wont support - drawPixel_msg dp = { (int16_t)x, (int16_t)y, color }; - sendDrawMsg(msg_type::drawPixel, std::string_view((char *)&dp, sizeof(dp))); + return; // won't support + drawPixel_msg dp = { static_cast(x), static_cast(y), color }; + sendDrawMsg(msg_type::drawPixel, std::string_view(reinterpret_cast(&dp), sizeof(dp))); } void drawRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color) { // same parameters as fillRect -> can use same struct - drawRect_msg dr = { (int16_t)x, (int16_t)y, (int16_t)w, (int16_t)h, (uint16_t)color }; - sendDrawMsg(msg_type::drawRect, std::string_view((char *)&dr, sizeof(dr))); + drawRect_msg dr = { static_cast(x), static_cast(y), static_cast(w), static_cast(h), static_cast(color) }; + sendDrawMsg(msg_type::drawRect, std::string_view(reinterpret_cast(&dr), sizeof(dr))); } void drawRightString(std::string_view string, int32_t x, int32_t y, uint8_t font) @@ -220,10 +218,10 @@ void drawRightString(std::string_view string, int32_t x, int32_t y, uint8_t font void drawRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) { drawRoundRect_msg drr = { - (int16_t)x, (int16_t)y, (int16_t)w, (int16_t)h, - (int16_t)radius, (uint16_t)color + static_cast(x), static_cast(y), static_cast(w), static_cast(h), + static_cast(radius), static_cast(color) }; - sendDrawMsg(msg_type::drawRoundRect, std::string_view((char *)&drr, sizeof(drr))); + sendDrawMsg(msg_type::drawRoundRect, std::string_view(reinterpret_cast(&drr), sizeof(drr))); } void drawString(std::string_view string, int32_t poX, int32_t poY, uint8_t font) @@ -234,62 +232,62 @@ void drawString(std::string_view string, int32_t poX, int32_t poY, uint8_t font) void drawSunkenRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color0, uint32_t color1, uint32_t color2) { drawSunkenRect_msg dsr = { - (int16_t)x, (int16_t)y, (int16_t)w, (int16_t)h, - (uint16_t)color0, (uint16_t)color1, (uint16_t)color2 + static_cast(x), static_cast(y), static_cast(w), static_cast(h), + static_cast(color0), static_cast(color1), static_cast(color2) }; - sendDrawMsg(msg_type::drawSunkenRect, std::string_view((char *)&dsr, sizeof(dsr))); + sendDrawMsg(msg_type::drawSunkenRect, std::string_view(reinterpret_cast(&dsr), sizeof(dsr))); } void drawTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) { drawTriangle_msg dt = { - (int16_t)x1, (int16_t)y1, (int16_t)x2, (int16_t)y2, (int16_t)x3, (int16_t)y3, - (uint16_t)color + static_cast(x1), static_cast(y1), static_cast(x2), static_cast(y2), static_cast(x3), static_cast(y3), + static_cast(color) }; - sendDrawMsg(msg_type::drawTriangle, std::string_view((char *)&dt, sizeof(dt))); + sendDrawMsg(msg_type::drawTriangle, std::string_view(reinterpret_cast(&dt), sizeof(dt))); } void fillCircle(int32_t x, int32_t y, int32_t r, uint32_t color) { - drawCircle_msg fcirc = { (int16_t)x, (int16_t)y, (int16_t)r, (uint16_t) color }; - sendDrawMsg(msg_type::fillCircle, std::string_view((char *)&fcirc, sizeof(fcirc))); + drawCircle_msg fcirc = { static_cast(x), static_cast(y), static_cast(r), static_cast(color) }; + sendDrawMsg(msg_type::fillCircle, std::string_view(reinterpret_cast(&fcirc), sizeof(fcirc))); } void fillEllipse(int16_t x, int16_t y, int32_t rx, int32_t ry, uint16_t color) { - drawEllipse_msg fellip = { (int16_t)x, (int16_t)y, (int16_t)rx, (int16_t)ry, (uint16_t) color }; - sendDrawMsg(msg_type::fillEllipse, std::string_view((char *)&fellip, sizeof(fellip))); + drawEllipse_msg fellip = { static_cast(x), static_cast(y), static_cast(rx), static_cast(ry), static_cast(color) }; + sendDrawMsg(msg_type::fillEllipse, std::string_view(reinterpret_cast(&fellip), sizeof(fellip))); } void fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color) { - drawRect_msg fr = { (int16_t)x, (int16_t)y, (int16_t)w, (int16_t)h, color }; - sendDrawMsg(msg_type::fillRect, std::string_view((char *)&fr, sizeof(fr))); + drawRect_msg fr = { static_cast(x), static_cast(y), static_cast(w), static_cast(h), color }; + sendDrawMsg(msg_type::fillRect, std::string_view(reinterpret_cast(&fr), sizeof(fr))); } void fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color) { drawRoundRect_msg frr = { - (int16_t)x, (int16_t)y, (int16_t)w, (int16_t)h, - (int16_t)radius, (uint16_t)color + static_cast(x), static_cast(y), static_cast(w), static_cast(h), + static_cast(radius), static_cast(color) }; - sendDrawMsg(msg_type::fillRoundRect, std::string_view((char *)&frr, sizeof(frr))); + sendDrawMsg(msg_type::fillRoundRect, std::string_view(reinterpret_cast(&frr), sizeof(frr))); } void fillScreen(uint32_t color) { - uint16_t fs = (uint16_t)color; - sendDrawMsg(msg_type::fillScreen, std::string_view((char *)&fs, sizeof(fs))); + auto fs = static_cast(color); + sendDrawMsg(msg_type::fillScreen, std::string_view(reinterpret_cast(&fs), sizeof(fs))); } void fillTriangle(int32_t x1,int32_t y1, int32_t x2,int32_t y2, int32_t x3,int32_t y3, uint32_t color) { drawTriangle_msg ft = { - (int16_t)x1, (int16_t)y1, (int16_t)x2, (int16_t)y2, (int16_t)x3, (int16_t)y3, - (uint16_t)color + static_cast(x1), static_cast(y1), static_cast(x2), static_cast(y2), static_cast(x3), static_cast(y3), + static_cast(color) }; - sendDrawMsg(msg_type::fillTriangle, std::string_view((char *)&ft, sizeof(ft))); + sendDrawMsg(msg_type::fillTriangle, std::string_view(reinterpret_cast(&ft), sizeof(ft))); } } // namespace remotedisplay