Browse Source

added rendering of previous / next month dayes

Toby Chui 1 year ago
parent
commit
00d26c8eba
2 changed files with 44 additions and 13 deletions
  1. 1 0
      InkyDash/InkyDash.ino
  2. 43 13
      InkyDash/draw.ino

+ 1 - 0
InkyDash/InkyDash.ino

@@ -40,6 +40,7 @@
 #define REFRESH_INTERVAL 900e6 //900 seconds, aka 15 minutes
 #define REFRESH_INTERVAL_HIGH_PWR_MODE 900000 //900 ms, aka 15 minutes
 
+#define SHOW_PREVIOUS_NEXT_MONTH_DAYS true //Show previous & next months days as well
 
 /* Display Libraries */
 #include <GxEPD.h>

+ 43 - 13
InkyDash/draw.ino

@@ -45,8 +45,8 @@ void drawDayProgressBar(int y, int padding, uint16_t color) {
   display.setTextColor(GxEPD_RED);
   for (int i = 0; i < numberOfBlocksToRender; i++) {
     int barHeight = 8;
-    if (i == int(totalNumberOfBlocks * 0.25) || i == int(totalNumberOfBlocks * 0.5) || i == int(totalNumberOfBlocks * 0.75)){
-      barHeight= 12;
+    if (i == int(totalNumberOfBlocks * 0.25) || i == int(totalNumberOfBlocks * 0.5) || i == int(totalNumberOfBlocks * 0.75)) {
+      barHeight = 12;
     }
     display.fillRect(padding + (i * (progressBarBlockSize * 2)), y + 5, progressBarBlockSize, barHeight, GxEPD_BLACK);
   }
@@ -125,21 +125,22 @@ void drawCalender(int y) {
   //Offset the y downward by 1.5 line height
   y += int(gridHeight * 1.5);
 
+  //Get the number of days in previous month
+  int previousMonthID = ptm->tm_mon;
+  if (previousMonthID == 0) {
+    //loop back to last year Dec
+    previousMonthID = 11;
+  } else {
+    previousMonthID = previousMonthID - 1;
+  }
+  int dayInPrevMonth = getNumberOfDayByMonth(previousMonthID);
+  int nextMonthDayCounter = 1;
+  
   //Render the calender dates
   display.setFont(&FreeSans12pt7b);
   int cx, cy, tcx, tcy;
   for (int dy = 0; dy < 6; dy++) {
     for (int dx = 0; dx < 7; dx++) {
-      if (dayCounter > dayInMonth) {
-        //End of this month
-        break;
-      }
-      if (dayCounter <= 0) {
-        //Shifting in first day of month
-        dayCounter++;
-        continue;
-      }
-
       //Get the center of the grid
       cx = dx * gridWidth + horizontalPadding + int(float(gridWidth) / 2.0);
       cy = y + dy * gridHeight + verticalPadding - int(float(gridHeight) / 2.0);
@@ -149,7 +150,36 @@ void drawCalender(int y) {
       tcx = cx - (tbw / 2.0);
       tcy = cy + (tbh / 2.0);
 
-      //Draw the text to screen
+      //Check for special case
+      if (dayCounter > dayInMonth) {
+        //End of this month
+        if (SHOW_PREVIOUS_NEXT_MONTH_DAYS) {
+          //Show next months days in another colors
+          display.setTextColor(GxEPD_RED);
+          display.setCursor(tcx, tcy);
+          display.print(String(nextMonthDayCounter));
+          display.setTextColor(GxEPD_BLACK);
+          nextMonthDayCounter++;
+          continue;
+        } else {
+          break;
+        }
+      }
+      if (dayCounter <= 0) {
+        //Shifting in first day of month
+        if (SHOW_PREVIOUS_NEXT_MONTH_DAYS) {
+          //Show previous months days in another colors
+          display.setTextColor(GxEPD_RED);
+          display.setCursor(tcx, tcy);
+          display.print(String(dayInPrevMonth + dayCounter));
+          display.setTextColor(GxEPD_BLACK);
+        }
+
+        dayCounter++;
+        continue;
+      }
+
+      //Draw the date to screen
       if (dayCounter == ptm->tm_mday) {
         //Today
         //display.fillRoundRect(dx * gridWidth + horizontalPadding, y + dy * gridHeight + verticalPadding - gridHeight, gridWidth, gridHeight, 3, GxEPD_RED);