Skip to content

Commit

Permalink
add devNetwork dcfg flag
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Apr 27, 2023
1 parent 28b2566 commit ef3036c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 11 deletions.
9 changes: 6 additions & 3 deletions build.js
Expand Up @@ -120,10 +120,15 @@ function filesInDir(fn) {
const genspecs = ["devicescript-spec.d.ts", "devicescript-boards.d.ts"]
const serversname = "core/src/devicescript-servers.d.ts"
function buildPrelude(folder, outp) {
// get the srvcfg.d.ts extension from archconfig.ts
let additions = fs
.readFileSync("interop/src/archconfig.ts", "utf-8")
.replace(/[^]*^declare module.*/m, "")
.replace(/^\}[^]*/m, "")
let srvcfg = fs.readFileSync("runtime/jacdac-c/dcfg/srvcfg.d.ts", "utf-8")
// no reason to encode hex number as strings in full TS syntax
srvcfg = srvcfg
.replace("type HexInt = integer | string", "type HexInt = integer")
.replace("type HexInt = integer | string", "type HexInt = integer" + "\n" + additions)
.replace(/type \w*Pin = .*/g, "")
.replace("/srvcfg", "/servers")
.replace(
Expand All @@ -145,8 +150,6 @@ function buildPrelude(folder, outp) {
return ""
})
startServ += `
type UserHardwareInfo = Pick<DeviceHardwareInfo, "scanI2C">
/**
* Configure C runtime.
*/
Expand Down
18 changes: 15 additions & 3 deletions interop/src/archconfig.ts
Expand Up @@ -3,12 +3,24 @@
/// <reference path="../../runtime/jacdac-c/dcfg/srvcfg.d.ts" />

import {
DeviceHardwareInfo,
DeviceScriptConfig,
HexInt,
JsonComment,
ServiceConfig,
} from "@devicescript/srvcfg"

declare module "@devicescript/srvcfg" {
interface DeviceScriptConfig extends DeviceHardwareInfo {
/**
* Don't start internal cloud adapter service (including the WiFi adapter) and instead use one running
* on the computer connected via USB.
*/
devNetwork?: boolean
}

type UserHardwareInfo = Pick<DeviceScriptConfig, "scanI2C" | "devNetwork">
}

export interface DeviceProps {
/**
* Name of the program, derived from package.json. Exposed as `program_name` register.
Expand All @@ -21,11 +33,11 @@ export interface DeviceProps {
"@version"?: string
}

export type ProgramConfig = Partial<DeviceProps> & Partial<DeviceHardwareInfo>
export type ProgramConfig = Partial<DeviceProps> & Partial<DeviceScriptConfig>

export interface DeviceConfig
extends DeviceProps,
DeviceHardwareInfo,
DeviceScriptConfig,
JsonComment {
$schema?: string

Expand Down
2 changes: 1 addition & 1 deletion packages/drivers/src/bme680.ts
Expand Up @@ -305,7 +305,7 @@ class BME680Driver extends I2CSensorDriver<{
gas,
pressure,
}
console.log(r)
// console.log(r)
return r
}
}
Expand Down
10 changes: 6 additions & 4 deletions runtime/devicescript/devsmgr.c
Expand Up @@ -510,11 +510,13 @@ void devs_service_full_init(const devsmgr_cfg_t *cfg) {
gpiosrv_config();
#endif

#if JD_NETWORK
if (!dcfg_get_bool("devNetwork")) {
#if JD_WIFI
wifi_init();
wifi_init();
#endif
#if JD_NETWORK
wsskhealth_init();
devscloud_init(&wssk_cloud);
wsskhealth_init();
devscloud_init(&wssk_cloud);
}
#endif
}

0 comments on commit ef3036c

Please sign in to comment.