From 319136f3e7690954c763d33a5911bf5188231d1b Mon Sep 17 00:00:00 2001 From: Dirk Jahnke Date: Mon, 22 Jan 2018 13:21:36 +0100 Subject: [PATCH] Local build works, remote build needs to be added --- .gitignore | 6 ++ README.md | 15 ++++ fs/fremo.gif | Bin 0 -> 2196 bytes fs/fremo64.gif | Bin 0 -> 2246 bytes fs/index.html | 5 ++ mos.yml | 56 ++++++++++++++ src/main.cpp | 194 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 276 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 fs/fremo.gif create mode 100644 fs/fremo64.gif create mode 100644 fs/index.html create mode 100644 mos.yml create mode 100644 src/main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5a80db6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +lib +deps +build +*.tmp +*.bak +*.a diff --git a/README.md b/README.md new file mode 100644 index 0000000..e04e7a5 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# A test app for Mongoose and SSD1306 (variant for Wemos 64x48 OLED display) + +## Overview + +This is a simple app using the C interface only to create some content on the OLED display. + +## How to install this app + +- Install and start [mos tool](https://mongoose-os.com/software.html) +- Switch to the Project page, find and import this app, build and flash it: + +

+ +

+ diff --git a/fs/fremo.gif b/fs/fremo.gif new file mode 100644 index 0000000000000000000000000000000000000000..88a2c259cc9bc9647c0d26f4c159be17f42f5de8 GIT binary patch literal 2196 zcmV;F2y6F8Nk%w1VW0qH0HOc@zrVkgm6hY;<85tiN=iy6Cno>^0RR90A^8LV00000 zEC2ui0H6S5000C3c)HyFFv>}*y*TU5yZ>M)j$~<`XsWJk>%Q!1rYQhx?TIw0&qG@7*xgh2*CSO zGt@r^1zQ9K1O{6J1vWE=i)#UEehYDYZFzZdIRTRjoC1S_h-L?M2VSQIfdU3fgl3O5 zotkEym@xvD4SQRmkA(%Qrvs-1rDj{2p@#-)zy!8?b+)%F(ww`&18AnGHvtC5iUX~s zs>EIZ!j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p6*5-oZ-vlEKQTf7rgW%-Du2Y{z7|TT z00je(g6WlVK#`hw4xyM1X$C6(2-0JA^hQzx5e!xFG{FQ^PQB4fFt{g}a@OpncZ$`7 z`X)1pu&*gJLc?ETcb=gF3#e;)6N8SIi+8G_N*57QDQsegz{F=aM+~c2$12ve<>wR> z1jtHhxK0_o2Mx))&?VB7obEJ0B1ToiL@}eBp|NMF<97FYg& zJ^$zfFnD?zBZf7BW{C>l-T?)#qSw3^$jBdlz=+ram_6)?!xKnigDr$32+jrDN4p1I z2+zn19$L#H@sl;}BO3Np~W&2(!@>RI~uio4LRTL3<)u4kN}~8!FNYwT2`ihK3B52YsmG z($@(kfomITAPb2G=LnGjGNt`98)V#b7j!_zsILIuDY$|OJK;$b|&cZ0RTJgZs8aJ literal 0 HcmV?d00001 diff --git a/fs/fremo64.gif b/fs/fremo64.gif new file mode 100644 index 0000000000000000000000000000000000000000..7af41ee5c6408d597468ab2f464b50713e075b33 GIT binary patch literal 2246 zcmds$`9IT-1IKsSX0Er~_b!=OUv#0;Ff&9;CCaz9kmEDirh{~BGt4A&rjiUDq+BZ! zwXt$%lSHY;x8$lQl`efBegBN_>-BiNetQ1$dOTh)Uq6bg8-oNQfWCqL3JeBAAP^`N z3WLFPb#(y%(AU>DFfcGOGBPnSv9hwVwzkIMaCkhPKp;3cIJmgDtY5$0!^6YJ$A?O# z1_T5I1_sh-v|YP)?cTjREG%sA-o4@B;rsUO+rNK5ola*k7zYjeZ{)u3f9Ds;aK8zH#G5O-;?sn>TOWx>Z|S zTUS?CUtizQ(9qb}D3wZY-@bk4&Yh;Frsn46yLa!lw6xs2cdxazwXLn~{{8z89z2lA zWOBK@y}iAoqeG!kJbd`@(W6J5ot<4>UEST?Jv}|Wy}f;Xef|CYj~_oC7#L70l`55L zaB%R+lP5z%Lrfzr{`_w#|A&G34uk!zh54i97te@} z3S>mbM*O22&4`a@Y<60`cHLit9RDJJ9|J-zgAz0?sdZ)YRHVVG@Gd9D&D~eYX%|fW z3#xYCHjf*N5r|ZU?Up|$ zmP2r7bDUTsiTekt$a!kxB1W5G)4~5#&^jeE2ccf#1aJ?VGna|pg1s9SYIs6a|PTM-ro)e;fttPM58I$ z&r}Q)2rZr0MG0+Im&*%0Yj)DhGmXlk#r82QSFw#??K+V~t+rHX`P@p-1KU{S>KTD( z8+?R?wl$=mbeYcWCS9x>_xGwG1Gbs^XYyzcOr{HMr7p)1WvP}A!U-se7asyHHswO_ zv`l~yzcx(E@%ZT(+HOh>5VrD|$(l&AAiAtJm58c-Icq&k~M~eL|U$1o}Rvmq~1eN$6Himd%!! z@iZWx1QD1)3KzWbO>f4@hWoB_0*LJE$y&rH^(f8pED+O;hD zc#vn!M?3pEuGD>i z-&lJOf-+UsZP&!ChnRE9xC){V6GO8#FX8lJv$YrD6_zQEKo`Vz0&K)WM#8nTnrRum zxWn}VoN0*NAZ)DSImb6=!kf?8luiWZXlBz_ufjg>8GFhZM4hO)Sb7H+1q8O%5_24?Q1 z)(Dh&{@dkzt|f=dcX!0bmt zOb)Rbk^>PS6)~92gII#Vn#c;%P9Ya+sD>Q9r(vs53cV^pu%x8z;HbgN>)||PEL9Ng zI=;ncX(5NJU5Rya)(Ywx*UdLoXhouhlse1~W>}g9l9#bE354VVsTPwgO#>H&(K&Id z1&SxMyRJs&00N7z-WH)F4BbK{)Wib~-vVpb8!^+h4+Uq1Dj>!+=(Lq328b;rtl@!q zlHPSdQ%PrS6f-*TraXa-l7w(fhV6O-%GfY8uA9JxS}i&ueMZ2#;$prhjDYFlxp()_gJga*KPtM zuyj815Rj=&S8GtkJe`s&8Jm7dbWVh7kxhaP-22A$a%9h}KFJW + +

Welcome to the empty project

+ + diff --git a/mos.yml b/mos.yml new file mode 100644 index 0000000..69479cf --- /dev/null +++ b/mos.yml @@ -0,0 +1,56 @@ +author: Dirk Jahnke +description: Test app for SSD1306 small display and epaper display +version: 1.0 + +libs_version: ${mos.version} +modules_version: ${mos.version} +mongoose_os_version: ${mos.version} + +# Optional. List of tags for online search. +tags: + - c + +# List of files / directories with C sources. No slashes at the end of dir names. +sources: + - src + +# List of dirs. Files from these dirs will be copied to the device filesystem +filesystem: + - fs + +config_schema: + - ["i2c.enable", true] + - ["i2c.sda_gpio", 4] + - ["i2c.scl_gpio", 5] + +# List of libraries used by this app, in order of initialisation +libs: + - origin: https://github.com/mongoose-os-libs/ca-bundle + - origin: https://github.com/mongoose-os-libs/i2c + - origin: https://github.com/mongoose-os-libs/spi + - origin: https://github.com/mongoose-os-libs/http-server + - origin: https://github.com/mongoose-os-libs/rpc-loopback + - origin: https://github.com/mongoose-os-libs/rpc-mqtt + - origin: https://github.com/mongoose-os-libs/rpc-service-config + - origin: https://github.com/mongoose-os-libs/rpc-service-fs + - origin: https://github.com/mongoose-os-libs/rpc-service-gpio + - origin: https://github.com/mongoose-os-libs/rpc-service-i2c + - origin: https://github.com/mongoose-os-libs/rpc-service-ota + - origin: https://github.com/mongoose-os-libs/rpc-uart + - origin: https://github.com/mongoose-os-libs/wifi + + # - origin: https://github.com/mongoose-os-libs/arduino-compat + # - origin: https://github.com/mongoose-os-libs/arduino-wire + # - origin: https://github.com/mongoose-os-libs/arduino-spi + # - origin: https://github.com/mongoose-os-libs/arduino-adafruit-gfx + # - origin: ../libs/ssd1306dj + - name: ssd1306dj + + - origin: https://github.com/mongoose-os-libs/mjs + + +build_vars: + MGOS_ENABLE_ARDUINO_API: 1 + +# Used by the mos tool to catch mos binaries incompatible with this file format +manifest_version: 2017-05-18 diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..2208de4 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,194 @@ + +/* + * Copyright (c) 2014-2017 Cesanta Software Limited + * All rights reserved + */ + +#define USE_I2C true +#define USE_SPI false +#define SSD1306_64_48 + +#include +#include "common/platform.h" +#include "common/cs_file.h" +#include "mgos_app.h" +#include "mgos_gpio.h" +#include "mgos_sys_config.h" +#include "mgos_timers.h" +#include "mgos_hal.h" +#include "mgos_dlsym.h" +#include "mjs.h" + +#include +#include "Adafruit_SSD1306dj.h" + +#include "mgos_rpc.h" +#include "common/cs_dbg.h" +#include "common/json_utils.h" +#include "frozen/frozen.h" +#include "mgos_net.h" + +Adafruit_SSD1306 *d1 = nullptr, *d2 = nullptr; +static void timer_cb(void *arg); + +#define FREMO_LOGO_WIDTH 64 +#define FREMO_LOGO_HEIGHT 48 +const PROGMEM uint8_t fremo_logo[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x5A, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, + 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x06, 0x68, 0x99, 0x20, 0x00, 0x00, + 0x00, 0x80, 0x40, 0x4D, 0x5B, 0x86, 0x01, 0x00, 0x00, 0x20, 0x5A, 0x09, + 0x88, 0x36, 0x04, 0x00, 0x00, 0x00, 0x35, 0x50, 0x03, 0x94, 0x10, 0x00, + 0x00, 0x44, 0x82, 0x02, 0x40, 0x40, 0x21, 0x00, 0x00, 0xC1, 0x10, 0x00, + 0x00, 0x0C, 0x83, 0x00, 0x80, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x01, + 0x40, 0x00, 0x01, 0xF8, 0x3F, 0x80, 0x00, 0x02, 0x20, 0x40, 0x00, 0xFC, + 0x3F, 0x00, 0x02, 0x04, 0x00, 0x20, 0x00, 0xFC, 0x3F, 0x00, 0x04, 0x00, + 0x00, 0x10, 0x00, 0xFC, 0x3F, 0x00, 0x08, 0x00, 0x08, 0x08, 0x00, 0xFC, + 0x3F, 0x00, 0x10, 0x10, 0x04, 0x00, 0x00, 0xFE, 0x7F, 0x00, 0x00, 0x20, + 0x00, 0x02, 0x00, 0xFE, 0x7F, 0x00, 0x40, 0x00, 0x02, 0x01, 0x00, 0xFC, + 0x3F, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x00, 0x00, + 0x80, 0x00, 0x00, 0xC0, 0x03, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x01, 0xF8, 0xFD, 0xB8, 0x33, 0x0C, 0x0F, 0x80, + 0x40, 0x10, 0x11, 0x11, 0x62, 0xC4, 0x18, 0x00, 0x01, 0x50, 0x11, 0x91, + 0x50, 0x4E, 0x10, 0x02, 0x40, 0x70, 0xF0, 0xF0, 0x60, 0x44, 0x10, 0x82, + 0x01, 0x50, 0x90, 0x91, 0x82, 0x45, 0x10, 0x00, 0x40, 0x10, 0x10, 0x11, + 0x92, 0xC5, 0x18, 0x82, 0x01, 0x38, 0x38, 0xF9, 0xB1, 0x0E, 0x07, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, 0x00, 0x80, + 0x03, 0x00, 0x00, 0x01, 0x02, 0x00, 0x00, 0xC0, 0x01, 0x00, 0x00, 0x40, + 0x22, 0x01, 0x00, 0x80, 0x03, 0x00, 0x80, 0x04, 0x30, 0x02, 0x00, 0xC0, + 0x03, 0x00, 0x40, 0x26, 0x54, 0x00, 0x00, 0xE0, 0x0F, 0x00, 0x00, 0x24, + 0x08, 0x09, 0x00, 0xFC, 0x3F, 0x00, 0x90, 0x13, 0xC0, 0x01, 0xC0, 0xFF, + 0xFF, 0x07, 0x80, 0x02, 0x10, 0x23, 0xF0, 0xFF, 0xFF, 0x0F, 0xC4, 0x09, + 0x20, 0x4E, 0xB0, 0xBF, 0xFF, 0x07, 0x62, 0x04, 0x40, 0x10, 0x01, 0x00, + 0x00, 0x80, 0x10, 0x02, 0x80, 0x14, 0x04, 0x00, 0x00, 0x20, 0x14, 0x01, + 0x00, 0xB1, 0x20, 0x00, 0x00, 0x88, 0x8D, 0x00, 0x00, 0xC4, 0x82, 0x12, + 0xA0, 0xA0, 0x23, 0x00, 0x00, 0x08, 0x27, 0x40, 0x02, 0x08, 0x11, 0x00, + 0x00, 0x20, 0x9C, 0x06, 0xD0, 0x5A, 0x04, 0x00, 0x00, 0x80, 0xA0, 0x75, + 0x2F, 0x87, 0x01, 0x00, 0x00, 0x00, 0x04, 0x16, 0xF7, 0x20, 0x00, 0x00, + 0x00, 0x00, 0x70, 0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x99, + 0x2A, 0x00, 0x00, 0x00, }; + +static void printTextPattern(Adafruit_SSD1306 *d) { + d->setTextSize(1); + d->setTextColor(WHITE); + d->setCursor(0, 18); + d->printf("%s", "abcdefghijk"); + d->setCursor(0, 27); + d->printf("%s", "@+#$%[]|{}"); + d->setCursor(0, 36); + d->printf("%s", "ABCDEFGHIJK"); + // d->setCursor(0, 48); + // d->printf("%s", "01234567890"); + // d->display(); +} + +static void show_num(Adafruit_SSD1306 *d, const char *s, int i) { + d->clearDisplay(); + d->setTextSize(1); + d->setTextColor(WHITE); + // d->setCursor(0, 0); + // d->printf("%s", " "); + d->setCursor(0, 0); + d->printf("%s%d", s, i); + printTextPattern(d1); + // draw frame + d->writeFastVLine(d->width()-1, 0, d->height(), WHITE); + d->writeFastHLine(0, d->height()-1, d->width(), WHITE); + d->display(); +} + +static void show_msg(Adafruit_SSD1306 *d, const char *s) { + d->setTextSize(1); + d->setTextColor(WHITE); + // d->setCursor(0, 9); + // d->printf("%s", " "); + d->setCursor(0, 9); + d->printf("%s", s); + d->display(); +} + +static void print_message_handler(struct mg_rpc_request_info *ri, void *cb_arg, + struct mg_rpc_frame_info *fi, struct mg_str args) { + struct mbuf fb; + struct json_out out = JSON_OUT_MBUF(&fb); + + mbuf_init(&fb, 20); + + const char *msg = ""; + if (json_scanf(args.p, args.len, ri->args_fmt, &msg) == 1) { + json_printf(&out, "{result: %Q, msg: %Q}", "OK", msg); + } else { + json_printf(&out, "{error: %Q}", "num is required"); + } + + // mgos_gpio_toggle(LED_GPIO); + if (d1 != nullptr) show_msg(d1, msg); + + printf("msg = %s\n", msg); + + mg_rpc_send_responsef(ri, "%.*s", fb.len, fb.buf); + ri = NULL; + + mbuf_free(&fb); + + (void) cb_arg; + (void) fi; +} + + +void setup(void) { + // I2C + d1 = new Adafruit_SSD1306(4 /* RST GPIO */, Adafruit_SSD1306::RES_64_48); + + if (d1 != nullptr) { + d1->begin(SSD1306_SWITCHCAPVCC, 0x3c, true /* reset */); + d1->display(); + } + // set codepage correctly / apply bug fix + d1->cp437(true); + d1->setTextWrap(false); + + struct mg_rpc *c = mgos_rpc_get_global(); + mg_rpc_add_handler(c, "Display.Message", "{msg: %s}", print_message_handler, NULL); + + mgos_set_timer(1000 /* ms */, true /* repeat */, timer_cb, NULL); +} + +static void timer_cb(void *arg) { + static int i = 0, j = 0; + static int startupStep = 0; + + switch (startupStep) { + case 0: startupStep++; break; + case 1: + d1->clearDisplay(); + d1->drawBitmap(0, 0, fremo_logo, FREMO_LOGO_WIDTH, FREMO_LOGO_HEIGHT, BLACK, WHITE); + d1->display(); + startupStep++; + break; + case 2: startupStep++; break; + case 3: startupStep ++; break; + case 4: + d1->clearDisplay(); + show_msg(d1, "*Init´ed*"); + startupStep++; + break; + default: + show_num(d1, "i = ", i); + LOG(LL_INFO, ("i = %d, j = %d", i, j)); + if (i % 10 == 0) { + switch (i/10) { + case 1: show_msg(d1, "-> 1st dec"); break; + case 2: show_msg(d1, "-> 2nd dec"); break; + case 3: show_msg(d1, "-> 3rd dec"); break; + case 4: show_msg(d1, "-> 4th dec"); break; + default: show_msg(d1, "-> more .."); + } + } + i++; + j++; + } + + (void) arg; +} +