Skip to content

Commit

Permalink
Merge pull request #2 from toitware/floitsch/cleanups
Browse files Browse the repository at this point in the history
Cleanups and make it work again.
  • Loading branch information
floitsch authored Oct 4, 2024
2 parents 2262d6d + 5b67f9c commit 5858f9c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: 2
updates:
- package-ecosystem: "github-actions" # Necessary to update action hashs.
directory: "/"
schedule:
interval: "weekly"
# Allow up to 3 opened pull requests for github-actions versions.
open-pull-requests-limit: 3
20 changes: 18 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
# Zero-Clause BSD License

# Copyright (C) 2024 Toitware ApS.

# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.

# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.

name: Publish package
on:
push:
tags:
- 'v*'
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-*'
jobs:
create-release:
name: Create new release
runs-on: ubuntu-latest
steps:
- name: Publish
uses: toitlang/pkg-publish@v1.0.2
uses: toitlang/pkg-publish@v1.5.0
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.packages/
5 changes: 5 additions & 0 deletions examples/package.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,31 @@ packages:
cellular: cellular
cellular:
url: github.com/toitware/cellular
name: cellular
version: 1.0.0
hash: 0fdbcd9cc5a0a96eac12ab634881bea5ef12114f
prefixes:
gnss_location: toit-gnss-location
pkg-http:
url: github.com/toitlang/pkg-http
name: http
version: 1.5.0
hash: 538c761a0f01d532ab9982a3f8f996e552311f4b
toit-gnss-location:
url: github.com/toitware/toit-gnss-location
name: gnss_location
version: 1.0.2
hash: e9457f50c5260f9451e823a39d435e3655125bb0
prefixes:
location: toit-location
toit-location:
url: github.com/toitware/toit-location
name: location
version: 1.0.0
hash: 080665c10587c1ef82e26b993dda7fa560cf2075
ublox-cellular:
url: github.com/toitware/ublox-cellular
name: u_blox_cellular
version: 0.1.1
hash: 031958609749e7705a694978a50d43bdd3a91cb9
prefixes:
Expand Down
4 changes: 2 additions & 2 deletions examples/sara_r4.toit
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ RESET_N_NUM ::= 4

main:
pwr_on := gpio.Pin PWR_ON_NUM
pwr_on.config --output --open_drain
pwr_on.configure --output --open_drain
pwr_on.set 1
reset_n := gpio.Pin RESET_N_NUM
reset_n.config --output --open_drain
reset_n.configure --output --open_drain
reset_n.set 1
tx := gpio.Pin TX_PIN_NUM
rx := gpio.Pin RX_PIN_NUM
Expand Down
2 changes: 2 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: cellular-connector
description: Strategy for connecting with a cellular modem.
dependencies:
cellular:
url: github.com/toitware/cellular
Expand Down
23 changes: 13 additions & 10 deletions src/cellular_connector.toit
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
// found in the LICENSE file.
import cellular
import device
import encoding.ubjson
import gpio
import log
import net
import system.storage

class Configuration:
is_always_online/bool
Expand Down Expand Up @@ -208,7 +208,7 @@ class Connector:
finally:
// Wait for chip to signal power-off.
if rts_:
rts_.config --output
rts_.configure --output
rts_.set 0
wait_for_quiescent_

Expand All @@ -234,7 +234,7 @@ class Connector:
// Block until a value has been sustained for at least $SUSTAIN_FOR_DURATION_.
wait_for_quiescent_:
logger_.debug "waiting for quiescent rx pin"
rx_.config --input
rx_.configure --input
while true:
value := rx_.get

Expand Down Expand Up @@ -312,27 +312,30 @@ class CellularInfo:
return cellular.Operator value[0] --rat=value[1]

class StateStore:
static STORE_PATH_ ::= "toit.io/cellular_connector"
static STORE_INFO_KEY_ ::= "connect info"
static STORE_PSM_KEY_ ::= "is psm"
store_ := device.FlashStore

bucket_/storage.Bucket

constructor:
bucket_ = storage.Bucket.open --flash STORE_PATH_

store bytes/ByteArray -> bool:
store_.set STORE_INFO_KEY_ bytes
bucket_[STORE_INFO_KEY_] = bytes
// TODO can we return bool here?
return true

load -> ByteArray?:
return store_.get STORE_INFO_KEY_
return bucket_.get STORE_INFO_KEY_

remove:
store_.delete STORE_INFO_KEY_
bucket_.remove STORE_INFO_KEY_

take_is_psm -> bool:
is_psm := store_.get STORE_PSM_KEY_
if is_psm: store_.delete STORE_PSM_KEY_
is_psm := bucket_.get STORE_PSM_KEY_
if is_psm: bucket_.remove STORE_PSM_KEY_
return is_psm ? true : false

set_use_psm -> none:
store_.set STORE_PSM_KEY_ (ByteArray 0)
bucket_[STORE_PSM_KEY_] = #[]

0 comments on commit 5858f9c

Please sign in to comment.