feat: config RTC from chrome.

This commit is contained in:
susabolca
2024-03-19 00:32:40 +08:00
parent 3358d5f582
commit fb995c2712
4 changed files with 100 additions and 13 deletions

View File

@@ -258,29 +258,29 @@ void EPD_SSD_Update(void)
obdCreateVirtualDisplay(&obd, EPD_WIDTH, EPD_HEIGHT, epd_buffer);
obdFill(&obd, 0, 0);
#if 0
// BLE dev name
extern void getBleAdvName(char* buf);
getBleAdvName(buf);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 0, 128, buf, 1);
#endif
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 2, 128, buf, 1);
#if 1
// battery voltage
uint32_t v = AONBatMonBatteryVoltageGet();
uint8_t t = EPD_2IN9_ReadTemp();
System_snprintf(buf, 32, "%3uc %u.%uv", t, INTFRAC_V(v), INTFRAC_mV(v)/100);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 210, 24, buf, 1);
#endif
System_snprintf(buf, 32, "%u.%uv", INTFRAC_V(v), INTFRAC_mV(v)/100);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_16, 256, 128, buf, 1);
// date
const char *wstr[]={"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
System_snprintf(buf, 32, "%u-%02u-%02u %s", 1900+l->tm_year, l->tm_mon+1, l->tm_mday, wstr[l->tm_wday]);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_24, 0, 24, buf, 1);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_24, 2, 22, buf, 1);
// temp
uint8_t t = EPD_2IN9_ReadTemp();
System_snprintf(buf, 32, "%3uc", t);
obdWriteStringCustom(&obd, (GFXfont *)&Dialog_plain_24, 240, 22, buf, 1);
// time
System_snprintf(buf, 32, "%02d:%02d", l->tm_hour, l->tm_min);
obdWriteStringCustom(&obd, (GFXfont *)&DSEG7_Classic_Regular_80, 8, 24+80+10, buf, 1);
obdWriteStringCustom(&obd, (GFXfont *)&DSEG7_Classic_Regular_80, 8, 24+80+5, buf, 1);
// endian and invent
for (int i=0; i<sizeof(epd_buffer); i++) {

View File

@@ -56,7 +56,7 @@ static gattAttribute_t EpdServiceAttrTbl[] =
// Epoch Characteristic Value
{
{ ATT_UUID_SIZE, EpdUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE | GATT_PERMIT_WRITE,
GATT_PERMIT_READ | GATT_PERMIT_WRITE,
0,
EpochVal
},

View File

@@ -343,6 +343,7 @@ static void SimpleBLEPeripheral_init(void)
GAP_SetParamValue(TGAP_GEN_DISC_ADV_INT_MAX, advInt);
}
#if 0
// Setup the GAP Bond Manager. For more information see the section in the
// User's Guide:
// http://software-dl.ti.com/lprf/ble5stack-docs-latest/html/ble-stack/gapbondmngr.html#
@@ -372,6 +373,7 @@ static void SimpleBLEPeripheral_init(void)
GAPBondMgr_SetParameter(GAPBOND_IO_CAPABILITIES, sizeof(uint8_t), &ioCap);
GAPBondMgr_SetParameter(GAPBOND_BONDING_ENABLED, sizeof(uint8_t), &bonding);
}
#endif
// Initialize GATT attributes
GGS_AddService(GATT_ALL_SERVICES); // GAP GATT Service
@@ -435,10 +437,10 @@ static void SimpleBLEPeripheral_init(void)
// This API is documented in hci.h
// See BLE5-Stack User's Guide for information on using this command:
// http://software-dl.ti.com/lprf/ble5stack-docs-latest/html/ble-stack/data-length-extensions.html
// HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);
HCI_LE_WriteSuggestedDefaultDataLenCmd(APP_SUGGESTED_PDU_SIZE, APP_SUGGESTED_TX_TIME);
}
#if defined (BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)
#if 0 // defined (BLE_V42_FEATURES) && (BLE_V42_FEATURES & PRIVACY_1_2_CFG)
// Initialize GATT Client
GATT_InitClient();

85
tools/cc2640r2_etag.html Normal file
View File

@@ -0,0 +1,85 @@
<html lang="zh-CN">
<script>
let bleDevice;
let gattServer;
let Theservice;
let epdService;
let epochCharacter;
async function doConnect() {
if (gattServer != null && gattServer.connected) {
if (bleDevice != null && bleDevice.gatt.connected)
bleDevice.gatt.disconnect();
}
else {
bleDevice = await navigator.bluetooth.requestDevice({
filters: [{ namePrefix: ['C26_'] }],
optionalServices: [
'f0001140-0451-4000-b000-000000000000',
],
//acceptAllDevices: true
});
await bleDevice.addEventListener('gattserverdisconnected', disconnect);
await connect();
//catch(handleError);
}
}
async function connect() {
if (epochCharacter == null) {
info("Connect to " + bleDevice.name)
gattServer = await bleDevice.gatt.connect();
info('> Found GATT server');
epdService = await gattServer.getPrimaryService('f0001140-0451-4000-b000-000000000000');
info('> Found service');
epochCharacter = await epdService.getCharacteristic('f0001141-0451-4000-b000-000000000000');
document.getElementById("btnConnect").innerHTML = 'Disconnect';
}
}
function disconnect() {
bleDevice = null;
info('Disconnected.');
document.getElementById("btnConnect").innerHTML = 'Connect';
}
async function doSetTime() {
var epoch = Date.now() / 1000 | 0;
var buf = new ArrayBuffer(4);
var arr = new Uint32Array(buf);
arr[0] = epoch;
await epochCharacter.writeValueWithResponse(arr);
info("Write unix epoch: " + epoch);
}
function handleNotify(data) {
console.log("Got bytes: " + data.buffer);
}
function handleError(error) {
console.log(error);
if (bleDevice == null) {
return;
} else {
console.log("Was not able to connect, aborting");
}
}
function info(logTXT) {
var today = new Date();
var time = ("0" + today.getHours()).slice(-2) + ":" + ("0" + today.getMinutes()).slice(-2) + ":" + ("0" + today.getSeconds()).slice(-2) + " : ";
document.getElementById("log").innerHTML += time + logTXT + '<br>';
console.log(time + logTXT);
while ((document.getElementById("log").innerHTML.match(/<br>/g) || []).length > 10) {
var logs_br_position = document.getElementById("log").innerHTML.search("<br>");
document.getElementById("log").innerHTML = document.getElementById("log").innerHTML.substring(logs_br_position + 4);
}
}
</script>
<button id="btnConnect" type="button" onclick="doConnect()">Connect</button>
<button id="btnSetTime" type="button" onclick="doSetTime()">SetTime</button>
<div id="log"></div>
</html>