Local build works, remote build needs to be added
This commit is contained in:
commit
319136f3e7
|
@ -0,0 +1,6 @@
|
|||
lib
|
||||
deps
|
||||
build
|
||||
*.tmp
|
||||
*.bak
|
||||
*.a
|
|
@ -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:
|
||||
|
||||
<p align="center">
|
||||
<img src="https://mongoose-os.com/images/app1.gif" width="75%">
|
||||
</p>
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 2.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.2 KiB |
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<h1>Welcome to the empty project</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,56 @@
|
|||
author: Dirk Jahnke <dirk.jahnke@mailbox.org>
|
||||
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
|
|
@ -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 <stdio.h>
|
||||
#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 <Arduino.h>
|
||||
#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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue