aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2019-03-28 14:47:22 -0400
committerClyne Sullivan <tullivan99@gmail.com>2019-03-28 14:47:22 -0400
commit51a072639f2bcf95a87ccaf82c75454212fde607 (patch)
tree9a7384e46725e0f41d9f4ecdfb8eb89344ce89c5
parentf986c858e54d9be72020ae2d7319e70eab6de17d (diff)
added input: scrolling and tapping
-rwxr-xr-xMakefile3
-rwxr-xr-xsource/controller.cpp35
-rw-r--r--source/sharp.cpp61
-rw-r--r--source/sharp.hpp13
-rw-r--r--source/widget.cpp4
-rw-r--r--source/widget.hpp15
6 files changed, 112 insertions, 19 deletions
diff --git a/Makefile b/Makefile
index 60a7490..961769d 100755
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ MCUFLAGS = -mcpu=cortex-m4 -mthumb -mabi=aapcs \
CFLAGS = $(MCUFLAGS) --std=gnu99
CXXFLAGS = $(MCUFLAGS) --std=c++17 -fno-builtin -fno-exceptions \
- -fno-strict-aliasing
+ -fno-strict-aliasing
SFLAGS = $(MCUFLAGS) -x assembler-with-cpp \
-DCONFIG_GPIO_AS_PINRESET \
@@ -35,6 +35,7 @@ CSRC = $(wildcard $(ARDUINO)/cores/nRF5/freertos/Source/*.c) \
$(ARDUINO)/cores/nRF5/nordic/nrfx/mdk/system_nrf52.c \
$(ARDUINO)/cores/nRF5/wiring.c \
$(ARDUINO)/cores/nRF5/wiring_digital.c \
+ $(ARDUINO)/cores/nRF5/wiring_analog_nRF52.c \
$(ARDUINO)/libraries/FileSystem/src/littlefs/lfs.c \
$(ARDUINO)/libraries/FileSystem/src/littlefs/lfs_util.c \
$(ARDUINO)/libraries/Bluefruit52Lib/src/utility/bootloader_util.c \
diff --git a/source/controller.cpp b/source/controller.cpp
index d9ac961..3aa6c3a 100755
--- a/source/controller.cpp
+++ b/source/controller.cpp
@@ -48,6 +48,13 @@ void setup(void)
Serial.println(F("Ready."));
Sharp::addWidget<TimeWidget>();
Sharp::addWidget<NotificationWidget>("Welcome to smartwatch");
+ Sharp::addWidget<NotificationWidget>("Hi");
+ Sharp::addWidget<NotificationWidget>("Once upon a time, there lived an old man. His name was Gerg.");
+ Sharp::addWidget<NotificationWidget>("NOTICE: Play more games");
+ Sharp::addWidget<NotificationWidget>("2 new messages");
+ Sharp::addWidget<NotificationWidget>("you have mail");
+ Sharp::addWidget<NotificationWidget>("GGGGGGGGGGGGGGGGGGGGGGG");
+ Sharp::addWidget<NotificationWidget>("ABCDEFGHIJKLMNOPQRSTUZWXYZ");
}
void loop(void)
@@ -55,6 +62,34 @@ void loop(void)
if (bleuart.available())
handlePacket();
+ static int last = 0;
+ static bool scrolled = false;
+ int val = analogRead(A5);
+ if (val >= 10) {
+ if (last == 0) {
+ scrolled = false;
+ last = val;
+ }
+
+ auto diff = val - last;
+ if (diff > 50) {
+ Sharp::setScrollVelocity(1);
+ scrolled = true;
+ } else if (diff < -50) {
+ Sharp::setScrollVelocity(-1);
+ scrolled = true;
+ } else {
+ Sharp::setScrollVelocity(0);
+ }
+ } else {
+ if (last != 0 && !scrolled) {
+ int ypos = last / 70 * (SHARP_HEIGHT / 10);
+ Sharp::sendInput(ypos);
+ }
+ last = 0;
+ Sharp::setScrollVelocity(0);
+ }
+
delay(10);
}
diff --git a/source/sharp.cpp b/source/sharp.cpp
index 8fa22f9..8572445 100644
--- a/source/sharp.cpp
+++ b/source/sharp.cpp
@@ -1,9 +1,6 @@
#include "sharp.hpp"
#include "rtc.hpp"
-constexpr unsigned int SHARP_WIDTH = 144;
-constexpr unsigned int SHARP_HEIGHT = 168;
-
constexpr unsigned int SHARP_SCK = 12;
constexpr unsigned int SHARP_MOSI = 13;
constexpr unsigned int SHARP_SS = 14;
@@ -13,6 +10,9 @@ Adafruit_SharpMem Sharp::display(SHARP_SCK, SHARP_MOSI, SHARP_SS, SHARP_WIDTH,
TaskHandle_t Sharp::taskHandle;
std::vector<Widget *> Sharp::widgets;
+int Sharp::topY = 0;
+int Sharp::scrollVelocity = 0;
+
void Sharp::begin(void)
{
widgets.reserve(10);
@@ -25,21 +25,56 @@ void Sharp::begin(void)
&taskHandle);
}
+void Sharp::sendInput(int ypos)
+{
+ if (ypos < 0 || ypos > SHARP_HEIGHT)
+ return;
+
+ int y = topY;
+ for (unsigned int i = 0; i < widgets.size(); i++) {
+ y += widgets[i]->getHeight();
+ if (ypos < y) {
+ if (widgets[i]->onPress()) {
+ delete widgets[i];
+ widgets.erase(widgets.begin() + i);
+ display.clearDisplay();
+ }
+ break;
+ }
+
+ y += 3;
+ if (y >= SHARP_HEIGHT)
+ break;
+ }
+}
+
void Sharp::updateTask([[maybe_unused]] void *arg)
{
+ static unsigned int counter = 0;
while (1) {
- unsigned int y = 0;
- for (auto& w : widgets) {
- w->render(display, y);
- y += w->getHeight();
- display.drawFastHLine(0, y + 1, SHARP_WIDTH, BLACK);
- y += 3;
- if (y >= SHARP_HEIGHT)
- break;
+ if (counter++ == 3) {
+ counter = 0;
+
+ auto y = topY;
+ for (auto& w : widgets) {
+ w->render(display, y);
+ y += w->getHeight();
+ display.drawFastHLine(0, y + 1, SHARP_WIDTH, BLACK);
+ y += 3;
+ if (y >= SHARP_HEIGHT)
+ break;
+ }
+
+ display.refresh();
+ } else {
+ topY += scrollVelocity * 20;
+ if (scrollVelocity != 0)
+ display.clearDisplay();
+ if (topY > 0)
+ topY = 0;
}
- display.refresh();
- delay(300);
+ delay(50);
}
}
diff --git a/source/sharp.hpp b/source/sharp.hpp
index 2775711..3c1d34e 100644
--- a/source/sharp.hpp
+++ b/source/sharp.hpp
@@ -9,12 +9,19 @@
#define BLACK 0
#define WHITE 1
+constexpr int SHARP_WIDTH = 144;
+constexpr int SHARP_HEIGHT = 168;
+
class Sharp {
private:
static Adafruit_SharpMem display;
static TaskHandle_t taskHandle;
static std::vector<Widget *> widgets;
+
+ static int topY;
+ static int scrollVelocity;
+
public:
static void begin(void);
@@ -23,6 +30,12 @@ public:
widgets.emplace_back(new T(args...));
}
+ inline static void setScrollVelocity(int vel) {
+ scrollVelocity = vel;
+ }
+
+ static void sendInput(int ypos);
+
private:
static void updateTask(void *);
};
diff --git a/source/widget.cpp b/source/widget.cpp
index 9109185..08b9dc6 100644
--- a/source/widget.cpp
+++ b/source/widget.cpp
@@ -1,7 +1,7 @@
#include "rtc.hpp"
#include "widget.hpp"
-void TimeWidget::render(Adafruit_GFX& display, unsigned int ypos)
+void TimeWidget::render(Adafruit_GFX& display, int ypos)
{
if (auto t = RTC::ticks(); t != prevTicks) {
prevTicks = t;
@@ -12,7 +12,7 @@ void TimeWidget::render(Adafruit_GFX& display, unsigned int ypos)
}
}
-void NotificationWidget::render(Adafruit_GFX& display, unsigned int ypos)
+void NotificationWidget::render(Adafruit_GFX& display, int ypos)
{
display.setTextSize(2);
display.setCursor(0, ypos);
diff --git a/source/widget.hpp b/source/widget.hpp
index afa9441..f94ccdb 100644
--- a/source/widget.hpp
+++ b/source/widget.hpp
@@ -3,6 +3,7 @@
class Adafruit_GFX;
+#include <bluefruit.h>
#include <cstring>
class Widget {
@@ -16,7 +17,8 @@ public:
return height;
}
- virtual void render(Adafruit_GFX& display, unsigned int ypos) = 0;
+ virtual void render(Adafruit_GFX& display, int ypos) = 0;
+ virtual bool onPress(void) = 0;
protected:
inline void setHeight(unsigned int _height) {
@@ -32,7 +34,10 @@ public:
constexpr TimeWidget(void)
: Widget(30), prevTicks(0) {}
- void render(Adafruit_GFX& display, unsigned int ypos) final;
+ void render(Adafruit_GFX& display, int ypos) final;
+ bool onPress(void) final {
+ return false;
+ }
};
class NotificationWidget : public Widget {
@@ -49,6 +54,10 @@ public:
setHeight(16 * (i / 12 + 1));
}
- void render(Adafruit_GFX& display, unsigned int ypos) final;
+ void render(Adafruit_GFX& display, int ypos) final;
+ bool onPress(void) final {
+ return true;
+ }
};
+
#endif // WIDGET_HPP_