Compare commits

..

5 Commits

  1. BIN
      aseprite_c/graphics/flame.ico
  2. BIN
      aseprite_c/graphics/no_flame.ico
  3. 2
      main/analog.c
  4. 20
      main/app_main.c
  5. 14
      main/firehazard.c
  6. 60
      main/graphics/bitmaps.c
  7. 52
      main/graphics/drawing.c
  8. 28
      main/graphics/drawing.h
  9. 3
      main/liquid/gui.c
  10. 2
      main/scenes/scene_bootanim.c
  11. 17
      main/scenes/scene_manual_menu.c

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

@ -25,7 +25,7 @@ static void analog_service(void *arg);
static TaskHandle_t hAnalog;
#define DEFAULT_VREF 1100 // TODO try to find the exact value
#define DEFAULT_VREF 1095
#define NO_OF_SAMPLES 128
void analog_init() {

@ -101,6 +101,7 @@ void __attribute__((noreturn)) app_main()
tcpip_adapter_init();
initialise_wifi();
#if 0
// TODO add proper join procedure
const char *ssid = "Chlivek_2.4G";
const char *pass = "slepice123";
@ -113,6 +114,7 @@ void __attribute__((noreturn)) app_main()
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_disconnect() );
ESP_ERROR_CHECK( esp_wifi_connect() );
#endif
gui_init();
knob_init();
@ -122,24 +124,6 @@ void __attribute__((noreturn)) app_main()
websrv_init();
fire_init();
nvs_handle nvs;
ESP_ERROR_CHECK(nvs_open("config", NVS_READWRITE, &nvs)); // must use RW to allow opening nonexistent
union uf32 kp, ki, kd;
// TODO set good defaults
kp.f = 0.3f;
ki.f = 0.5f;
kd.f = 0.0f;
nvs_get_u32(nvs, "kp", &kp.u);
nvs_get_u32(nvs, "ki", &ki.u);
nvs_get_u32(nvs, "kd", &kd.u);
fire_set_tuning(kp.f, ki.f, kd.f);
nvs_close(nvs);
bool level = 0;
while (1) {
vTaskDelay(pdMS_TO_TICKS(1000));

@ -8,6 +8,7 @@
#include <nvs.h>
#include "driver/ledc.h"
#include "esp_err.h"
#include "utils.h"
static const char *TAG = "fire";
@ -29,7 +30,18 @@ void fire_init() {
PID_SetOutputLimits(&pid, 0, 1);
PID_SetCtlMode(&pid, PID_MANUAL);
PID_SetTunings(&pid, 0.3, 0.01, 0.1); // TODO load from nvs
nvs_handle nvs;
ESP_ERROR_CHECK(nvs_open("config", NVS_READWRITE, &nvs)); // must use RW to allow opening nonexistent
union uf32 kp, ki, kd;
kp.f = 0.4f;
ki.f = 0.5f;
kd.f = 0.0f;
nvs_get_u32(nvs, "kp", &kp.u);
nvs_get_u32(nvs, "ki", &ki.u);
nvs_get_u32(nvs, "kd", &kd.u);
PID_SetTunings(&pid, kp.f, ki.f, kd.f);
nvs_close(nvs);
pwm_init();
fire_setlevel(20);

@ -3,6 +3,60 @@
#include <string.h>
/* 24x24: no_flame */
// ··········██····█·······
// ···········██···██······
// ············██··········
// ············███·····█···
// ·······█····███····█····
// ·····██····█████··█···█·
// ····██···██████··█···█··
// ····█···██████··█···█···
// ···██··██████··█···█····
// ···█··██████··█···█·····
// ···█··█████··█···█······
// ······████··█···█·······
// ·······██··█···█··█··█··
// ··········█···█··██··██·
// ···█·····█···█··████··█·
// ··█·····█···█··█████····
// ··██···█···█··██████····
// ··██··█···█····█████····
// ·····█···█·····█████····
// ····█···█······█·███····
// ···█···█·········██·····
// ··█···█·········██······
// ·····█··██······█·······
// ····█··········█········
static const uint8_t G_NO_FLAME_BYTES[] = { 0x00, 0x00, 0x00, 0x00, 0xc0, 0x60, 0x20, 0x10, 0x80, 0xc0, 0xc1, 0xe3, 0xfe, 0xfc, 0x78, 0x20, 0x83, 0x42, 0x20, 0x10, 0x88, 0x40, 0x20, 0x00, 0x00, 0x00, 0x80, 0x47, 0x01, 0x00, 0x0e, 0x1f, 0x9f, 0x4f, 0x27, 0x13, 0x89, 0x44, 0x22, 0x91, 0xc8, 0xe4, 0xf2, 0xc1, 0x00, 0x30, 0x60, 0x00, 0x00, 0x00, 0x23, 0x13, 0x88, 0x44, 0x22, 0x11, 0x48, 0x44, 0x02, 0x01, 0x00, 0x00, 0x01, 0x8f, 0x67, 0x3f, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00 };
/* 24x24: flame */
// ··········██····█·······
// ···········██···██······
// ············██··········
// ············███·········
// ·······█····███·········
// ·····██····█████···█····
// ····██···███████··█·····
// ····█···███████··██·····
// ···██··████████·██······
// ···█··████████··██······
// ···█··████████·███······
// ······████████·████·····
// ·······████·███·███··█··
// ········███·███████··██·
// ···█·····██··███████··█·
// ··█·······██·███████····
// ··██·····███··██████····
// ··█████·████···█████····
// ···█████████···█████····
// ····██████·····█·███····
// ·····███·········██·····
// ······███·······██······
// ········██······█·······
// ···············█········
static const uint8_t G_FLAME_BYTES[] = { 0x00, 0x00, 0x00, 0x00, 0xc0, 0x60, 0x20, 0x10, 0x80, 0xc0, 0xc1, 0xe3, 0xfe, 0xfc, 0xf8, 0x60, 0x03, 0x82, 0xc0, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x47, 0x01, 0x00, 0x0e, 0x1f, 0x3f, 0x7f, 0xff, 0x8f, 0x3f, 0xff, 0xf1, 0xec, 0xff, 0xff, 0xf8, 0xc0, 0x00, 0x30, 0x60, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0e, 0x1e, 0x3e, 0x3c, 0x6e, 0x4f, 0x07, 0x07, 0x00, 0x00, 0x01, 0x8f, 0x67, 0x3f, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00 };
/* 84x48: boot_logo */
// ····················································································
// ·····································································████████·······
@ -55,17 +109,19 @@
static const uint8_t G_BOOT_LOGO_BYTES[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x20, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0x40, 0xc0, 0xc0, 0x40, 0xc0, 0xa0, 0xa0, 0x20, 0xa0, 0xa0, 0xe0, 0x60, 0xd0, 0x90, 0xd0, 0xd0, 0xf0, 0xf0, 0xc8, 0xe8, 0xe8, 0xb8, 0xb8, 0x64, 0xd4, 0xb4, 0x94, 0x9c, 0x14, 0x0c, 0x0c, 0x1c, 0x14, 0x34, 0x34, 0x34, 0x12, 0x1a, 0x0a, 0x0a, 0x06, 0x82, 0x82, 0x82, 0x44, 0x44, 0x28, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xc0, 0xc0, 0x60, 0x60, 0x60, 0x50, 0x30, 0x30, 0x38, 0x3c, 0x3c, 0x2c, 0x2c, 0x3c, 0x2e, 0x2e, 0x3e, 0x3e, 0x37, 0x3d, 0x2b, 0x3f, 0x3d, 0x2f, 0x3f, 0x3f, 0x5f, 0x4d, 0xad, 0x25, 0x16, 0x1d, 0x1f, 0x1e, 0x0a, 0x1b, 0x09, 0x0d, 0x04, 0x02, 0x03, 0x03, 0xc3, 0x43, 0x43, 0x43, 0xa5, 0x63, 0x23, 0x22, 0x21, 0x91, 0xd1, 0x31, 0x11, 0x08, 0x08, 0x28, 0x58, 0x2c, 0x04, 0x34, 0x1c, 0x16, 0x0a, 0x0a, 0x16, 0x0a, 0x05, 0x01, 0x04, 0x0b, 0x0f, 0x3c, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x09, 0x09, 0x10, 0x10, 0x10, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x38, 0xe8, 0x08, 0xf4, 0x4c, 0x32, 0x29, 0x10, 0x08, 0x00, 0x10, 0x48, 0x84, 0x02, 0x05, 0x02, 0x05, 0x02, 0x01, 0x00, 0x00, 0x02, 0x05, 0x82, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x60, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3c, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x80, 0x87, 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x08, 0x10, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x8c, 0xb0, 0xc0, 0x80, 0x40, 0x40, 0x20, 0x20, 0x20, 0x20, 0x20, 0x11, 0x16, 0x18, 0x30, 0x28, 0x08, 0x08, 0x08, 0x08, 0x04, 0x05, 0x06, 0x04, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0xa1, 0x41, 0xa1, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, 0x0f, 0x10, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x05, 0x06, 0x02, 0x02, 0x02, 0x01, 0x01, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x02, 0x07, 0x02, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x20, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x7f, 0x44, 0x44, 0x44, 0x2b, 0x10, 0x00, 0x02, 0xff, 0x19, 0x29, 0x29, 0x49, 0x49, 0xc6, 0x04, 0x0a, 0x09, 0x3f, 0x49, 0x49, 0x49, 0x49, 0x41, 0x21, 0x21, 0x00, 0x50, 0x38, 0x16, 0x11, 0x16, 0x18, 0x70, 0x40, 0x00, 0x21, 0x21, 0x3f, 0x21, 0x21, 0x11, 0x09, 0x06, 0x00, 0x0a, 0x09, 0x7f, 0x05, 0x05, 0x05, 0x05, 0x05, 0x00, 0x00, 0x1e, 0x21, 0x20, 0x20, 0x20, 0x20, 0x0e, 0x11, 0x20, 0x10, 0x09, 0x06, 0x00, 0x00, 0x00, 0x07, 0x18, 0x21, 0x1f, 0x08, 0x10, 0x20, 0x10, 0x0f, 0x00, 0x00, 0x00 };
static const struct BitmapImage bitmaps[] = {
{ .name="no_flame", .width=24, .height=24, .bytes=G_NO_FLAME_BYTES },
{ .name="flame", .width=24, .height=24, .bytes=G_FLAME_BYTES },
{ .name="boot_logo", .width=84, .height=48, .bytes=G_BOOT_LOGO_BYTES },
{}
};
const struct BitmapImage *Bitmap_Get(const char *name) {
const struct BitmapImage *ptr = &bitmaps[0];
const struct BitmapImage *ptr = bitmaps;
while (ptr->name) {
if (0 == strcmp(ptr->name, name)) {
return ptr;
}
ptr++;
}
return NULL;
}

@ -1,6 +1,7 @@
#include "drawing.h"
#include "display_spec.h"
#include "font.h"
#include "bitmaps.h"
extern uint8_t LCD_displayMap[LCD_WIDTH * LCD_HEIGHT / 8];
@ -231,17 +232,39 @@ static const int char_heights[] = {
// library. AND HEAVILY MODIFIED
void LCD_setStrEx(const char *dString, int x, int y, enum Color color, struct TextStyle style)
{
const int x0 = x;
struct Utf8Char uchar;
struct Utf8Iterator iter;
Utf8Iterator_Init(&iter, dString);
int charw = char_widths[style.size];
int charh = char_heights[style.size];
int spacingx = char_spacings[style.size] + style.spacing_x;
int spacingy = style.spacing_y;
struct Utf8Char uchar;
if (style.align != ALIGN_LEFT) {
int line_len = 0;
int skip = style.skip;
while ((uchar = Utf8Iterator_Next(&iter)).uint) {
if (skip > 0) {
skip -= 1;
continue;
}
if (uchar.bytes[0] == '\n') {
break;
}
line_len++;
}
if (style.align == ALIGN_CENTER) {
x -= ((charw + spacingx) * line_len) / 2 - spacingx/2;
} else {
// right
x -= ((charw + spacingx) * line_len) - spacingx;
}
}
const int x0 = x;
Utf8Iterator_Init(&iter, dString);
int limit = style.limit;
int skip = style.skip;
bool wrap;
@ -292,13 +315,32 @@ void LCD_setStrEx(const char *dString, int x, int y, enum Color color, struct Te
// This function will draw an array over the screen. (For now) the
// array must be the same size as the screen, covering the entirety
// of the display.
void LCD_setBitmap(const uint8_t *bitArray)
void LCD_setBitmapFullScreen(const uint8_t *bitArray)
{
for (int i = 0; i < (LCD_WIDTH * LCD_HEIGHT / 8); i++) {
for (int i = 0; i < sizeof(LCD_displayMap); i++) {
LCD_displayMap[i] = bitArray[i];
}
}
void LCD_setBitmap(const struct BitmapImage *image, int x, int y, bool bg, enum Color color)
{
int byte_count = image->width * (image->height + 7) / 8;
for (int xi = 0; xi < image->width; xi++) {
for (int yi = 0; yi < image->height; yi++) {
int idx = xi + ((yi + 7) / 8) * image->width;
if (idx > byte_count) continue;
bool bit = image->bytes[idx] & (1 << yi);
if (bit) {
LCD_setPixel(x + xi, y + yi, color);
}
else if (bg) {
LCD_setPixel(x + xi, y + yi, !color);
}
}
}
}
// This function clears the entire display either white (0) or
// black (1).
// The screen won't actually clear until you call updateDisplay()!

@ -11,6 +11,7 @@
#include <stdbool.h>
#include "utf8.h"
#include "bitmaps.h"
enum Color {
WHITE = 0,
@ -34,7 +35,7 @@ void LCD_setRect(int x0, int y0, int x1, int y1, bool fill, enum Color bw);
// thickness ranging from 1 to the radius of the circle.
void LCD_setCircle (int x0, int y0, int radius, enum Color bw, int lineThickness);
void LCD_setBitmap(const uint8_t *bitArray);
void LCD_setBitmapFullScreen(const uint8_t *bitArray);
/*
FONT FUNCTIONS
@ -50,15 +51,22 @@ enum TextSize {
FONT_BOLD = 2,
};
enum TextAlign {
ALIGN_LEFT = 0,
ALIGN_CENTER = 1,
ALIGN_RIGHT = 2,
};
struct TextStyle {
bool bg; //!< Fill the characters background with the opposite color
enum TextSize size; //!< Character size
int limit; //!< Number of characters to print from the string, if > 0
int skip; //!< Characters to skip before printing
int spacing_x; //!< Additional X spacing
int spacing_y; //!< Additional Y spacing
bool nowrap; //!< Stop painting when the right edge of the screen is reached
bool wrap_to_0; //!< wrap to 0 instead of the initial X coordinate
bool bg; //!< Fill the characters background with the opposite color
enum TextSize size; //!< Character size
enum TextAlign align; //!< Alignment (works only for single line)
int limit; //!< Number of characters to print from the string, if > 0
int skip; //!< Characters to skip before printing
int spacing_x; //!< Additional X spacing
int spacing_y; //!< Additional Y spacing
bool nowrap; //!< Stop painting when the right edge of the screen is reached
bool wrap_to_0; //!< wrap to 0 instead of the initial X coordinate
};
// setStr draws a string of characters, calling setChar with
@ -77,4 +85,6 @@ void LCD_clearDisplay(enum Color bw);
/* Invert colors (hard change in data; does NOT send to display immediately) */
void LCD_invertDisplayData();
void LCD_setBitmap(const struct BitmapImage *image, int x, int y, bool bg, enum Color color);
#endif //LCD_DRAWING_H

@ -1,8 +1,6 @@
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/timers.h>
#include "gui.h"
#include "nokia.h"
#include "liquid.h"
#include "drawing.h"
@ -27,7 +25,6 @@ void gui_init() {
* 0b10 - knowb CCW
* 0b100 - button released
* 0b1000 - button pressed
* 0b10000 - ticker event
*
* @param arg
*/

@ -24,7 +24,7 @@ static struct SceneEvent onTick(struct BootScene *self, uint32_t millis) {
static void paint(struct BootScene *self)
{
LCD_clearDisplay(0);
LCD_setBitmap(Bitmap_Get("boot_logo")->bytes);
LCD_setBitmapFullScreen(Bitmap_Get("boot_logo")->bytes);
}
struct Scene *NewScene_Boot(void) {

@ -2,9 +2,10 @@
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <analog.h>
#include <firehazard.h>
#include "analog.h"
#include "firehazard.h"
#include "graphics/bitmaps.h"
#include "liquid.h"
#include "graphics/drawing.h"
#include "graphics/display_spec.h"
@ -74,15 +75,17 @@ static void paint(struct MenuScene *self)
char buf[10];
sprintf(buf, "%.0f", analog_read());
// TODO centering
LCD_setStrEx(buf, 0, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE});
LCD_setStrEx("°C", 0, 17, BLACK, (struct TextStyle) {.size = FONT_BOLD});
LCD_setStrEx(buf, XLINE/2, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE, .align = ALIGN_CENTER});
LCD_setStrEx("°C", XLINE/2, 17, BLACK, (struct TextStyle) {.align = ALIGN_CENTER}); //.size = FONT_BOLD,
const struct BitmapImage *img;
if (fire_enabled()) {
strcpy(buf, "RUN");
img = Bitmap_Get("flame");
} else {
strcpy(buf, "Off");
img = Bitmap_Get("no_flame");
}
LCD_setStrEx(buf, 0, 30, BLACK, (struct TextStyle) {.size = FONT_BOLD});
LCD_setBitmap(img, XLINE/2-24/2, 26, false, BLACK);
priv->basePaint((struct Scene *) self);
}

Loading…
Cancel
Save