aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortcsullivan <tullivan99@gmail.com>2019-03-04 19:00:00 -0500
committertcsullivan <tullivan99@gmail.com>2019-03-04 19:00:00 -0500
commit3c3f87b4cab153b49e3cde105dd2f34712e0b790 (patch)
treeafd47ab574d832b040141050693c32c031324dda
parentd2284735eee14f2210d9ee1b77b6cecb02e0589b (diff)
lower power, sharp refresh task
-rwxr-xr-xsource/controller.cpp98
-rw-r--r--source/driverSharp.cpp15
-rw-r--r--source/driverSharp.h1
3 files changed, 24 insertions, 90 deletions
diff --git a/source/controller.cpp b/source/controller.cpp
index 853e8fc..c4ea12c 100755
--- a/source/controller.cpp
+++ b/source/controller.cpp
@@ -12,7 +12,10 @@
any redistribution
*********************************************************************/
+// sharp takes < ~0.05uA
+
#include <bluefruit.h>
+#include <cmath>
#include "driverSharp.h"
@@ -35,9 +38,11 @@ void setup(void)
Serial.println(F("Initializing..."));
+ sharpInit();
+
Bluefruit.begin();
// Set max power. Accepted values are: -40, -30, -20, -16, -12, -8, -4, 0, 4
- Bluefruit.setTxPower(4);
+ Bluefruit.setTxPower(-20);//4);
Bluefruit.setName("Bluefruit52");
// Configure and start the BLE Uart service
@@ -47,8 +52,6 @@ void setup(void)
startAdv();
Serial.println(F("Ready."));
-
- sharpInit();
}
void startAdv(void)
@@ -86,29 +89,17 @@ void startAdv(void)
/**************************************************************************/
void loop(void)
{
- sharpRefresh(300);
-
+ //static unsigned int i = 0;
+ //auto y = 8.7L * std::sin(i++ / -0.5L);
+ //bleuart.print(i);
+ //bleuart.print(',');
+ //bleuart.println((int)y);
+ //delay(900);
// Wait for new data to arrive
+
uint8_t len = readPacket(&bleuart, 500);
if (len == 0) return;
- // Got a packet!
- // printHex(packetbuffer, len);
-
- // Color
- if (packetbuffer[1] == 'C') {
- uint8_t red = packetbuffer[2];
- uint8_t green = packetbuffer[3];
- uint8_t blue = packetbuffer[4];
- Serial.print ("RGB #");
- if (red < 0x10) Serial.print("0");
- Serial.print(red, HEX);
- if (green < 0x10) Serial.print("0");
- Serial.print(green, HEX);
- if (blue < 0x10) Serial.print("0");
- Serial.println(blue, HEX);
- }
-
// Buttons
if (packetbuffer[1] == 'B') {
uint8_t buttnum = packetbuffer[2] - '0';
@@ -121,67 +112,4 @@ void loop(void)
}
}
- // GPS Location
- if (packetbuffer[1] == 'L') {
- float lat, lon, alt;
- lat = parsefloat(packetbuffer+2);
- lon = parsefloat(packetbuffer+6);
- alt = parsefloat(packetbuffer+10);
- Serial.print("GPS Location\t");
- Serial.print("Lat: "); Serial.print(lat, 4); // 4 digits of precision!
- Serial.print('\t');
- Serial.print("Lon: "); Serial.print(lon, 4); // 4 digits of precision!
- Serial.print('\t');
- Serial.print(alt, 4); Serial.println(" meters");
- }
-
- // Accelerometer
- if (packetbuffer[1] == 'A') {
- float x, y, z;
- x = parsefloat(packetbuffer+2);
- y = parsefloat(packetbuffer+6);
- z = parsefloat(packetbuffer+10);
- Serial.print("Accel\t");
- Serial.print(x); Serial.print('\t');
- Serial.print(y); Serial.print('\t');
- Serial.print(z); Serial.println();
- }
-
- // Magnetometer
- if (packetbuffer[1] == 'M') {
- float x, y, z;
- x = parsefloat(packetbuffer+2);
- y = parsefloat(packetbuffer+6);
- z = parsefloat(packetbuffer+10);
- Serial.print("Mag\t");
- Serial.print(x); Serial.print('\t');
- Serial.print(y); Serial.print('\t');
- Serial.print(z); Serial.println();
- }
-
- // Gyroscope
- if (packetbuffer[1] == 'G') {
- float x, y, z;
- x = parsefloat(packetbuffer+2);
- y = parsefloat(packetbuffer+6);
- z = parsefloat(packetbuffer+10);
- Serial.print("Gyro\t");
- Serial.print(x); Serial.print('\t');
- Serial.print(y); Serial.print('\t');
- Serial.print(z); Serial.println();
- }
-
- // Quaternions
- if (packetbuffer[1] == 'Q') {
- float x, y, z, w;
- x = parsefloat(packetbuffer+2);
- y = parsefloat(packetbuffer+6);
- z = parsefloat(packetbuffer+10);
- w = parsefloat(packetbuffer+14);
- Serial.print("Quat\t");
- Serial.print(x); Serial.print('\t');
- Serial.print(y); Serial.print('\t');
- Serial.print(z); Serial.print('\t');
- Serial.print(w); Serial.println();
- }
}
diff --git a/source/driverSharp.cpp b/source/driverSharp.cpp
index 74a2a70..2dbcec6 100644
--- a/source/driverSharp.cpp
+++ b/source/driverSharp.cpp
@@ -9,19 +9,26 @@ Adafruit_SharpMem display(SHARP_SCK, SHARP_MOSI, SHARP_SS, 144, 168);
#define BLACK 0
#define WHITE 1
+static TaskHandle_t sharpHandle;
+void sharpTask(void *arg);
+
void sharpInit(void)
{
display.begin();
display.clearDisplay();
- display.setTextSize(1);
+ display.setTextSize(3);
display.setTextColor(BLACK);
display.setCursor(0, 0);
display.println("Hello!");
+
+ xTaskCreate(sharpTask, "sharp", 512, nullptr, TASK_PRIO_LOW, &sharpHandle);
}
-void sharpRefresh(unsigned int pause)
+void sharpTask([[maybe_unused]] void *arg)
{
- display.refresh();
- delay(pause);
+ while (1) {
+ display.refresh();
+ delay(500);
+ }
}
diff --git a/source/driverSharp.h b/source/driverSharp.h
index 9da6f98..f99c03c 100644
--- a/source/driverSharp.h
+++ b/source/driverSharp.h
@@ -1,3 +1,2 @@
void sharpInit(void);
-void sharpRefresh(unsigned int pause = 500);