#include <cstdio>
#include <stdint.h>
#include <cstring>
+#include <ctype.h>
#include <stdio.h>
#include <wiringPi.h>
+#include <time.h>
+#include <math.h>
int binWriteDisplay (uint8_t digit, uint8_t segment);
-void printBinary (int num);
const int digits [3] = { 17, 27, 22 };
const int segments [3] = { 23, 24, 25 };
-const int segmentDigits [] =
-{
-// g f e d c b a
-// 0 1 2 3 4 5 6
- 1, 1, 1, 1, 1, 1, 0, // 0
- 0, 1, 1, 0, 0, 0, 0, // 1
- 1, 1, 0, 1, 1, 0, 1, // 2
- 1, 1, 1, 1, 0, 0, 1, // 3
- 0, 1, 1, 0, 0, 1, 1, // 4
- 1, 0, 1, 1, 0, 1, 1, // 5
- 1, 0, 1, 1, 1, 1, 1, // 6
- 1, 1, 1, 0, 0, 0, 0, // 7
- 1, 1, 1, 1, 1, 1, 1, // 8
- 1, 1, 1, 1, 0, 1, 1, // 9
- 1, 1, 1, 0, 1, 1, 1, // A
- 0, 0, 1, 1, 1, 1, 1, // b
- 1, 0, 0, 1, 1, 1, 0, // C
- 0, 1, 1, 1, 1, 0, 1, // d
- 1, 0, 0, 1, 1, 1, 1, // E
- 1, 0, 0, 0, 1, 1, 1, // F
- 0, 0, 0, 0, 0, 0, 0, // blank
-};
-
const uint8_t segDigits[] =
{
0b01111110, // 0
0b01110000, // 7
0b01111111, // 8
0b01111011, // 9
+ 0b01110111, // A
+ 0b00011111, // b
+ 0b01001110, // C
+ 0b01001111, // E
+ 0b01000111, // F
+ 0b01011110, // G
+ 0b00010111, // h
+ 0b00000110, // I
+ 0b00111100, // J
+ 0b01010111, // K
+ 0b00001110, // L
+ 0b01010100, // M
+ 0b01110110, // N
+ 0b01111110, // O
+ 0b01100111, // P
+ 0b01110011, // Q
+ 0b01100110, // R
+ 0b01011011, // S
+ 0b00001111, // t
+ 0b00111110, // U
+ 0b00111010, // V
+ 0b00101010, // W
+ 0b00110111, // X
+ 0b00111011, // Y
+ 0b01101001, // Z
0b00000000, // blank
};
REC = 0b1110
};
+enum Mode
+{
+ CLOCK,
+ TEXT
+};
+
+struct displayState {
+ enum Mode Mode;
+ char text[6];
+ uint16_t symbols;
+ int delay = 100;
+};
+
+displayState display;
+
+// Time
+time_t now;
+struct tm *t;
+
int binWriteDisplay (uint8_t digit, uint8_t segment)
{
if (digit > 0b111 || segment > 0b111)
return 0;
}
-void writeSymbol (enum Symbol symbol)
+void writeSymbol (enum Symbol symbol, int delay = 100)
{
binWriteDisplay(symbol >> 3, symbol & 0b0111);
+ delayMicroseconds(delay);
}
void binWriteSegments (uint8_t digit, uint8_t segments, int delay = 100)
for (int i = 0; i < length; i++)
{
- binWriteSegments(i + 2, segDigits[str[length - i - 1] - 48]);
+ char c = str[length - i - 1];
+ char index;
+
+ c = toupper(c);
+
+ if (c >= '0' && c <= '9')
+ index = c - '0';
+ else if (c >= 'A' && c <= 'Z')
+ index = c - 'A' + 10;
+ else
+ index = sizeof(segDigits);
+
+ binWriteSegments(i + 2, segDigits[index]);
}
}
+bool getSymbolState(Symbol symbol)
+{
+ int mask = 2 ^ symbol;
+
+ return false;
+}
+
+void setSymbolState(Symbol symbol, bool state)
+{
+
+}
+
void testDisplay (void)
{
- char str[] = "123456";
- write(str);
- //binWriteSegments(2, segDigits[2]);
+
+}
+
+void updateTime(tm *t)
+{
+ int hour = t->tm_hour;
+ int min = t->tm_min;
+ int sec = t->tm_sec;
+
+ if (hour > 12)
+ hour -= 12;
+
+ sprintf (display.text, "%d%02d%02d", hour, min, sec);
+
+ if (t->tm_sec % 2)
+ {
+
+ }
+}
+
+PI_THREAD (dispalyDigits)
+{
+ piHiPri(50);
+
+ for (;;)
+ {
+ write(display.text);
+
+ /*if (t->tm_sec % 2 == 0)
+ {
+ writeSymbol(COL1);
+ writeSymbol(COL2);
+ }*/
+ }
+
+ return 0;
}
void setupDisplay (void)
}
displayOff();
+
+
+ piThreadCreate(dispalyDigits);
+ delay(10);
}