Skip to content

Commit

Permalink
back to c source
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaminwater committed May 9, 2018
1 parent bd26045 commit 002949d
Show file tree
Hide file tree
Showing 22 changed files with 1,820 additions and 128 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -3,7 +3,7 @@
# project subdirectory.
#

PROJECT_NAME := app-template
PROJECT_NAME := chronic-o-matic

include $(IDF_PATH)/make/project.mk

5 changes: 5 additions & 0 deletions gdbinit
@@ -0,0 +1,5 @@
target remote :3333
mon reset halt
thb app_main
x $a1=0
c
33 changes: 33 additions & 0 deletions main/app_main.c
@@ -0,0 +1,33 @@
/* Hello World Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

#include "ble.h"
#include "kv.h"
#include "wifi.h"
#include "time.h"
#include "led.h"

#define VERSION "v0.1"

void app_main() {
printf("Welcome to chronic-o-matic firmware %s\n", VERSION);

init_kv();
init_ble();
init_wifi();
init_time();
init_led();

fflush(stdout);
while(1) vTaskDelay(10);
}
20 changes: 20 additions & 0 deletions main/ble.h
@@ -0,0 +1,20 @@
/*
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/

#ifndef BLE_H_
#define BLE_H_

#include "ble_db.h"

void init_ble();
void notify_handle(enum idx i, const uint8_t *notify_data, uint16_t notify_data_length);
void notify_attr(enum idx i);

void set_attr_value(enum idx i, const uint8_t *value, uint16_t value_length);

#endif
40 changes: 40 additions & 0 deletions main/ble_api.c
@@ -0,0 +1,40 @@
/*
* =====================================================================================
*
* Filename: ble_api.c
*
* Description:
*
* Version: 1.0
* Created: 05/9/2018 15:47:31
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/

#include "ble.h"
#include "ble_utils.h"

void notify_handle(enum idx i, const uint8_t *notify_data, uint16_t notify_data_length) {
if (profile_tab[PROFILE_APP_IDX].gatts_if == ESP_GATT_IF_NONE || profile_tab[PROFILE_APP_IDX].conn_id == UINT16_MAX) return;

ESP_ERROR_CHECK(esp_ble_gatts_send_indicate(profile_tab[PROFILE_APP_IDX].gatts_if, profile_tab[PROFILE_APP_IDX].conn_id, handle_table[i], notify_data_length, (uint8_t *)notify_data, false));
}

void set_attr_value(enum idx i, const uint8_t *value, uint16_t value_length) {
ESP_ERROR_CHECK(esp_ble_gatts_set_attr_value(handle_table[i], value_length, value));
}

void notify_attr(enum idx i) {
if (profile_tab[PROFILE_APP_IDX].gatts_if == ESP_GATT_IF_NONE || profile_tab[PROFILE_APP_IDX].conn_id == UINT16_MAX) return;

const uint8_t *value;
uint16_t value_length;

ESP_ERROR_CHECK(esp_ble_gatts_get_attr_value(handle_table[i], &value_length, &value));
notify_handle(i, value, value_length);
}
38 changes: 38 additions & 0 deletions main/ble_db.c
@@ -0,0 +1,38 @@
/*
* =====================================================================================
*
* Filename: ble_db.c
*
* Description:
*
* Version: 1.0
* Created: 05/09/2018 11:58:37
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/

#include "ble_db.h"

#include "ble_utils.h"
#include "time.h"

const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB] =
{
// Time Service Declaration
[IDX_TIME_SVC] =
{{ESP_GATT_AUTO_RSP}, {ESP_UUID_LEN_16, (uint8_t *)&primary_service_uuid, ESP_GATT_PERM_READ,
ESP_UUID_LEN_16, sizeof(TIME_SERVICE), (uint8_t *)TIME_SERVICE}},

R_I_NOTIFIABLE_CHAR(IDX_CHAR_TIME, IDX_CHAR_VAL_TIME, IDX_CHAR_CFG_TIME, TIME_UUID),
R_I_NOTIFIABLE_CHAR(IDX_CHAR_SIMULATED_TIME, IDX_CHAR_VAL_SIMULATED_TIME, IDX_CHAR_CFG_SIMULATED_TIME, SIMULATED_TIME_UUID),
RW_I_CHAR(IDX_CHAR_START_DATE_MONTH, IDX_CHAR_VAL_START_DATE_MONTH, START_DATE_MONTH_UUID),
RW_I_CHAR(IDX_CHAR_START_DATE_DAY, IDX_CHAR_VAL_START_DATE_DAY, START_DATE_DAY_UUID),
RW_I_CHAR(IDX_CHAR_DURATION_DAYS, IDX_CHAR_VAL_DURATION_DAYS, DURATION_DAYS_UUID),
RW_I_CHAR(IDX_CHAR_SIMULATION_DURATION_DAYS, IDX_CHAR_VAL_SIMULATION_DURATION_DAYS, SIMULATION_DURATION_DAYS_UUID),
RW_I_CHAR(IDX_CHAR_STARTED_AT, IDX_CHAR_VAL_STARTED_AT, STARTED_AT_UUID)
};
56 changes: 56 additions & 0 deletions main/ble_db.h
@@ -0,0 +1,56 @@
/*
* =====================================================================================
*
* Filename: ble_db.h
*
* Description:
*
* Version: 1.0
* Created: 05/09/2018 11:57:38
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =====================================================================================
*/

#ifndef BLE_DB_H_
#define BLE_DB_H_

#include "esp_gatts_api.h"

enum idx
{
IDX_TIME_SVC,

IDX_CHAR_TIME,
IDX_CHAR_VAL_TIME,
IDX_CHAR_CFG_TIME,

IDX_CHAR_SIMULATED_TIME,
IDX_CHAR_VAL_SIMULATED_TIME,
IDX_CHAR_CFG_SIMULATED_TIME,

IDX_CHAR_START_DATE_MONTH,
IDX_CHAR_VAL_START_DATE_MONTH,

IDX_CHAR_START_DATE_DAY,
IDX_CHAR_VAL_START_DATE_DAY,

IDX_CHAR_DURATION_DAYS,
IDX_CHAR_VAL_DURATION_DAYS,

IDX_CHAR_SIMULATION_DURATION_DAYS,
IDX_CHAR_VAL_SIMULATION_DURATION_DAYS,

IDX_CHAR_STARTED_AT,
IDX_CHAR_VAL_STARTED_AT,

HRS_IDX_NB,
};

extern const esp_gatts_attr_db_t gatt_db[HRS_IDX_NB];

#endif

0 comments on commit 002949d

Please sign in to comment.