Permalink
Browse files

Add the ability to save the image. Improve color choice.

  • Loading branch information...
dulsi committed Jun 16, 2018
1 parent 439e773 commit e92a337bd5484d22952e2450438c5dd29c0ca17f
Showing with 104 additions and 64 deletions.
  1. +52 −12 colormonster.ino
  2. +52 −52 ui.h
  3. BIN ui/paint.png
@@ -1,4 +1,5 @@
#include <TinyScreen.h>
#include "SdFat.h"
#include <SPI.h>
#include <Wire.h>
#include "TinyConfig.h"
@@ -14,6 +15,9 @@
TinyScreen display = TinyScreen(TinyScreenPlus);
SdFat sd;
SdFile dataFile;
#define STATE_PAINT 0
#define STATE_PAINTZOOM 1
@@ -27,11 +31,12 @@ int joystickCoolDown = 0;
class ColorMonster
{
public:
ColorMonster() { memset(img, 0, 64*48*2); }
ColorMonster() : saved(false) { memset(img, 0, 64*48*2); }
void initImage(const unsigned char *bi);
unsigned char img[64*48*2];
const unsigned char *baseImg;
bool saved;
};
void ColorMonster::initImage(const unsigned char *bi)
@@ -115,6 +120,7 @@ void Painter::update()
if ((btn & TAButton1) && (px < 48))
{
buttonCoolDown = BUTTON_COOLDOWN;
active->saved = false;
uint8_t dx;
uint8_t dy;
if (STATE_PAINT == state)
@@ -148,22 +154,39 @@ void Painter::update()
}
}
}
else if ((btn & TAButton1) && (px > 51) && (py > 19) && (py < 62))
else if ((btn & TAButton1) && (px > 50) && (py > 19) && (py < 62))
{
color1 = _image_paint_data[(py * 48 + (px - 48)) * 2];
color2 = _image_paint_data[(py * 48 + (px - 48)) * 2 + 1];
buttonCoolDown = BUTTON_COOLDOWN;
}
else if ((btn & TAButton1) && (px > 51) && (px < 68) && (py > 1) && (py < 18))
else if ((btn & TAButton1) && (px > 50) && (px < 68) && (py > 1) && (py < 18))
{
tool = TOOL_DRAW;
buttonCoolDown = BUTTON_COOLDOWN;
}
else if ((btn & TAButton1) && (px > 75) && (px < 92) && (py > 1) && (py < 18))
else if ((btn & TAButton1) && (px > 70) && (px < 87) && (py > 1) && (py < 18))
{
tool = TOOL_FLOOD;
buttonCoolDown = BUTTON_COOLDOWN;
}
else if ((btn & TAButton1) && (px > 88) && (px < 95) && (py > 1) && (py < 18))
{
if (!active->saved)
{
if (!dataFile.open("colormn1.dat", O_WRITE | O_CREAT | O_TRUNC))
{
}
else
{
dataFile.write(active->img, 64*48*2);
dataFile.sync();
dataFile.close();
active->saved = true;
}
}
buttonCoolDown = BUTTON_COOLDOWN;
}
if ((btn & TAButton2) && (px < 48))
{
if (state == STATE_PAINT)
@@ -214,15 +237,15 @@ void Painter::draw()
{
if (tool == TOOL_DRAW)
{
for (int i = (48 + 3) * 2; i < (48 + 20) * 2; i += 2)
for (int i = (48 + 2) * 2; i < (48 + 20) * 2; i += 2)
{
lineBuffer[i] = color1;
lineBuffer[i + 1] = color2;
}
}
else if (tool == TOOL_FLOOD)
{
for (int i = (48 + 27) * 2; i < (48 + 45) * 2; i += 2)
for (int i = (48 + 22) * 2; i < (48 + 40) * 2; i += 2)
{
lineBuffer[i] = color1;
lineBuffer[i + 1] = color2;
@@ -233,17 +256,17 @@ void Painter::draw()
{
if (tool == TOOL_DRAW)
{
lineBuffer[(48 + 3) * 2] = color1;
lineBuffer[(48 + 3) * 2 + 1] = color2;
lineBuffer[(48 + 2) * 2] = color1;
lineBuffer[(48 + 2) * 2 + 1] = color2;
lineBuffer[(48 + 19) * 2] = color1;
lineBuffer[(48 + 19) * 2 + 1] = color2;
}
else if (tool == TOOL_FLOOD)
{
lineBuffer[(48 + 27) * 2] = color1;
lineBuffer[(48 + 27) * 2 + 1] = color2;
lineBuffer[(48 + 44) * 2] = color1;
lineBuffer[(48 + 44) * 2 + 1] = color2;
lineBuffer[(48 + 22) * 2] = color1;
lineBuffer[(48 + 22) * 2 + 1] = color2;
lineBuffer[(48 + 39) * 2] = color1;
lineBuffer[(48 + 39) * 2 + 1] = color2;
}
}
if ((lines >= py) && (lines < py + 8))
@@ -284,7 +307,24 @@ void setup()
#endif
SerialUSB.begin(9600);
active->initImage(_image_cateye_data);
if (!sd.begin(10,SPI_FULL_SPEED)) {
SerialUSB.println("Card failed");
while(1);
}
lastTime = millis();
if (sd.exists("colormn1.dat"))
{
if (!dataFile.open("colormn1.dat", O_READ))
{
}
else
{
int sz = dataFile.write(active->img, 64*48*2);
dataFile.read(active->img, 64*48*2);
dataFile.sync();
dataFile.close();
}
}
}
void loop()
Oops, something went wrong.

0 comments on commit e92a337

Please sign in to comment.