Compare commits

..

2 Commits

4 changed files with 168 additions and 195 deletions

View File

@ -12,6 +12,137 @@ void SPI_SlaveInit(void)
SPCR = (1 << SPE) | (1 << SPIE);
}
void SetCommand(char *data2, int length){
char command = data2[0];
// Отрезать 1 элемент от оставшихся
switch (command){
case 1:
AllClearCommand(&data2[1], length-1);
break;
case 2:
SetPageCommand(&data2[1], length-1);
break;
case 3:
AddSymbolCommand(&data2[1], length-1);
break;
case 4:
DelSymbolCommand(&data2[1], length-1);
break;
case 5:
DrawPixelCommand(&data2[1], length-1);
break;
case 6:
DrawLineCommand(&data2[1], length-1);
break;
case 7:
DrawCircleCommand(&data2[1], length-1);
break;
case 8:
DrawRectangleCommand(&data2[1], length-1);
break;
case 9:
DrawCharCommand(&data2[1], length-1);
break;
}
}
// command 1
void AllClearCommand(char *symbols, int lenght){
int param = symbols[0];
if (param == 0){
Fill(0);
update();
}
else{
Fill(255);
update();
}
}
// command 2
void SetPageCommand(char *symbols, int lenght){
SetPage(symbols[0]);
update();
}
// command 3
void AddSymbolCommand(char *symbols, int lenght) {
for (int i = 0; i < lenght - 1; i++) {
AddSymbol(symbols[i]);
}
update();
}
// command 4
void DelSymbolCommand(char *symbols, int lenght) {
for (int i = 0; i < symbols[0]; i++) {
DelSymbol();
}
update();
}
// command 5
void DrawPixelCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int color = symbols[2];
DrawPixel(x, y, color);
update();
}
// command 6
void DrawLineCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int x1 = symbols[2];
int y1 = symbols[3];
int color = symbols[4];
DrawLine(x, y, x1, y1, color);
update();
}
// command 7
void DrawCircleCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int r = symbols[2];
// white on black color=1, fill=0
int color = symbols[3];
int fill = symbols[4];
DrawCircle(x, y, r, color, fill);
update();
}
// command 8
void DrawRectangleCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int width = symbols[2];
int height = symbols[3];
// white on black color=1, fill=0
int color = symbols[4];
int fill = symbols[5];
DrawRect(x, y, width, height, color, fill);
update();
}
// command 9
void DrawCharCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int charIndex = symbols[2];
int fill = symbols[3];
// white on black color=1, fill=0
DrawChar(x, y, charIndex, fill);
update();
}
// Функция для вычисления контрольной суммы XOR
char CRC8(char *data, int length) {
char crc = 0x00;

View File

@ -13,6 +13,20 @@ extern "C" {
#endif
void SPI_SlaveInit(void);
void SetCommand(char *data2, int length);
void AllClearCommand(char *symbols, int lenght);
void SetPageCommand(char *symbols, int lenght);
void AddSymbolCommand(char *symbols, int lenght);
void DelSymbolCommand(char *symbols, int lenght);
void DrawPixelCommand(char *symbols, int lenght);
void DrawLineCommand(char *symbols, int lenght);
void DrawCircleCommand(char *symbols, int lenght);
void DrawRectangleCommand(char *symbols, int lenght);
void DrawCharCommand(char *symbols, int lenght);
char CRC8(char *data, int length);
char checkArray(char *arr, int size);

View File

@ -240,29 +240,29 @@ void update() {
}
const uint8_t _charMap[][5] = {
{0x00, 0x00, 0x00, 0x00, 0x00}, // 0x20 32
{0x00, 0x1c, 0x22, 0x41, 0x00}, // ( 0x21 33
{0x00, 0x41, 0x22, 0x1c, 0x00}, // ) 0x22 34
{0x14, 0x08, 0x3e, 0x08, 0x14}, // * 0x23 35
{0x08, 0x08, 0x3e, 0x08, 0x08}, // + 0x24 36
{0x00, 0x50, 0x30, 0x00, 0x00}, // , 0x25 37
{0x08, 0x08, 0x08, 0x08, 0x08}, // - 0x26 38
{0x00, 0x60, 0x60, 0x00, 0x00}, // . 0x27 39
{0x20, 0x10, 0x08, 0x04, 0x02}, // / 0x28 40
{0x3e, 0x51, 0x49, 0x45, 0x3e}, // 0 0x29 41
{0x00, 0x42, 0x7f, 0x40, 0x00}, // 1 0x2a 42
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2 0x2b 43
{0x21, 0x41, 0x45, 0x4b, 0x31}, // 3 0x2c 44
{0x18, 0x14, 0x12, 0x7f, 0x10}, // 4 0x2d 45
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5 0x2e 46
{0x3c, 0x4a, 0x49, 0x49, 0x30}, // 6 0x2f 47
{0x01, 0x71, 0x09, 0x05, 0x03}, // 7 0x30 48
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8 0x31 49
{0x06, 0x49, 0x49, 0x29, 0x1e}, // 9 0x32 50
{0x00, 0x36, 0x36, 0x00, 0x00}, // : 0x33 51
{0x08, 0x14, 0x22, 0x41, 0x00}, // < 0x34 52
{0x14, 0x14, 0x14, 0x14, 0x14}, // = 0x35 53
{0x00, 0x41, 0x22, 0x14, 0x08}, // > 0x36 54
{0x00, 0x00, 0x00, 0x00, 0x00}, // 0x00 32
{0x00, 0x1c, 0x22, 0x41, 0x00}, // ( 0x01 33
{0x00, 0x41, 0x22, 0x1c, 0x00}, // ) 0x02 34
{0x14, 0x08, 0x3e, 0x08, 0x14}, // * 0x03 35
{0x08, 0x08, 0x3e, 0x08, 0x08}, // + 0x04 36
{0x00, 0x50, 0x30, 0x00, 0x00}, // , 0x05 37
{0x08, 0x08, 0x08, 0x08, 0x08}, // - 0x06 38
{0x00, 0x60, 0x60, 0x00, 0x00}, // . 0x07 39
{0x20, 0x10, 0x08, 0x04, 0x02}, // / 0x08 40
{0x3e, 0x51, 0x49, 0x45, 0x3e}, // 0 0x09 41
{0x00, 0x42, 0x7f, 0x40, 0x00}, // 1 0x0a 42
{0x42, 0x61, 0x51, 0x49, 0x46}, // 2 0x0b 43
{0x21, 0x41, 0x45, 0x4b, 0x31}, // 3 0x0c 44
{0x18, 0x14, 0x12, 0x7f, 0x10}, // 4 0x0d 45
{0x27, 0x45, 0x45, 0x45, 0x39}, // 5 0x0e 46
{0x3c, 0x4a, 0x49, 0x49, 0x30}, // 6 0x0f 47
{0x01, 0x71, 0x09, 0x05, 0x03}, // 7 0x10 48
{0x36, 0x49, 0x49, 0x49, 0x36}, // 8 0x11 49
{0x06, 0x49, 0x49, 0x29, 0x1e}, // 9 0x12 50
{0x00, 0x36, 0x36, 0x00, 0x00}, // : 0x13 51
{0x08, 0x14, 0x22, 0x41, 0x00}, // < 0x14 52
{0x14, 0x14, 0x14, 0x14, 0x14}, // = 0x15 53
{0x00, 0x41, 0x22, 0x14, 0x08}, // > 0x16 54
};
void DrawChar(uint8_t x, uint8_t y, uint8_t charIndex, uint8_t fill) {

View File

@ -1,27 +1,10 @@
#include "SPISlave.h"
#include "head_oled_i2c.h"
// #include <GyverOLED.h>
// #include <GyverOLED.h>
// GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
// GyverOLED<SSD1306_128x64, OLED_NO_BUFFER> oled;
static int index = 0;
static int arIndex = 0;
static char data[64];
// void SPI_SlaveInit(void)
// {
// DDR_SPI = (1 << DD_MISO);
// SPCR = (1 << SPE) | (1 << SPIE);
// }
// biblary
ISR(SPI_STC_vect)
{
char received = SPDR;
@ -35,169 +18,15 @@ void setup()
SPI_SlaveInit();
initialization();
// oled_init();
Fill(0);
SetPage(2);
update();
// oled.setScale(3);
// oled.home();
Serial.println();
Serial.println("Initialization ");
}
void SetCommand(char *data2, int length){
char command = data2[0];
// Отрезать 1 элемент от оставшихся
Serial.print("\nReceived command: ");
Serial.println(command, HEX);
switch (command){
case 1:
AllClearCommand(&data2[1], length-1);
break;
case 2:
SetPageCommand(&data2[1], length-1);
break;
// case 6:
// PrintMassive(&data2[1], length-1);
// break;
case 3:
AddSymbolCommand(&data2[1], length-1);
break;
case 4:
DelSymbolCommand(&data2[1], length-1);
break;
case 5:
DrawPixelCommand(&data2[1], length-1);
PrintMassive(&data2[1], length-1);
break;
case 6:
DrawLineCommand(&data2[1], length-1);
break;
case 7:
DrawCircleCommand(&data2[1], length-1);
break;
case 8:
DrawRectangleCommand(&data2[1], length-1);
break;
}
}
void PrintMassive(uint8_t *symbols, int lenght){
Serial.print("Received Add: ");
// oled.setScale(3); // масштаб текста (1..4)
// oled.home(); // курсор в 0,0
// oled.print("Привет!");
for(int i = 0; i < lenght - 1; i++) {
char str[3];
sprintf(str, "%01X", symbols[i]);
Serial.print(str);
Serial.print(" ");
}
}
// Another
// command 1
void AllClearCommand(char *symbols, int lenght){
int param = symbols[0];
if (param == 0){
Fill(0);
update();
// oled.fill(0);
}
else{
Fill(255);
update();
// oled.fill(255);
}
}
// command 2
void SetPageCommand(char *symbols, int lenght){
// int x = symbols[0];
// int y = symbols[1];
// oled.setCursor(x,y);
SetPage(symbols[0]);
update();
}
// command 3
void AddSymbolCommand(char *symbols, int lenght) {
// SetPage(2);
for (int i = 0; i < lenght - 1; i++) {
// oled.print(symbols[i]);
AddSymbol(symbols[i]);
}
update();
}
// command 4
void DelSymbolCommand(char *symbols, int lenght) {
for (int i = 0; i < symbols[0]; i++) {
DelSymbol();
}
update();
}
// command 5
void DrawPixelCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int color = symbols[2];
DrawPixel(x, y, color);
update();
// oled.dot(x,y,color);
}
// command 6
void DrawLineCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int x1 = symbols[2];
int y1 = symbols[3];
int color = symbols[4];
DrawLine(x, y, x1, y1, color);
update();
// oled.line(x,y,x1,y1,color);
}
// command 7
void DrawCircleCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int r = symbols[2];
// white on black color=1, fill=0
int color = symbols[3];
int fill = symbols[4];
DrawCircle(x, y, r, color, fill);
update();
// oled.circle(x,y,r,color);
}
// command 8
void DrawRectangleCommand(char *symbols, int lenght){
int x = symbols[0];
int y = symbols[1];
int width = symbols[2];
int height = symbols[3];
// white on black color=1, fill=0
int color = symbols[4];
int fill = symbols[5];
DrawRect(x, y, width, height, color, fill);
update();
// oled.rect(x,y,x1,y1,color);
}
// Вывод массива
@ -216,7 +45,6 @@ void arrayOut(uint8_t *arr, int size){
void loop() {
if(PINB & (1 << 2)){
if(index > 0){
arrayOut(data, index);
char sum = 0;