Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • backslash
  • blinkisync-as-preload
  • ch3/api-speed-eval2
  • ch3/dual-core
  • ch3/genapi-refactor
  • ch3/leds-api
  • ch3/splashscreen
  • dualcore
  • freertos-btle
  • genofire/ble-follow-py
  • genofire/haule-ble-fs-deactive
  • genofire/leds_rgb_get_state
  • genofire/rockets-state
  • ios-workarounds
  • koalo/bhi160-works-but-dirty
  • koalo/factory-reset
  • koalo/wip/i2c-for-python
  • master
  • msgctl/faultscreen
  • msgctl/gfx_rle
  • msgctl/textbuffer_api
  • nickname-match-configs
  • plaetzchen/ios-workaround
  • rahix/bhi
  • rahix/bma
  • renze/hatchery_apps
  • renze/safe_mode
  • schleicher-test
  • schneider/ble-buffers
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • schneider/fundamental-test
  • schneider/max30001
  • schneider/max30001-epicaridum
  • schneider/max30001-pycardium
  • schneider/maxim-sdk-update
  • schneider/mp-for-old-bl
  • schneider/schleicher-test
  • schneider/stream-locks
  • bootloader-v1
  • release-1
  • v0.0
  • v1.0
  • v1.1
  • v1.2
  • v1.3
  • v1.4
  • v1.5
  • v1.6
  • v1.7
  • v1.8
  • v1.9
53 results

Target

Select target project
  • card10/firmware
  • annejan/firmware
  • astro/firmware
  • fpletz/firmware
  • gerd/firmware
  • fleur/firmware
  • swym/firmware
  • l/firmware
  • uberardy/firmware
  • wink/firmware
  • madonius/firmware
  • mot/firmware
  • filid/firmware
  • q3k/firmware
  • hauke/firmware
  • Woazboat/firmware
  • pink/firmware
  • mossmann/firmware
  • omniskop/firmware
  • zenox/firmware
  • trilader/firmware
  • Danukeru/firmware
  • shoragan/firmware
  • zlatko/firmware
  • sistason/firmware
  • datenwolf/firmware
  • bene/firmware
  • amedee/firmware
  • martinling/firmware
  • griffon/firmware
  • chris007/firmware
  • adisbladis/firmware
  • dbrgn/firmware
  • jelly/firmware
  • rnestler/firmware
  • mh/firmware
  • ln/firmware
  • penguineer/firmware
  • monkeydom/firmware
  • jens/firmware
  • jnaulty/firmware
  • jeffmakes/firmware
  • marekventur/firmware
  • pete/firmware
  • h2obrain/firmware
  • DooMMasteR/firmware
  • jackie/firmware
  • prof_r/firmware
  • Draradech/firmware
  • Kartoffel/firmware
  • hinerk/firmware
  • abbradar/firmware
  • JustTB/firmware
  • LuKaRo/firmware
  • iggy/firmware
  • ente/firmware
  • flgr/firmware
  • Lorphos/firmware
  • matejo/firmware
  • ceddral7/firmware
  • danb/firmware
  • joshi/firmware
  • melle/firmware
  • fitch/firmware
  • deurknop/firmware
  • sargon/firmware
  • markus/firmware
  • kloenk/firmware
  • lucaswerkmeister/firmware
  • derf/firmware
  • meh/firmware
  • dx/card10-firmware
  • torben/firmware
  • yuvadm/firmware
  • AndyBS/firmware
  • klausdieter1/firmware
  • katzenparadoxon/firmware
  • xiretza/firmware
  • ole/firmware
  • techy/firmware
  • thor77/firmware
  • TilCreator/firmware
  • fuchsi/firmware
  • dos/firmware
  • yrlf/firmware
  • PetePriority/firmware
  • SuperVirus/firmware
  • sur5r/firmware
  • tazz/firmware
  • Alienmaster/firmware
  • flo_h/firmware
  • baldo/firmware
  • mmu_man/firmware
  • Foaly/firmware
  • sodoku/firmware
  • Guinness/firmware
  • ssp/firmware
  • led02/firmware
  • Stormwind/firmware
  • arist/firmware
  • coon/firmware
  • mdik/firmware
  • pippin/firmware
  • royrobotiks/firmware
  • zigot83/firmware
  • mo_k/firmware
106 results
Select Git revision
  • add_menu_vibration
  • blinkisync-as-preload
  • ch3/api-speed-eval2
  • ch3/dual-core
  • ch3/genapi-refactor
  • ch3/leds-api
  • ch3/splashscreen
  • dualcore
  • dx/flatten-config-module
  • dx/meh-bdf-to-stm
  • freertos-btle
  • genofire/ble-follow-py
  • koalo/bhi160-works-but-dirty
  • koalo/factory-reset
  • koalo/wip/i2c-for-python
  • master
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • plaetzchen/ios-workaround
  • rahix/bhi
  • rahix/bluetooth-app-favorite
  • rahix/bma
  • rahix/user-space-ctx
  • renze/hatchery_apps
  • renze/safe_mode
  • schleicher-test
  • schneider/212-reset-hardware-when-entering-repl
  • schneider/ancs
  • schneider/ble-buffers
  • schneider/ble-central
  • schneider/ble-ecg-stream-visu
  • schneider/ble-fixes-2020-3
  • schneider/ble-mini-demo
  • schneider/ble-stability
  • schneider/ble-stability-new-phy
  • schneider/bonding
  • schneider/bonding-fail-if-full
  • schneider/bootloader-update-9a0d158
  • schneider/deepsleep
  • schneider/deepsleep2
  • schneider/deepsleep4
  • schneider/default-main
  • schneider/freertos-list-debug
  • schneider/fundamental-test
  • schneider/iaq-python
  • schneider/ir
  • schneider/max30001
  • schneider/max30001-epicaridum
  • schneider/max30001-pycardium
  • schneider/maxim-sdk-update
  • schneider/mp-exception-print
  • schneider/mp-for-old-bl
  • schneider/png
  • schneider/schleicher-test
  • schneider/sdk-0.2.1-11
  • schneider/sdk-0.2.1-7
  • schneider/sleep-display
  • schneider/spo2-playground
  • schneider/stream-locks
  • schneider/v1.17-changelog
  • bootloader-v1
  • release-1
  • v0.0
  • v1.0
  • v1.1
  • v1.10
  • v1.11
  • v1.12
  • v1.13
  • v1.14
  • v1.15
  • v1.16
  • v1.17
  • v1.18
  • v1.2
  • v1.3
  • v1.4
  • v1.5
  • v1.6
  • v1.7
  • v1.8
  • v1.9
82 results
Show changes
Commits on Source (3)
#define _POSIX_C_SOURCE 200809
#include "epicardium.h"
#include "modules/log.h"
......@@ -13,6 +14,7 @@
#include "timers.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
......@@ -170,28 +172,62 @@ void wsf_ble_signal_event(void)
}
/*************************************************************************************************/
#define BLEMAXCFGBYTES 100
bool ble_shall_start(void)
int ble_get_option(const char *name, char *buf, size_t buf_len)
{
char *saveptr1, *saveptr2;
char *token, *str1, *name_parsed, *option;
char cfgBuf[BLEMAXCFGBYTES + 1];
int bleConfigFile = epic_file_open("ble.txt", "r");
if (bleConfigFile < 0) {
LOG_INFO("ble", "can not open ble.txt -> BLE is not started");
epic_file_close(bleConfigFile);
return false;
return bleConfigFile;
}
char cfgBuf[BLEMAXCFGBYTES + 1];
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES);
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES - 1);
epic_file_close(bleConfigFile);
if (readNum < 0) {
LOG_WARN("ble", "can not read ble.txt -> BLE is not started");
return false;
return readNum;
}
cfgBuf[readNum] = '\0';
char bleActiveStr[] = "active=true";
cfgBuf[sizeof(bleActiveStr) - 1] = '\0';
str1 = cfgBuf;
while (TRUE) {
token = strtok_r(str1, "\n", &saveptr1);
if (token == NULL)
break;
str1 = NULL;
name_parsed = strtok_r(token, "=", &saveptr2);
if (name_parsed == NULL)
continue;
if (strcmp(token, name_parsed) != 0)
continue;
option = strtok_r(NULL, "=", &saveptr2);
if (option == NULL)
return -ENOENT;
strncpy(buf, option, buf_len - 1);
buf[buf_len - 1] = '\0';
return 0;
}
return -ENOENT;
}
bool ble_shall_start(void)
{
char buf[10];
int ret;
ret = ble_get_option("active", buf, sizeof(buf));
if (ret) {
LOG_INFO("ble", "BLE is disabled.");
return false;
}
if (strcmp(cfgBuf, "active=true") != 0) {
if (strcmp(buf, "true") != 0) {
LOG_INFO("ble", "BLE is disabled.");
return false;
} else {
......
......@@ -34,6 +34,7 @@
#include <epicardium.h>
#include "modules/log.h"
#include "modules/modules.h"
#include "util/bstream.h"
#include "att_api.h"
......@@ -407,10 +408,25 @@ static attsGroup_t fileTransCfgGroup = {
.endHandle = FILE_TRANS_END_HDL,
};
bool ble_fileTrans_start(void)
{
char buf[10];
int ret;
/* if the option is not there activate it for now */
ret = ble_get_option("fileTrans", buf, sizeof(buf));
if (ret)
return true;
return !strcmp(buf, "true");
}
/*
* This registers and starts the BLE file transfer service.
*/
void bleFileTransfer_init(void)
{
if (ble_fileTrans_start()) {
AttsAddGroup(&fileTransCfgGroup);
LOG_INFO("ble", "BLE fileTransfer is enabled.");
} else
LOG_INFO("ble", "BLE fileTransfer is disabled.");
}
......@@ -66,6 +66,7 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result);
void vBleTask(void *pvParameters);
bool ble_shall_start(void);
void ble_uart_write(uint8_t *pValue, uint8_t len);
int ble_get_option(const char *name, char *buf, size_t buf_len);
/* ---------- Hardware (Peripheral) Locks ---------------------------------- */
void hwlock_init(void);
......
import os
import display
import utime
import buttons
import simple_menu
CONFIG_NAME = "ble.txt"
MAC_NAME = "mac.txt"
ACTIVE_STRING = "active=true"
INACTIVE_STRING = "active=false"
def init():
if CONFIG_NAME not in os.listdir("."):
with open(CONFIG_NAME, "w") as f:
f.write(INACTIVE_STRING)
BLE="active"
BLE_FILETRANS="fileTrans"
ENABLE = "true"
DISABLE = "false"
MENU = {
BLE: {
"name:":"Active",
"value":False,
"run": lambda: toggle(BLE),
},
BLE_FILETRANS: {
"name":"FileTransfer",
"value": False,
"run": lambda: toggle(BLE),
},
"__save__": {
"name": "Save",
"run": lambda: save() os.reset(),
}
}
def load_mac():
if MAC_NAME in os.listdir("."):
with open(MAC_NAME) as f:
return f.read().strip()
def triangle(disp, x, y, left):
yf = 1 if left else -1
scale = 6
disp.line(x - scale * yf, int(y + scale / 2), x, y)
disp.line(x, y, x, y + scale)
disp.line(x, y + scale, x - scale * yf, y + int(scale / 2))
def toggle():
content = INACTIVE_STRING if is_active() else ACTIVE_STRING
def init():
if CONFIG_NAME not in os.listdir("."):
with open(CONFIG_NAME, "w") as f:
f.write(content)
disp.clear()
disp.print("resetting", posy=0, fg=[0, 255, 255])
disp.print("to toggle", posy=20, fg=[0, 255, 255])
disp.print("BLE state", posy=40, fg=[0, 255, 255])
disp.update()
os.reset()
def is_active():
with open(CONFIG_NAME, "r") as f:
state = f.readlines()[0]
if len(state) < len(ACTIVE_STRING):
return False
state = state[0 : len(ACTIVE_STRING)]
return state == ACTIVE_STRING
f.write(BLE+"="+DISABLE)
f.write(BLE_FILETRANS+"="+ENABLE)
def headline():
disp.print("BLE", posy=0, fg=[0, 255, 255])
if is_active():
disp.print("active", posy=20, fg=[0, 255, 0])
mac = load_mac()
if mac is not None:
disp.print(mac[9:], posy=60, fg=[0, 0, 255])
else:
disp.print("inactive", posy=20, fg=[255, 0, 0])
def load():
with open(CONFIG_NAME) as f:
for line in f.readlines():
key, value = line.split("=")
MENU[key].value = value == ENABLE,
def selector():
triangle(disp, 148, 46, False)
disp.print("toggle", posx=25, posy=40, fg=[255, 255, 255])
def toggle(key):
MENU[key].value = not MENU[key].value
disp = display.open()
button_pressed = True
init()
while True:
disp.clear()
headline()
v = buttons.read(buttons.TOP_RIGHT)
if v == 0:
button_pressed = False
if not button_pressed and v & buttons.TOP_RIGHT != 0:
button_pressed = True
toggle()
selector()
disp.update()
utime.sleep(0.1)
def save():
with open(CONFIG_NAME, "w") as f:
f.write(BLE + "=" + MENU[BLE].value)
f.write(BLE_FILETRANS + "=" + MENU[BLE_FILETRANS].value)
class BLEMenu(simple_menu.Menu):
color_1 = color.CAMPGREEN
color_2 = color.CAMPGREEN_DARK
def draw_entry(self, item, index, offset):
name = item if type(item) is str else item.name
self.disp.print(
" " + name + " " * 9,
posy=offset,
fg=self.color_text,
bg=self.color_1 if index % 2 == 0 else self.color_2,
)
if value in item:
self.disp.rect(
xs=-20, ys=offset,
xe=-4, ye=offset+18,
filled=True,
col=color.GREEN if item.value else color.RED
)
def on_select(self, item, index):
if type(item) is not str and "run" in item:
item.run()
if __name__ == "__main__":
BLEMenu([load_mac()]+MENU).run()