Skip to content
Snippets Groups Projects
Commit 30ca51c9 authored by Jason Chiang's avatar Jason Chiang
Browse files

final

parent 2741616e
Branches main
No related tags found
No related merge requests found
Pipeline #459899 passed
......@@ -11,11 +11,11 @@ CONFIG_SENSOR=y
# BLE
CONFIG_BT=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DEVICE_NAME="Final_Project"
CONFIG_BT_DEVICE_NAME="Jason's device"
CONFIG_BT_DEVICE_APPEARANCE=0
CONFIG_BT_MAX_CONN=1
CONFIG_BT_LL_SOFTDEVICE=y
CONFIG_BT_BAS=y // Battery Service GATT
CONFIG_BT_BAS=y
CONFIG_BT_SETTINGS=y
CONFIG_SETTINGS_RUNTIME=y
CONFIG_SETTINGS=y
......
src/Connected.jpeg

622 KiB

......@@ -105,8 +105,8 @@ K_WORK_DEFINE(pressure_work, pressure_handler);
#define VOLTAGE_RANGE 3.3
#define NUM_STEPS 20
#define INTERVALS 40
#define MEASUREMENT_DELAY_MS 1000 // delay between measurements
#define OVERSAMPLE 10 // number of samples to average together
#define MEASUREMENT_DELAY_MS 1000
#define OVERSAMPLE 10
#define MAX_BRIGHTNESS 1000000
// ADC value variables
......@@ -123,7 +123,6 @@ bool usbregstatus;
// Pressure sensor
static int32_t atm_pressure_kPa;
// maybe change the sine and min to floats?
// 100Hz variables
int32_t sine_value_0[10];
int32_t min_value_0;
......@@ -753,6 +752,12 @@ static int init_entry(void *o)
LOG_INF("MPR pressure sensor %s is ready", pressure_in->name);
}
/* Initialize Bluetooth */
int err = bluetooth_init(&bluetooth_callbacks, &remote_service_callbacks);
if (err) {
LOG_ERR("BT init failed (err = %d)", err);
}
}
......@@ -770,13 +775,11 @@ static void init_exit(void *o)
//Start the battery timer
k_timer_start(&battery_timer, K_MSEC(LED_ON_TIME_MS), K_MSEC(LED_ON_TIME_MS));
LOG_ERR("Leaving init state");
}
/***************** READ STATE *******************/
static void read_entry(void *o)
{
LOG_ERR("Entered read state");
// start read timers
k_timer_start(&read_100hz_timer, K_MSEC(10), K_MSEC(10));
......@@ -800,13 +803,11 @@ static void read_exit(void *o)
wave_counter_0 = 0;
wave_counter_1 = 0;
LOG_ERR("Leaving read state");
}
/***************** ACTION STATE *******************/
static void action_entry(void *o)
{
LOG_ERR("Entered action state");
// Configure and add callbacks to button
ret = gpio_pin_interrupt_configure_dt(&save, GPIO_INT_EDGE_TO_ACTIVE);
......@@ -838,15 +839,12 @@ static void action_entry(void *o)
static void action_run(void *o)
{
// Check for vbus and pressure
if (usbregstatus == true || atm_pressure_kPa <= 0){
// VBUS detected or no pressure (go to error)
smf_set_state(SMF_CTX(&s_obj), &device_states[error]);
}
}
static void action_exit(void *o)
......@@ -854,15 +852,11 @@ static void action_exit(void *o)
// Remove callbacks associated with the buttons
gpio_remove_callback(save.port, &save_cb);
gpio_remove_callback(send.port, &send_cb);
// Stop the timers?
LOG_INF("Leaving action state");
}
/***************** ERROR STATE *******************/
static void error_entry(void *o)
{
LOG_ERR("Entered error state");
{;
if (usbregstatus == true) {
// VBUS detected, start error led timer (make led3 blink)
......@@ -894,22 +888,14 @@ static void error_exit(void *o)
// turn off error led
gpio_pin_set_dt(&error_led, 0);
LOG_ERR("Leaving error state");
}
/***************** CONNECT STATE *******************/
static void connect_entry(void *o)
{
LOG_INF("Entered connect state");
/* Initialize Bluetooth */
int err = bluetooth_init(&bluetooth_callbacks, &remote_service_callbacks);
if (err) {
LOG_ERR("BT init failed (err = %d)", err);
}
// send a notification that "data" is ready to be read...
err = send_data_notification(current_conn, data_array, 1);
int err = send_data_notification(current_conn, data_array, 1);
if (err) {
LOG_ERR("Could not send BT notification (err: %d)", err);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment