Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed BufferedSerial Servo2 PCT2075 I2CEeprom FastPWM
i2c_2020_06.cpp@3:43cb067ecd00, 2020-07-27 (annotated)
- Committer:
- JonFreeman
- Date:
- Mon Jul 27 08:44:59 2020 +0000
- Revision:
- 3:43cb067ecd00
End of July after good day out at Ashton Court
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JonFreeman | 3:43cb067ecd00 | 1 | #include "mbed.h" |
| JonFreeman | 3:43cb067ecd00 | 2 | #include "Alternator.h" |
| JonFreeman | 3:43cb067ecd00 | 3 | #include "I2CEeprom.h" |
| JonFreeman | 3:43cb067ecd00 | 4 | |
| JonFreeman | 3:43cb067ecd00 | 5 | const int settings_ee_addr = eeprom_page * eeprom_page_size; |
| JonFreeman | 3:43cb067ecd00 | 6 | |
| JonFreeman | 3:43cb067ecd00 | 7 | /*struct sldandt { |
| JonFreeman | 3:43cb067ecd00 | 8 | const uint32_t min, max, de_fault; // min, max, default |
| JonFreeman | 3:43cb067ecd00 | 9 | const char * txt; // description |
| JonFreeman | 3:43cb067ecd00 | 10 | char val; |
| JonFreeman | 3:43cb067ecd00 | 11 | } ; |
| JonFreeman | 3:43cb067ecd00 | 12 | */ |
| JonFreeman | 3:43cb067ecd00 | 13 | const char tabletext[] = "User Table entry 0 to 100"; |
| JonFreeman | 3:43cb067ecd00 | 14 | extern const int numof_op_modes; |
| JonFreeman | 3:43cb067ecd00 | 15 | |
| JonFreeman | 3:43cb067ecd00 | 16 | struct sldandt option_list[] = { |
| JonFreeman | 3:43cb067ecd00 | 17 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 0 |
| JonFreeman | 3:43cb067ecd00 | 18 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 1 |
| JonFreeman | 3:43cb067ecd00 | 19 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 2 |
| JonFreeman | 3:43cb067ecd00 | 20 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 3 |
| JonFreeman | 3:43cb067ecd00 | 21 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 4 |
| JonFreeman | 3:43cb067ecd00 | 22 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 5 |
| JonFreeman | 3:43cb067ecd00 | 23 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 6 |
| JonFreeman | 3:43cb067ecd00 | 24 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 7 |
| JonFreeman | 3:43cb067ecd00 | 25 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 8 |
| JonFreeman | 3:43cb067ecd00 | 26 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 9 |
| JonFreeman | 3:43cb067ecd00 | 27 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 10 |
| JonFreeman | 3:43cb067ecd00 | 28 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 11 |
| JonFreeman | 3:43cb067ecd00 | 29 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 12 |
| JonFreeman | 3:43cb067ecd00 | 30 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 13 |
| JonFreeman | 3:43cb067ecd00 | 31 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 14 |
| JonFreeman | 3:43cb067ecd00 | 32 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 15 |
| JonFreeman | 3:43cb067ecd00 | 33 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 16 |
| JonFreeman | 3:43cb067ecd00 | 34 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 17 |
| JonFreeman | 3:43cb067ecd00 | 35 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 18 |
| JonFreeman | 3:43cb067ecd00 | 36 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 19 |
| JonFreeman | 3:43cb067ecd00 | 37 | {0, 100, 0, tabletext}, // Field Current Limit User Entry Table position 20 |
| JonFreeman | 3:43cb067ecd00 | 38 | {0, 120, 3, "Engine warn-up delay seconds"}, |
| JonFreeman | 3:43cb067ecd00 | 39 | {0, 100, 20, "Warmup servo position percent"}, |
| JonFreeman | 3:43cb067ecd00 | 40 | {0, numof_op_modes - 1, 0, "Operating Mode - 0=Engine Only test, 1=Const Voltage, 2=Var Voltage, 3=Current feedback"}, |
| JonFreeman | 3:43cb067ecd00 | 41 | {20, 100, 50, "Engine speed control 'P' adjust"}, |
| JonFreeman | 3:43cb067ecd00 | 42 | {0, 1, 0, "0 Servo normal, 1 reverse"}, |
| JonFreeman | 3:43cb067ecd00 | 43 | {0, 100, 0, "Future 26"}, |
| JonFreeman | 3:43cb067ecd00 | 44 | {0, 100, 0, "Future 27"}, |
| JonFreeman | 3:43cb067ecd00 | 45 | {0, 100, 0, "Future 28"}, |
| JonFreeman | 3:43cb067ecd00 | 46 | {0, 100, 0, "Future 29"}, |
| JonFreeman | 3:43cb067ecd00 | 47 | {0, 100, 0, "Future 30"}, |
| JonFreeman | 3:43cb067ecd00 | 48 | {0, 100, 0, "Future 31"}, |
| JonFreeman | 3:43cb067ecd00 | 49 | } ; |
| JonFreeman | 3:43cb067ecd00 | 50 | |
| JonFreeman | 3:43cb067ecd00 | 51 | /*enum {TABL0, TABL1, TABL2, TABL3, TABL4, TABL5, TABL6, TABL7, TABL8, TABL9, TABL10, TABL11, TABL12, TABL13, TABL14, TABL15, TABL16, |
| JonFreeman | 3:43cb067ecd00 | 52 | TABL17, TABL18, TABL19, TABL20, |
| JonFreeman | 3:43cb067ecd00 | 53 | WARM_UP_DELAY, WARMUP_SERVO_POS, OP_MODE, SPEED_CTRL_P, SERVO_DIR, FUT30, FUT31 } ; |
| JonFreeman | 3:43cb067ecd00 | 54 | */ |
| JonFreeman | 3:43cb067ecd00 | 55 | const int numof_eeprom_options = sizeof(option_list) / sizeof (struct sldandt); |
| JonFreeman | 3:43cb067ecd00 | 56 | |
| JonFreeman | 3:43cb067ecd00 | 57 | |
| JonFreeman | 3:43cb067ecd00 | 58 | //I2CEeprom eeprom (SDA_PIN, SCL_PIN, 0xa0, eeprom_page_size, 8192, 100000); |
| JonFreeman | 3:43cb067ecd00 | 59 | extern I2CEeprom eeprom; // (SDA_PIN, SCL_PIN, 0xa0, eeprom_page_size, 8192, 100000); |
| JonFreeman | 3:43cb067ecd00 | 60 | |
| JonFreeman | 3:43cb067ecd00 | 61 | /* |
| JonFreeman | 3:43cb067ecd00 | 62 | class ee_settings_2020 { |
| JonFreeman | 3:43cb067ecd00 | 63 | char new_settings[eeprom_page_size + 2]; |
| JonFreeman | 3:43cb067ecd00 | 64 | public: |
| JonFreeman | 3:43cb067ecd00 | 65 | ee_settings_2020 () ; // Constructor |
| JonFreeman | 3:43cb067ecd00 | 66 | int load () ; |
| JonFreeman | 3:43cb067ecd00 | 67 | int save () ; |
| JonFreeman | 3:43cb067ecd00 | 68 | char rd (uint32_t i) ; |
| JonFreeman | 3:43cb067ecd00 | 69 | bool wr (char c, uint32_t i) ; // Write one setup char value to private buffer 'settings' |
| JonFreeman | 3:43cb067ecd00 | 70 | } ; |
| JonFreeman | 3:43cb067ecd00 | 71 | */ |
| JonFreeman | 3:43cb067ecd00 | 72 | ee_settings_2020::ee_settings_2020 () { |
| JonFreeman | 3:43cb067ecd00 | 73 | // load (); // Can't use this here, causes core dump |
| JonFreeman | 3:43cb067ecd00 | 74 | } |
| JonFreeman | 3:43cb067ecd00 | 75 | |
| JonFreeman | 3:43cb067ecd00 | 76 | int ee_settings_2020::load () { |
| JonFreeman | 3:43cb067ecd00 | 77 | return eeprom.read (settings_ee_addr, new_settings, eeprom_page_size); |
| JonFreeman | 3:43cb067ecd00 | 78 | } |
| JonFreeman | 3:43cb067ecd00 | 79 | |
| JonFreeman | 3:43cb067ecd00 | 80 | int ee_settings_2020::save () { // Write to eeprom only those that need changing |
| JonFreeman | 3:43cb067ecd00 | 81 | int count = 0; |
| JonFreeman | 3:43cb067ecd00 | 82 | char tmp[eeprom_page_size + 2]; |
| JonFreeman | 3:43cb067ecd00 | 83 | int n = eeprom.read (settings_ee_addr, tmp, eeprom_page_size); |
| JonFreeman | 3:43cb067ecd00 | 84 | for (int i = 0; i < eeprom_page_size; i++) { |
| JonFreeman | 3:43cb067ecd00 | 85 | if (new_settings[i] != tmp[i]) { |
| JonFreeman | 3:43cb067ecd00 | 86 | count++; |
| JonFreeman | 3:43cb067ecd00 | 87 | eeprom.write (settings_ee_addr + i, new_settings[i]); |
| JonFreeman | 3:43cb067ecd00 | 88 | } |
| JonFreeman | 3:43cb067ecd00 | 89 | } |
| JonFreeman | 3:43cb067ecd00 | 90 | return count; |
| JonFreeman | 3:43cb067ecd00 | 91 | } |
| JonFreeman | 3:43cb067ecd00 | 92 | |
| JonFreeman | 3:43cb067ecd00 | 93 | char ee_settings_2020::rd (uint32_t i) { |
| JonFreeman | 3:43cb067ecd00 | 94 | return new_settings[i]; |
| JonFreeman | 3:43cb067ecd00 | 95 | } |
| JonFreeman | 3:43cb067ecd00 | 96 | |
| JonFreeman | 3:43cb067ecd00 | 97 | |
| JonFreeman | 3:43cb067ecd00 | 98 | bool ee_settings_2020::wr (char c, uint32_t i) { // Write one setup char value to private buffer 'settings' |
| JonFreeman | 3:43cb067ecd00 | 99 | if (i >= eeprom_page_size) |
| JonFreeman | 3:43cb067ecd00 | 100 | return false; |
| JonFreeman | 3:43cb067ecd00 | 101 | new_settings[i] = c; |
| JonFreeman | 3:43cb067ecd00 | 102 | return true; |
| JonFreeman | 3:43cb067ecd00 | 103 | } |
| JonFreeman | 3:43cb067ecd00 | 104 | |
| JonFreeman | 3:43cb067ecd00 | 105 | sldandt * ee_settings_2020::inform (uint32_t which) { |
| JonFreeman | 3:43cb067ecd00 | 106 | if (which >= numof_eeprom_options) |
| JonFreeman | 3:43cb067ecd00 | 107 | return NULL; |
| JonFreeman | 3:43cb067ecd00 | 108 | return &option_list[which]; |
| JonFreeman | 3:43cb067ecd00 | 109 | } |
| JonFreeman | 3:43cb067ecd00 | 110 | |
| JonFreeman | 3:43cb067ecd00 | 111 | |
| JonFreeman | 3:43cb067ecd00 | 112 |