fix memory leak in layout.cpp
This commit is contained in:
parent
6af3988056
commit
806fc7c3e5
5 changed files with 31 additions and 26 deletions
6
Makefile
6
Makefile
|
@ -14,9 +14,13 @@ lib/libssd1306.a:
|
||||||
@mkdir -p lib
|
@mkdir -p lib
|
||||||
@cp deps/ssd1306/bld/libssd1306.a lib/libssd1306.a
|
@cp deps/ssd1306/bld/libssd1306.a lib/libssd1306.a
|
||||||
|
|
||||||
flash:
|
flash: avr
|
||||||
@make -f avr.Makefile flash
|
@make -f avr.Makefile flash
|
||||||
|
|
||||||
|
run: linux
|
||||||
|
@make -f linux.Makefile run
|
||||||
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -r build
|
@rm -r build
|
||||||
@echo clean all
|
@echo clean all
|
||||||
|
|
|
@ -42,3 +42,7 @@ $(OBJDIR):
|
||||||
clean:
|
clean:
|
||||||
@$(REMOVEDIR) "$(OBJDIR)"
|
@$(REMOVEDIR) "$(OBJDIR)"
|
||||||
@echo clean $(OBJDIR)
|
@echo clean $(OBJDIR)
|
||||||
|
|
||||||
|
run: $(OBJDIR)/$(TARGET)
|
||||||
|
@echo run $(OBJDIR)/$(TARGET)
|
||||||
|
@$(OBJDIR)/$(TARGET)
|
||||||
|
|
|
@ -46,6 +46,8 @@ int layout::expand_(int packedsize) {
|
||||||
if (size > slots[i].content->maxsize)
|
if (size > slots[i].content->maxsize)
|
||||||
size = slots[i].content->maxsize;
|
size = slots[i].content->maxsize;
|
||||||
slots[i].size_ = size;
|
slots[i].size_ = size;
|
||||||
|
if(slots[i].canvas_)
|
||||||
|
delete slots[i].canvas_;
|
||||||
slots[i].canvas_ = new canvas(size, maxheight_);
|
slots[i].canvas_ = new canvas(size, maxheight_);
|
||||||
pos += size;
|
pos += size;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,15 +9,11 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <hal/hal.h>
|
#include <hal/hal.h>
|
||||||
|
|
||||||
uint8_t *canvasData;
|
uint8_t canvasData[128 * (32 / 8)];
|
||||||
NanoCanvas *canvas;
|
NanoCanvas canvas(128, 32, canvasData);
|
||||||
|
|
||||||
void hal_init_screen(int w, int h) {
|
void hal_init_screen(int w, int h) {
|
||||||
ssd1306_128x32_i2c_init();
|
ssd1306_128x32_i2c_init();
|
||||||
ssd1306_fillScreen( 0x00 );
|
|
||||||
canvasData = new uint8_t[w * (h / 8)];
|
|
||||||
canvas = new NanoCanvas(w, h, canvasData);
|
|
||||||
canvas.clear();
|
|
||||||
|
|
||||||
DDRD = 0;
|
DDRD = 0;
|
||||||
PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5);
|
PORTD |= (1 << PC2) | (1 << PC3) | (1 << PC4) | (1 << PC5);
|
||||||
|
@ -31,17 +27,16 @@ void hal_draw(int x, int y){
|
||||||
void hal_poll_input(bool *ptr) {
|
void hal_poll_input(bool *ptr) {
|
||||||
int in = PIND & 0x3c;
|
int in = PIND & 0x3c;
|
||||||
|
|
||||||
ptr[0] = in & (1 << PC2);
|
ptr[0] = !(in & (1 << PC2));
|
||||||
ptr[1] = in & (1 << PC3);
|
ptr[1] = !(in & (1 << PC3));
|
||||||
ptr[2] = in & (1 << PC4);
|
ptr[2] = !(in & (1 << PC4));
|
||||||
ptr[3] = in & (1 << PC5);
|
ptr[3] = !(in & (1 << PC5));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void hal_render() {
|
void hal_render() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
canvas.clear();
|
ssd1306_fillScreen( 0x00 );
|
||||||
render();
|
render();
|
||||||
canvas.blt(0, 0);
|
canvas.blt(0, 0);
|
||||||
}
|
}
|
||||||
|
|
26
src/main.cpp
26
src/main.cpp
|
@ -31,19 +31,17 @@ int main() {
|
||||||
|
|
||||||
root = new menu("",
|
root = new menu("",
|
||||||
new menu("foo",
|
new menu("foo",
|
||||||
new menu("bar",
|
new menu("baz",
|
||||||
new menu("baz",
|
new fooValue("I", 5),
|
||||||
new fooValue("I", 5),
|
new fooValue("II", 5),
|
||||||
new fooValue("II", 5),
|
new fooValue("III", 5),
|
||||||
new fooValue("III", 5),
|
new fooValue("IIII", 5)
|
||||||
new fooValue("IIII", 5)
|
),
|
||||||
),
|
new menu("peng",
|
||||||
new menu("peng",
|
new fooValue("o", 5),
|
||||||
new fooValue("o", 5),
|
new fooValue("oo", 5),
|
||||||
new fooValue("oo", 5),
|
new fooValue("o o", 5)
|
||||||
new fooValue("o o", 5)
|
),
|
||||||
)
|
|
||||||
),
|
|
||||||
new menu("x",
|
new menu("x",
|
||||||
new fooValue("x x", 5),
|
new fooValue("x x", 5),
|
||||||
new fooValue("xxx", 5)
|
new fooValue("xxx", 5)
|
||||||
|
@ -93,6 +91,8 @@ void buttons::onPush(int id, bool state) {
|
||||||
l.cursor = c;
|
l.cursor = c;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case I_UP:
|
||||||
|
break;
|
||||||
case I_RIGHT:
|
case I_RIGHT:
|
||||||
c = l.cursor;
|
c = l.cursor;
|
||||||
if (c = c->getCursor()) {
|
if (c = c->getCursor()) {
|
||||||
|
|
Loading…
Reference in a new issue