|
| 1 | +/* |
| 2 | + Copyright (c) 2020 SiWi Embedded Solutions. All right reserved. |
| 3 | +
|
| 4 | + This library is free software; you can redistribute it and/or |
| 5 | + modify it under the terms of the GNU Lesser General Public |
| 6 | + License as published by the Free Software Foundation; either |
| 7 | + version 2.1 of the License.. |
| 8 | +
|
| 9 | + This library is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | + See the GNU Lesser General Public License for more details. |
| 13 | +*/ |
| 14 | + |
| 15 | +#include "Arduino.h" |
| 16 | + |
| 17 | +void serialEvent() __attribute__((weak)); |
| 18 | +void serialEvent1() __attribute__((weak)); |
| 19 | + |
| 20 | +void serialEventRun(void) |
| 21 | +{ |
| 22 | + /* TODO */ |
| 23 | +} |
| 24 | + |
| 25 | +#ifdef __cplusplus |
| 26 | +extern "C" |
| 27 | +{ |
| 28 | +#endif |
| 29 | + |
| 30 | +int g_ioHandles[GPIO_PIN_MAX]; |
| 31 | +int g_ioModes[GPIO_PIN_MAX]; |
| 32 | + |
| 33 | +static const uint32_t adc_channel_map[4][2] = { |
| 34 | + {GPIO_1, ADC_CH1}, |
| 35 | + {GPIO_7, ADC_CH2}, |
| 36 | + {GPIO_8, ADC_CH3}, |
| 37 | + {GPIO_PIN_MAX, ADC_CH0}, |
| 38 | +}; |
| 39 | + |
| 40 | +int pin2adc_channel(uint32_t pin) |
| 41 | +{ |
| 42 | + for (int i = 0; i < 4; i++) { |
| 43 | + if (adc_channel_map[i][0] == pin) |
| 44 | + return adc_channel_map[i][1]; |
| 45 | + } |
| 46 | + |
| 47 | + return -1; |
| 48 | +} |
| 49 | + |
| 50 | +int pin2pwm_channel(uint32_t pin) |
| 51 | +{ |
| 52 | + if (pin == GPIO_1) |
| 53 | + return PWM_CH0; |
| 54 | + |
| 55 | + return -1; |
| 56 | +} |
| 57 | + |
| 58 | +#ifdef __cplusplus |
| 59 | +} |
| 60 | +#endif |
| 61 | + |
| 62 | +static void urc_callback(unsigned int param1, unsigned int param2) |
| 63 | +{ |
| 64 | + switch (param1) |
| 65 | + { |
| 66 | + case URC_SYS_INIT_STATE_IND: |
| 67 | + if (param2 == SYS_STATE_SMSOK) |
| 68 | + { |
| 69 | + /* Ready for SMS */ |
| 70 | + } |
| 71 | + break; |
| 72 | + case URC_SIM_CARD_STATE_IND: |
| 73 | + switch (param2) |
| 74 | + { |
| 75 | + case SIM_STAT_NOT_INSERTED: |
| 76 | + debug(DBG_OFF, "SYSTEM: SIM card not inserted!\n"); |
| 77 | + break; |
| 78 | + case SIM_STAT_READY: |
| 79 | + debug(DBG_INFO, "SYSTEM: SIM card Ready!\n"); |
| 80 | + break; |
| 81 | + case SIM_STAT_PIN_REQ: |
| 82 | + debug(DBG_OFF, "SYSTEM: SIM PIN required!\n"); |
| 83 | + break; |
| 84 | + case SIM_STAT_PUK_REQ: |
| 85 | + debug(DBG_OFF, "SYSTEM: SIM PUK required!\n"); |
| 86 | + break; |
| 87 | + case SIM_STAT_NOT_READY: |
| 88 | + debug(DBG_OFF, "SYSTEM: SIM card not recognized!\n"); |
| 89 | + break; |
| 90 | + default: |
| 91 | + debug(DBG_OFF, "SYSTEM: SIM ERROR: %d\n", param2); |
| 92 | + } |
| 93 | + break; |
| 94 | + case URC_GSM_NW_STATE_IND: |
| 95 | + debug(DBG_OFF, "SYSTEM: GSM NW State: %d\n", param2); |
| 96 | + break; |
| 97 | + case URC_GPRS_NW_STATE_IND: |
| 98 | + break; |
| 99 | + case URC_CFUN_STATE_IND: |
| 100 | + break; |
| 101 | + case URC_COMING_CALL_IND: |
| 102 | + debug(DBG_OFF, "Incoming voice call from: %s\n", ((ST_ComingCall *)param2)->phoneNumber); |
| 103 | + /* Take action here, Answer/Hang-up */ |
| 104 | + break; |
| 105 | + case URC_CALL_STATE_IND: |
| 106 | + switch (param2) |
| 107 | + { |
| 108 | + case CALL_STATE_BUSY: |
| 109 | + debug(DBG_OFF, "The number you dialed is busy now\n"); |
| 110 | + break; |
| 111 | + case CALL_STATE_NO_ANSWER: |
| 112 | + debug(DBG_OFF, "The number you dialed has no answer\n"); |
| 113 | + break; |
| 114 | + case CALL_STATE_NO_CARRIER: |
| 115 | + debug(DBG_OFF, "The number you dialed cannot reach\n"); |
| 116 | + break; |
| 117 | + case CALL_STATE_NO_DIALTONE: |
| 118 | + debug(DBG_OFF, "No Dial tone\n"); |
| 119 | + break; |
| 120 | + default: |
| 121 | + break; |
| 122 | + } |
| 123 | + break; |
| 124 | + case URC_NEW_SMS_IND: |
| 125 | + debug(DBG_OFF, "SMS: New SMS (%d)\n", param2); |
| 126 | + /* Handle New SMS */ |
| 127 | + break; |
| 128 | + case URC_MODULE_VOLTAGE_IND: |
| 129 | + debug(DBG_INFO, "VBatt Voltage: %d\n", param2); |
| 130 | + break; |
| 131 | + case URC_ALARM_RING_IND: |
| 132 | + break; |
| 133 | + case URC_FILE_DOWNLOAD_STATUS: |
| 134 | + break; |
| 135 | + case URC_FOTA_STARTED: |
| 136 | + break; |
| 137 | + case URC_FOTA_FINISHED: |
| 138 | + break; |
| 139 | + case URC_FOTA_FAILED: |
| 140 | + break; |
| 141 | + case URC_STKPCI_RSP_IND: |
| 142 | + break; |
| 143 | + default: |
| 144 | + break; |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +/* |
| 149 | + * \brief Main entry point of Arduino application |
| 150 | + */ |
| 151 | +int main(int argc, char *argv[]) |
| 152 | +{ |
| 153 | + /* Initialize Siwi system task */ |
| 154 | + siwilib_init(DEFAULT_STDIO_PORT, urc_callback); |
| 155 | + |
| 156 | + setup(); |
| 157 | + for (;;) |
| 158 | + { |
| 159 | + loop(); |
| 160 | + } |
| 161 | +} |
0 commit comments