Skip to content

Commit

Permalink
refactor: use unsigned type where possible in constants
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya Agarwal <[email protected]>
  • Loading branch information
Aditya-A-garwal committed Feb 17, 2024
1 parent bc5103c commit 9ff10c4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 27 deletions.
37 changes: 17 additions & 20 deletions include/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,29 @@

// display constants

const uint16_t RED = 0xF800;
const uint16_t GREEN = 0x07E0;
const uint16_t BLUE = 0x001F;
const uint16_t CYAN = 0x07FF;
const uint16_t MAGENTA = 0xF81F;
const uint16_t YELLOW = 0xFFE0;
const uint16_t WHITE = 0xFFFF;
const uint16_t GRAY = 0x520A;
const uint16_t BLACK = 0x0000;

const uint16_t DISPLAY_WIDTH = 320;
const uint16_t DISPLAY_HEIGHT = 480;
constexpr uint16_t RED = 0xF800;
constexpr uint16_t GREEN = 0x07E0;
constexpr uint16_t BLUE = 0x001F;
constexpr uint16_t CYAN = 0x07FF;
constexpr uint16_t MAGENTA = 0xF81F;
constexpr uint16_t YELLOW = 0xFFE0;
constexpr uint16_t WHITE = 0xFFFF;
constexpr uint16_t GRAY = 0x520A;
constexpr uint16_t BLACK = 0x0000;

constexpr unsigned DISPLAY_WIDTH = 320;
constexpr unsigned DISPLAY_HEIGHT = 480;

// touch constants

const uint16_t PRESSURE_LEFT = 10;
const uint16_t PRESSURE_RIGHT = 1200;
constexpr unsigned PRESSURE_LEFT = 10;
constexpr unsigned PRESSURE_RIGHT = 1200;

const int XP = 8;
const int XM = A2;
const int YP = A3;
const int YM = 9;

// UNO R3
// const int XBEGIN = 129;
// const int XEND = 902;
// const int YBEGIN = 94;
// const int YEND = 961;

// UNO R4 MINIMA
const int XBEGIN = 177;
const int XEND = 863;
Expand Down Expand Up @@ -115,4 +109,7 @@ const uint16_t SLOT_MENU_H = SAVE_H * 4;
constexpr unsigned CANVAS_BUFFER_W = 32;
constexpr unsigned CANVAS_BUFFER_H = 32;

constexpr unsigned CANVAS_BUFFER_MAX_SEGMENTS = 18;
constexpr unsigned CLIENT_BUFFER_MAX_SEGMENTS = 105;

#endif
2 changes: 1 addition & 1 deletion include/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
uint16_t code2color(uint8_t code);
uint8_t color2code(uint16_t clr);

bool inRange(uint16_t value, uint16_t lo, uint16_t hi);
bool inRange(unsigned value, unsigned lo, unsigned hi);

uint32_t distance(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1);
4 changes: 2 additions & 2 deletions include/touch.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define __TOUCH_H__

void toDisplayMode();
void convertTouchCoors(uint16_t tx, uint16_t ty, uint16_t *xptr, uint16_t *yptr);
void getTouchCoors(uint16_t *xptr, uint16_t *yptr);
void convertTouchCoors(unsigned tx, unsigned ty, unsigned *xptr, unsigned *yptr);
void getTouchCoors(unsigned *xptr, unsigned *yptr);

#endif
4 changes: 2 additions & 2 deletions src/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uint8_t color2code(uint16_t clr) {
}
}

bool inRange(uint16_t value, uint16_t lo, uint16_t hi) {
bool inRange(unsigned value, unsigned lo, unsigned hi) {
return lo <= value && value <= hi;
}

Expand All @@ -61,4 +61,4 @@ uint32_t distance(uint32_t x0, uint32_t y0, uint32_t x1, uint32_t y1) {
uint32_t j = (y0 > y1) ? (y0 - y1) : (y1 - y0);

return sqrt(i*i + j*j);
}
}
4 changes: 2 additions & 2 deletions src/touch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void toDisplayMode() {
pinMode(YP, OUTPUT);
}

void convertTouchCoors(uint16_t tx, uint16_t ty, uint16_t *xptr, uint16_t *yptr) {
void convertTouchCoors(unsigned tx, unsigned ty, unsigned *xptr, unsigned *yptr) {

tx = constrain(tx, XBEGIN, XEND);
ty = constrain(ty, YBEGIN, YEND);
Expand All @@ -28,7 +28,7 @@ void convertTouchCoors(uint16_t tx, uint16_t ty, uint16_t *xptr, uint16_t *yptr)
*yptr = ty;
}

void getTouchCoors(uint16_t *xptr, uint16_t *yptr) {
void getTouchCoors(unsigned *xptr, unsigned *yptr) {

TSPoint p;

Expand Down

0 comments on commit 9ff10c4

Please sign in to comment.