Skip to content

Commit

Permalink
Adding board types
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed May 2, 2017
1 parent 354d6af commit 59fddc4
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 37 deletions.
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
# Selectable build options
#------------------------------------------------------------------------------

#TARGET_BOARD ?= BOARD_PCA10000
#TARGET_BOARD ?= BOARD_PCA10001
#TARGET_BOARD ?= BOARD_PCA10028
TARGET_BOARD ?= BOARD_SENSEI
TARGET_BOARD ?= BOARD_RFD77201
#TARGET_BOARD ?= BOARD_SHOE_SENSOR

USE_DFU ?= "no"

Expand All @@ -21,10 +19,11 @@ TEMPLATE_PATH := $(COMPONENTS)/toolchain/gcc
SIMBLEE_BASE := /Users/pete/Library/Arduino15/packages/Simblee/hardware/Simblee/1.1.2
RBC_MESH := rbc_mesh


LINKER_SCRIPT := $(SIMBLEE_BASE)/variants/Simblee/linker_scripts/gcc/Simblee.ld
RFD_LOADER := $(SIMBLEE_BASE)/RFDLoader_osx
SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left
#SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right
#SERIAL_PORT := /dev/cu.usbserial-DN00CSZ7 # left
SERIAL_PORT := /dev/cu.usbserial-DN00D34P # right
#SERIAL_PORT := /dev/cu.usbserial-A105RB12
#SERIAL_PORT := /dev/cu.usbserial-FTZ86FTC # tag-connect
#SERIAL_PORT := /dev/cu.usbserial-DO00C2G2 # Breadboard setup
Expand Down Expand Up @@ -95,13 +94,13 @@ remduplicates = $(strip $(if $1,$(firstword $1) $(call remduplicates,$(filter-ou

C_SOURCE_FILES += src/main.c src/config.c src/sensor.c src/app_cmd.c \
src/scheduler.c src/proximity.c src/heartbeat.c src/battery.c src/shoe_accel.c \
src/app_evt.c
src/app_evt.c bsp/bsp.c
C_SOURCE_FILES += $(COMPONENTS)/libraries/timer/app_timer.c

CXX_SOURCE_FILES += $(SIMBLEE_BASE)/libraries/SimbleeBLE/SimbleeBLE.cpp
CXX_SOURCE_FILES += $(SIMBLEE_BASE)/variants/Simblee/variant.cpp

CFLAGS += -D RBC_MESH_SERIAL=1
CFLAGS += -DRBC_MESH_SERIAL=1 -DBSP_SIMPLE
C_SOURCE_FILES += $(RBC_MESH)/src/serial_handler_uart.c
C_SOURCE_FILES += $(RBC_MESH)/src/mesh_aci.c

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

# Compile and flash devices

Program a sensor with id 1, turning off serial for power savings
Program a shoe sensor with id 1, turning off serial for power savings

`make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_ID=1 SENSOR_CONFIGURATION_OPTIONS="--no-serial"`
`make program SERIAL_PORT=/dev/cu.usbserial-FTZ86FTC SENSOR_CONFIGURATION_OPTIONS="--no-serial" TARGET_BOARD=BOARD_SHOE_SENSOR SENSOR_ID=1`

Program a master listening device that doesn't sleep, and listens all the time.

`make program SERIAL_PORT=/dev/cu.usbserial-DN00D34P SENSOR_ID=3 SENSOR_CONFIGURATION_OPTIONS="--no-sleep"`
`make program SERIAL_PORT=/dev/cu.usbserial-DN00CSZ7 SENSOR_CONFIGURATION_OPTIONS="--no-sleep” TARGET_BOARD=BOARD_RFD77201 SENSOR_ID=51`
13 changes: 6 additions & 7 deletions bsp/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
#include "arduino_primo.h"
#elif defined (BOARD_SENSEI)
#include "board_sensei.h"
#elif defined(BOARD_CUSTOM)
#include "custom_board.h"
#elif defined(BOARD_SHOE_SENSOR)
#include "shoe_sensor.h"
#elif defined(BOARD_LESSON_TRACKER)
#include "lesson_tracker.h"
#elif defined(BOARD_RFD77201)
#include "rfd77201.h"
#else
#error "Board is not defined"

Expand All @@ -67,11 +71,6 @@ extern "C" {
NRF_GPIO->OUTSET = ((leds_mask) & ~gpio_state); \
NRF_GPIO->OUTCLR = ((leds_mask) & gpio_state); } while (0)

#define LEDS_CONFIGURE(leds_mask) do { uint32_t pin; \
for (pin = 0; pin < 32; pin++) \
if ( (leds_mask) & (1 << pin) ) \
nrf_gpio_cfg_output(pin); } while (0)


#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion bsp/bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,14 +565,16 @@ uint32_t bsp_init(uint32_t type, uint32_t ticks_per_100ms, bsp_event_callback_t
}
#endif // (BUTTONS_NUMBER > 0) && !(defined BSP_SIMPLE)

#if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)

#if LEDS_NUMBER > 0
if (type & BSP_INIT_LED)
{
LEDS_OFF(LEDS_MASK);
NRF_GPIO->DIRSET = LEDS_MASK;
}
#endif

#if LEDS_NUMBER > 0 && !(defined BSP_SIMPLE)
// timers module must be already initialized!
if (err_code == NRF_SUCCESS)
{
Expand Down
23 changes: 23 additions & 0 deletions bsp/lesson_tracker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef BOARD_LESSON_TRACKER_H
#define BOARD_LESSON_TRACKER_H

#ifdef __cplusplus
extern "C" {
#endif

#define SIMBLEE

#define LEDS_NUMBER 0
#define BUTTONS_NUMBER 0

#define RX_PIN_NUMBER 0
#define TX_PIN_NUMBER 1
//#define CTS_PIN_NUMBER 0xff
//#define RTS_PIN_NUMBER 0xff
#define HWFC false

#ifdef __cplusplus
}
#endif

#endif //BOARD_LESSON_TRACKER_H
10 changes: 6 additions & 4 deletions bsp/board_sensei.h → bsp/rfd77201.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
* the file.
*
*/
#ifndef BOARD_SENSEI_H
#define BOARD_SENSEI_H
#ifndef RFD77201_H
#define RFD77201_H

#ifdef __cplusplus
extern "C" {
#endif

// LEDs definitions for PCA10028
#define SIMBLEE

// LEDs definitions for RFDuino board with RGB Shield
#define LEDS_NUMBER 3

#define LED_START 2
Expand Down Expand Up @@ -67,4 +69,4 @@ extern "C" {
}
#endif

#endif // BOARD_SENSEI_H
#endif // RFD77201_H
38 changes: 38 additions & 0 deletions bsp/shoe_sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@


#ifndef SHOE_SENSOR_H
#define SHOE_SENSOR_H

#ifdef __cplusplus
extern "C" {
#endif

#define ACCEL_ADXL337
#define SIMBLEE

// LEDs definitions for Sensei shoe sensor board
#define LEDS_NUMBER 0
#define BUTTONS_NUMBER 0


#define BUTTONS_LIST { BUTTON_1, BUTTON_2 }

#define BSP_BUTTON_0 BUTTON_1
#define BSP_BUTTON_1 BUTTON_2

#define BSP_BUTTON_0_MASK (1<<BSP_BUTTON_0)
#define BSP_BUTTON_1_MASK (1<<BSP_BUTTON_1)

#define BUTTONS_MASK (BSP_BUTTON_0_MASK | BSP_BUTTON_1_MASK )

#define RX_PIN_NUMBER 0
#define TX_PIN_NUMBER 1
//#define CTS_PIN_NUMBER 0xff
//#define RTS_PIN_NUMBER 0xff
#define HWFC false

#ifdef __cplusplus
}
#endif

#endif // SHOE_SENSOR_H
2 changes: 1 addition & 1 deletion pyaci/aci_serial/AciUart.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def write_aci_cmd(self, cmd):
if isinstance(cmd,AciCommand.AciCommandPkt):
self.WriteData(cmd.serialize())
retval = self.Wait(self)
print("Event received: %s" %retval)
print("Events received: %s" %retval)
if retval == None:
logging.info('cmd %s, timeout waiting for event' % (cmd.__class__.__name__))
else:
Expand Down
19 changes: 13 additions & 6 deletions pyaci/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ def get_sensor_updates(self):
break
return updates

def runAppCommand(self, command):
def run_app_command(self, command):
data = command.serialize()
return self.aci.write_aci_cmd(AciCommand.AciAppCommand(data=data,length=len(data)+1))

def sync_time(self):
self.last_time_sync = time.time()
result = self.runAppCommand(sensei_cmd.SetTime())
print(str.format("Synced time: %s" %(result)))
result = self.run_app_command(sensei_cmd.SetTime())

def get_config(self):
return self.run_app_command(sensei_cmd.GetConfig())

def radio_obs_from_update(self, update):
if not update.is_valid:
Expand All @@ -55,7 +57,12 @@ def radio_obs_from_update(self, update):

def run(self):
# Wait for serial connection to be ready
time.sleep(2)
time.sleep(3)
print("Getting config")
self.get_config()

# Sync time
print("Syncing time")
self.sync_time()

while True:
Expand All @@ -65,10 +72,10 @@ def run(self):
flattened_obs = [ob for sublist in obs for ob in sublist]
if len(flattened_obs) > 0:
self.api.upload_obs(flattened_obs)
elif time.time() - self.last_time_sync > Uploader.TIME_SYNC_INTERVAL:
self.sync_time()
else:
time.sleep(0.5)
if time.time() - self.last_time_sync > Uploader.TIME_SYNC_INTERVAL:
self.sync_time()


if __name__ == '__main__':
Expand Down
1 change: 0 additions & 1 deletion src/heartbeat.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ void heartbeat_init(uint8_t channel) {

void send_heartbeat_packet(uint8_t sensor_id, uint32_t epoch_seconds, uint16_t epoch_ms, uint16_t clock_version) {
// Send out time sync packet
//TOGGLE_PIN(LED_RED + LED_START);

mesh_packet_t *p_packet;
if (mesh_packet_acquire(&p_packet)) {
Expand Down
11 changes: 11 additions & 0 deletions src/leds.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
#include "boards.h"
#include "gpio_pins.h"


#define LED_RED 0
#define LED_GREEN 1
#define LED_BLUE 2

#if LEDS_NUMBER > 0

#define SET_LED(x) SET_PIN(LED_START + x)
#define CLEAR_LED(x) CLEAR_PIN(LED_START + x)
#define TOGGLE_LED(x) TOGGLE_PIN(LED_START + x)

#else

#define SET_LED(x)
#define CLEAR_LED(x)
#define TOGGLE_LED(x)

#endif

#endif // LEDS_H
11 changes: 6 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "scheduler.h"
#include "heartbeat.h"
#include "handles.h"
#include "bsp.h"
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
Expand Down Expand Up @@ -117,8 +118,7 @@ static void packet_peek_cb(rbc_mesh_packet_peek_params_t *params) {
int main(void)
{

nrf_gpio_cfg_input(BUTTON_1, NRF_GPIO_PIN_PULLDOWN);
nrf_gpio_cfg_input(BUTTON_2, NRF_GPIO_PIN_PULLDOWN);
bsp_init(BSP_INIT_BUTTONS & BSP_INIT_LED, 0, 0);

/* Enable Softdevice (including sd_ble before framework */
SOFTDEVICE_HANDLER_INIT(MESH_CLOCK_SRC, NULL);
Expand All @@ -130,14 +130,15 @@ int main(void)
// Register with the SoftDevice handler module for system events.
softdevice_sys_evt_handler_set(sys_evt_dispatch);

LEDS_CONFIGURE(LEDS_MASK);
// Debug pins
nrf_gpio_cfg_output(5);
nrf_gpio_cfg_output(6);
// nrf_gpio_cfg_output(5);
// nrf_gpio_cfg_output(6);

// Disable simblee's proximityMode
#ifdef SIMBLEE
nrf_gpio_cfg_output(31);
CLEAR_PIN(31);
#endif

// if (NRF_CLOCK->LFCLKSRC == (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos)) {
// TOGGLE_LED(LED_GREEN);
Expand Down
2 changes: 1 addition & 1 deletion src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void set_clock_time(int32_t epoch, uint16_t ms, clock_source_t clock_source, int
} else if (clock_source == CLOCK_SOURCE_SERIAL) {
m_clock_version++;
}
TOGGLE_PIN(LED_BLUE + LED_START);
TOGGLE_LED(LED_BLUE);
m_boot_time += epoch - m_current_time;
m_last_sync = m_current_time = epoch;
app_timer_stop(m_periodic_timer_ID);
Expand Down
11 changes: 11 additions & 0 deletions src/sensor.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

#include "boards.h"
#include "sensor.h"
#include "config.h"
#include "rbc_mesh.h"
Expand All @@ -7,32 +8,42 @@
#include "handles.h"
#include "shoe_accel.h"
#include <app_error.h>
#include <string.h>

static sensor_value_t m_value;

void sensor_init() {
#ifdef ACCEL_ADXL337
shoe_accel_init();
#endif

uint32_t error_code;
error_code = rbc_mesh_value_enable(SENSOR_HANDLE);
APP_ERROR_CHECK(error_code);
}

void sensor_warmup_event() {
#ifdef ACCEL_ADXL337
enable_shoe_accel();
#endif
}

void gather_sensor_data() {
memset(&m_value, 0, sizeof(sensor_value_t));
m_value.valid_time = get_clock_time();
m_value.battery = get_battery_adc();
//m_value.status = ??

#ifdef ACCEL_ADXL337
read_shoe_accel(&m_value.accel_x, &m_value.accel_y, &m_value.accel_z);
#endif

proximity_get_strongest_signals(m_value.proximity_ids, m_value.proximity_rssi, MAX_PROXIMITY_TRACKING_COUNT);
proximity_values_reset();

#ifdef ACCEL_ADXL337
disable_shoe_accel();
#endif
}

void report_sensor_data() {
Expand Down

0 comments on commit 59fddc4

Please sign in to comment.