]> code.bitgloo.com Git - clyne/smartwatch.git/commitdiff
lower power, sharp refresh task
authortcsullivan <tullivan99@gmail.com>
Tue, 5 Mar 2019 00:00:00 +0000 (19:00 -0500)
committertcsullivan <tullivan99@gmail.com>
Tue, 5 Mar 2019 00:00:00 +0000 (19:00 -0500)
source/controller.cpp
source/driverSharp.cpp
source/driverSharp.h

index 853e8fc7ef2ca5e6662f25a408bafefadef7d85a..c4ea12c39fc0b8deeda7af9624d683c38ce0f03b 100755 (executable)
  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();
-  }
 }
index 74a2a707d17c9b48dfaf4c299fe41fba5a104f1a..2dbcec6df58965d0c0a5baef58b94a8785ebe2f4 100644 (file)
@@ -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);
+       }
 }
 
index 9da6f984c8905655ffbea7ac25c38499f50f4e86..f99c03c2e945ff38e1a9010a5393fc5ad498ef01 100644 (file)
@@ -1,3 +1,2 @@
 
 void sharpInit(void);
-void sharpRefresh(unsigned int pause = 500);