aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsource/controller.cpp40
-rw-r--r--source/sharp.cpp38
-rw-r--r--source/sharp.hpp10
-rw-r--r--source/vibrate.hpp42
4 files changed, 81 insertions, 49 deletions
diff --git a/source/controller.cpp b/source/controller.cpp
index 73bc440..defae8a 100755
--- a/source/controller.cpp
+++ b/source/controller.cpp
@@ -22,6 +22,7 @@
#include "rtc.hpp"
#include "sharp.hpp"
+#include "vibrate.hpp"
#include "widget.hpp"
BLEUart bleuart;
@@ -40,8 +41,7 @@ void setup(void)
while (!Serial)
delay(10);
- Serial.println(F("Initializing..."));
-
+ Vibrate::begin();
RTC::begin();
Sharp::begin();
@@ -63,16 +63,13 @@ void setup(void)
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
- 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");
+}
+
+static int touchToCoord(int val)
+{
+ return val / 70 * (SHARP_HEIGHT / 10);
}
void loop(void)
@@ -90,22 +87,15 @@ void loop(void)
}
auto diff = val - last;
- if (diff > 50) {
- Sharp::setScrollVelocity(1);
+ if (std::abs(diff) > 50) {
+ Sharp::setScroll(touchToCoord(diff));
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);
- }
+ if (last != 0 && !scrolled)
+ Sharp::sendInput(touchToCoord(last));
last = 0;
- Sharp::setScrollVelocity(0);
+ Sharp::setScroll();
}
delay(10);
@@ -121,9 +111,11 @@ void handlePacket(void)
switch (buf[0]) {
case 'L':
- //RTC::setMessage(buf + 1);
+ Vibrate::pulse();
+ Sharp::addWidget<NotificationWidget>(buf + 1);
break;
case 'T':
+ Vibrate::pulse();
Sharp::addWidget<NotificationWidget>("Time updated");
RTC::setTicks(std::atoi(buf + 1) * 60);
break;
diff --git a/source/sharp.cpp b/source/sharp.cpp
index 4b7aa94..ab0788b 100644
--- a/source/sharp.cpp
+++ b/source/sharp.cpp
@@ -31,7 +31,6 @@ TaskHandle_t Sharp::taskHandle;
std::vector<Widget *> Sharp::widgets;
int Sharp::topY = 0;
-int Sharp::scrollVelocity = 0;
void Sharp::begin(void)
{
@@ -70,31 +69,26 @@ void Sharp::sendInput(int ypos)
void Sharp::updateTask([[maybe_unused]] void *arg)
{
- static unsigned int counter = 0;
- while (1) {
- if (counter++ == 3) {
- counter = 0;
+ static int oldTopY = 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;
- }
+ while (1) {
+ if (oldTopY != topY) {
+ oldTopY = topY;
+ display.clearDisplay();
+ }
- display.refresh();
- } else {
- topY += scrollVelocity * 20;
- if (scrollVelocity != 0)
- display.clearDisplay();
- if (topY > 0)
- topY = 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;
}
- delay(50);
+ display.refresh();
+ delay(150);
}
}
diff --git a/source/sharp.hpp b/source/sharp.hpp
index f1b6631..155acec 100644
--- a/source/sharp.hpp
+++ b/source/sharp.hpp
@@ -40,7 +40,6 @@ private:
static std::vector<Widget *> widgets;
static int topY;
- static int scrollVelocity;
public:
static void begin(void);
@@ -50,8 +49,13 @@ public:
widgets.emplace_back(new T(args...));
}
- inline static void setScrollVelocity(int vel) {
- scrollVelocity = vel;
+ inline static void setScroll(int scr = 0) {
+ static int oldTopY = 0;
+ if (scr == 0) {
+ oldTopY = topY;
+ } else {
+ topY = minof(0, oldTopY + scr);
+ }
}
static void sendInput(int ypos);
diff --git a/source/vibrate.hpp b/source/vibrate.hpp
new file mode 100644
index 0000000..55eb511
--- /dev/null
+++ b/source/vibrate.hpp
@@ -0,0 +1,42 @@
+/**
+ * @file vibrate.hpp
+ * @brief Provides access to the vibration motor.
+ *
+ * Copyright (C) 2019 Clyne Sullivan
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef VIBRATE_HPP_
+#define VIBRATE_HPP_
+
+class Vibrate {
+private:
+ constexpr static unsigned int motorPin = 27;
+ constexpr static unsigned int pulseDuration = 200;
+
+public:
+ inline static void begin(void) {
+ pinMode(motorPin, OUTPUT);
+ digitalWrite(motorPin, false);
+ }
+
+ inline static void pulse(void) {
+ digitalWrite(motorPin, true);
+ delay(pulseDuration);
+ digitalWrite(motorPin, false);
+ }
+};
+
+#endif // VIBRATE_HPP_