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

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
Show changes
Commits on Source (3)
#define _POSIX_C_SOURCE 200809
#include "epicardium.h" #include "epicardium.h"
#include "modules/log.h" #include "modules/log.h"
...@@ -13,6 +14,7 @@ ...@@ -13,6 +14,7 @@
#include "timers.h" #include "timers.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -170,28 +172,62 @@ void wsf_ble_signal_event(void) ...@@ -170,28 +172,62 @@ void wsf_ble_signal_event(void)
} }
/*************************************************************************************************/ /*************************************************************************************************/
#define BLEMAXCFGBYTES 100 #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"); int bleConfigFile = epic_file_open("ble.txt", "r");
if (bleConfigFile < 0) { if (bleConfigFile < 0) {
LOG_INFO("ble", "can not open ble.txt -> BLE is not started"); LOG_INFO("ble", "can not open ble.txt -> BLE is not started");
epic_file_close(bleConfigFile); return bleConfigFile;
return false;
} }
char cfgBuf[BLEMAXCFGBYTES + 1]; int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES - 1);
int readNum = epic_file_read(bleConfigFile, cfgBuf, BLEMAXCFGBYTES);
epic_file_close(bleConfigFile); epic_file_close(bleConfigFile);
if (readNum < 0) { if (readNum < 0) {
LOG_WARN("ble", "can not read ble.txt -> BLE is not started"); LOG_WARN("ble", "can not read ble.txt -> BLE is not started");
return false; return readNum;
} }
cfgBuf[readNum] = '\0'; cfgBuf[readNum] = '\0';
char bleActiveStr[] = "active=true"; str1 = cfgBuf;
cfgBuf[sizeof(bleActiveStr) - 1] = '\0'; 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."); LOG_INFO("ble", "BLE is disabled.");
return false; return false;
} else { } else {
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include <epicardium.h> #include <epicardium.h>
#include "modules/log.h" #include "modules/log.h"
#include "modules/modules.h"
#include "util/bstream.h" #include "util/bstream.h"
#include "att_api.h" #include "att_api.h"
...@@ -407,10 +408,25 @@ static attsGroup_t fileTransCfgGroup = { ...@@ -407,10 +408,25 @@ static attsGroup_t fileTransCfgGroup = {
.endHandle = FILE_TRANS_END_HDL, .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. * This registers and starts the BLE file transfer service.
*/ */
void bleFileTransfer_init(void) void bleFileTransfer_init(void)
{ {
if (ble_fileTrans_start()) {
AttsAddGroup(&fileTransCfgGroup); 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); ...@@ -66,6 +66,7 @@ int pmic_read_amux(enum pmic_amux_signal sig, float *result);
void vBleTask(void *pvParameters); void vBleTask(void *pvParameters);
bool ble_shall_start(void); bool ble_shall_start(void);
void ble_uart_write(uint8_t *pValue, uint8_t len); 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 ---------------------------------- */ /* ---------- Hardware (Peripheral) Locks ---------------------------------- */
void hwlock_init(void); void hwlock_init(void);
......
import os import os
import display import display
import utime import simple_menu
import buttons
CONFIG_NAME = "ble.txt" CONFIG_NAME = "ble.txt"
MAC_NAME = "mac.txt" MAC_NAME = "mac.txt"
ACTIVE_STRING = "active=true" BLE="active"
INACTIVE_STRING = "active=false" BLE_FILETRANS="fileTrans"
ENABLE = "true"
DISABLE = "false"
def init():
if CONFIG_NAME not in os.listdir("."): MENU = {
with open(CONFIG_NAME, "w") as f: BLE: {
f.write(INACTIVE_STRING) "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(): def load_mac():
if MAC_NAME in os.listdir("."): if MAC_NAME in os.listdir("."):
with open(MAC_NAME) as f: with open(MAC_NAME) as f:
return f.read().strip() return f.read().strip()
def init():
def triangle(disp, x, y, left): if CONFIG_NAME not in os.listdir("."):
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
with open(CONFIG_NAME, "w") as f: with open(CONFIG_NAME, "w") as f:
f.write(content) f.write(BLE+"="+DISABLE)
f.write(BLE_FILETRANS+"="+ENABLE)
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
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() def save():
button_pressed = True with open(CONFIG_NAME, "w") as f:
init() f.write(BLE + "=" + MENU[BLE].value)
f.write(BLE_FILETRANS + "=" + MENU[BLE_FILETRANS].value)
while True:
disp.clear() class BLEMenu(simple_menu.Menu):
headline() color_1 = color.CAMPGREEN
v = buttons.read(buttons.TOP_RIGHT) color_2 = color.CAMPGREEN_DARK
if v == 0:
button_pressed = False def draw_entry(self, item, index, offset):
name = item if type(item) is str else item.name
if not button_pressed and v & buttons.TOP_RIGHT != 0: self.disp.print(
button_pressed = True " " + name + " " * 9,
toggle() posy=offset,
fg=self.color_text,
selector() bg=self.color_1 if index % 2 == 0 else self.color_2,
disp.update() )
utime.sleep(0.1) 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()