Simulated product dispenser
Fork of mbed-cloud-workshop-connect-HTS221 by
update_ui_example.cpp
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2018 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #include "update_ui_example.h" 00020 00021 #ifdef MBED_CLOUD_CLIENT_SUPPORT_UPDATE 00022 00023 #include <stdio.h> 00024 #include <stdint.h> 00025 00026 static MbedCloudClient* _client; 00027 00028 #ifdef ARM_UPDATE_CLIENT_VERSION_VALUE 00029 #if ARM_UPDATE_CLIENT_VERSION_VALUE > 101000 00030 void update_ui_set_cloud_client(MbedCloudClient* client) 00031 { 00032 _client = client; 00033 } 00034 00035 void update_authorize(int32_t request) 00036 { 00037 switch (request) 00038 { 00039 /* Cloud Client wishes to download new firmware. This can have a negative 00040 impact on the performance of the rest of the system. 00041 00042 The user application is supposed to pause performance sensitive tasks 00043 before authorizing the download. 00044 00045 Note: the authorization call can be postponed and called later. 00046 This doesn't affect the performance of the Cloud Client. 00047 */ 00048 case MbedCloudClient::UpdateRequestDownload: 00049 printf("Firmware download requested\r\n"); 00050 printf("Authorization granted\r\n"); 00051 _client->update_authorize(MbedCloudClient::UpdateRequestDownload); 00052 break; 00053 00054 /* Cloud Client wishes to reboot and apply the new firmware. 00055 00056 The user application is supposed to save all current work before rebooting. 00057 00058 Note: the authorization call can be postponed and called later. 00059 This doesn't affect the performance of the Cloud Client. 00060 */ 00061 case MbedCloudClient::UpdateRequestInstall: 00062 printf("Firmware install requested\r\n"); 00063 printf("Authorization granted\r\n"); 00064 _client->update_authorize(MbedCloudClient::UpdateRequestInstall); 00065 break; 00066 00067 default: 00068 printf("Error - unknown request\r\n"); 00069 break; 00070 } 00071 } 00072 #endif 00073 #endif 00074 00075 void update_progress(uint32_t progress, uint32_t total) 00076 { 00077 uint8_t percent = progress * 100 / total; 00078 00079 /* only show progress bar if debug trace is disabled */ 00080 #if (!defined(MBED_CONF_MBED_TRACE_ENABLE) || MBED_CONF_MBED_TRACE_ENABLE == 0) \ 00081 && !ARM_UC_ALL_TRACE_ENABLE \ 00082 && !ARM_UC_HUB_TRACE_ENABLE 00083 00084 printf("\rDownloading: ["); 00085 for (uint8_t index = 0; index < 50; index++) 00086 { 00087 if (index < percent / 2) 00088 { 00089 printf("+"); 00090 } 00091 else if (index == percent / 2) 00092 { 00093 static uint8_t old_max = 0; 00094 static uint8_t counter = 0; 00095 00096 if (index == old_max) 00097 { 00098 counter++; 00099 } 00100 else 00101 { 00102 old_max = index; 00103 counter = 0; 00104 } 00105 00106 switch (counter % 4) 00107 { 00108 case 0: 00109 printf("/"); 00110 break; 00111 case 1: 00112 printf("-"); 00113 break; 00114 case 2: 00115 printf("\\"); 00116 break; 00117 case 3: 00118 default: 00119 printf("|"); 00120 break; 00121 } 00122 } 00123 else 00124 { 00125 printf(" "); 00126 } 00127 } 00128 printf("] %d %%", percent); 00129 fflush(stdout); 00130 #else 00131 printf("Downloading: %d %%\r\n", percent); 00132 #endif 00133 00134 if (progress == total) 00135 { 00136 printf("\r\nDownload completed\r\n"); 00137 } 00138 } 00139 00140 #endif // MBED_CLOUD_CLIENT_SUPPORT_UPDATE
Generated on Tue Jul 12 2022 19:12:17 by 1.7.2